Skip to content

Backport #17084 and #17210 to v3.2.x #17346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def __call__(self, orig, dest):
# Inkscape's output is not localized but gtk's is, so the output
# stream probably has a mixed encoding. Using the filesystem
# encoding should at least get the filenames right...
self._stderr.seek(0)
self._proc.stderr.seek(0)
raise ImageComparisonFailure(
self._stderr.read().decode(
self._proc.stderr.read().decode(
sys.getfilesystemencoding(), "replace"))


Expand Down
30 changes: 1 addition & 29 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static int wait_for_stdin(void)
}

NSEvent* event;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
while (true) {
while (true) {
event = [NSApp nextEventMatchingMask: NSAnyEventMask
Expand All @@ -151,7 +150,6 @@ static int wait_for_stdin(void)
CFRunLoopRun();
if (interrupted || CFReadStreamHasBytesAvailable(stream)) break;
}
[pool release];

if (py_sigint_handler) PyOS_setsig(SIGINT, py_sigint_handler);
CFReadStreamUnscheduleFromRunLoop(stream,
Expand Down Expand Up @@ -280,15 +278,13 @@ static void lazy_init(void) {
PyOS_InputHook = wait_for_stdin;
#endif

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
WindowServerConnectionManager* connectionManager = [WindowServerConnectionManager sharedManager];
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSNotificationCenter* notificationCenter = [workspace notificationCenter];
[notificationCenter addObserver: connectionManager
selector: @selector(launch:)
name: NSWorkspaceDidLaunchApplicationNotification
object: nil];
[pool release];
}

static PyObject*
Expand Down Expand Up @@ -366,11 +362,7 @@ static CGFloat _get_device_scale(CGContextRef cr)

if(view) /* The figure may have been closed already */
{
/* Whereas drawRect creates its own autorelease pool, apparently
* [view display] also needs one. Create and release it here. */
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[view display];
[pool release];
}

Py_RETURN_NONE;
Expand Down Expand Up @@ -546,7 +538,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
close(channel[0]);
}

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSDate* date =
(timeout > 0.0) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
: [NSDate distantFuture];
Expand All @@ -558,7 +549,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
if (!event || [event type]==NSApplicationDefined) break;
[NSApp sendEvent: event];
}
[pool release];

if (py_sigint_handler) PyOS_setsig(SIGINT, py_sigint_handler);

Expand Down Expand Up @@ -731,7 +721,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
rect.size.height = height;
rect.size.width = width;

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
self->window = [self->window initWithContentRect: rect
styleMask: NSTitledWindowMask
| NSClosableWindowMask
Expand All @@ -749,7 +738,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
[window makeFirstResponder: view];
[[window contentView] addSubview: view];

[pool release];
return 0;
}

Expand All @@ -766,9 +754,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
Window* window = self->window;
if(window)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[window close];
[pool release];
}
Py_TYPE(self)->tp_free((PyObject*)self);
}
Expand All @@ -779,10 +765,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
Window* window = self->window;
if(window)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[window makeKeyAndOrderFront: nil];
[window orderFrontRegardless];
[pool release];
}
Py_RETURN_NONE;
}
Expand All @@ -793,9 +777,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
Window* window = self->window;
if(window)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[window close];
[pool release];
self->window = NULL;
}
Py_RETURN_NONE;
Expand All @@ -812,12 +794,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
Window* window = self->window;
if(window)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString* ns_title = [[[NSString alloc]
initWithCString: title
encoding: NSUTF8StringEncoding] autorelease];
[window setTitle: ns_title];
[pool release];
}
Py_RETURN_NONE;
}
Expand All @@ -829,13 +809,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
PyObject* result = NULL;
if(window)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSString* title = [window title];
if (title) {
const char* cTitle = [title UTF8String];
result = PyUnicode_FromString(cTitle);
}
[pool release];
}
if (result) {
return result;
Expand Down Expand Up @@ -1164,7 +1142,6 @@ -(void)save_figure:(id)sender

if(!PyArg_ParseTuple(args, "s", &basedir)) return -1;

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSRect bounds = [view bounds];
NSWindow* window = [view window];

Expand Down Expand Up @@ -1265,8 +1242,6 @@ -(void)save_figure:(id)sender
[messagebox release];
[[window contentView] display];

[pool release];

self->messagebox = messagebox;
return 0;
}
Expand Down Expand Up @@ -1297,10 +1272,9 @@ -(void)save_figure:(id)sender
NSText* messagebox = self->messagebox;

if (messagebox)
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
{
NSString* text = [NSString stringWithUTF8String: message];
[messagebox setString: text];
[pool release];
}

Py_RETURN_NONE;
Expand Down Expand Up @@ -2349,14 +2323,12 @@ - (int)index
show(PyObject* self)
{
[NSApp activateIgnoringOtherApps: YES];
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSArray *windowsArray = [NSApp windows];
NSEnumerator *enumerator = [windowsArray objectEnumerator];
NSWindow *window;
while ((window = [enumerator nextObject])) {
[window orderFront:nil];
}
[pool release];
Py_BEGIN_ALLOW_THREADS
[NSApp run];
Py_END_ALLOW_THREADS
Expand Down