Skip to content

Commit cb34934

Browse files
authored
Merge pull request #17084 from cbrnr/fix-macosx-segfault
Fix macosx segfault
2 parents 10b0b48 + af58544 commit cb34934

File tree

1 file changed

+5
-34
lines changed

1 file changed

+5
-34
lines changed

src/_macosx.m

+5-34
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ static int wait_for_stdin(void)
138138
}
139139

140140
NSEvent* event;
141-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
142141
while (true) {
143142
while (true) {
144143
event = [NSApp nextEventMatchingMask: NSAnyEventMask
@@ -151,7 +150,6 @@ static int wait_for_stdin(void)
151150
CFRunLoopRun();
152151
if (interrupted || CFReadStreamHasBytesAvailable(stream)) break;
153152
}
154-
[pool release];
155153

156154
if (py_sigint_handler) PyOS_setsig(SIGINT, py_sigint_handler);
157155
CFReadStreamUnscheduleFromRunLoop(stream,
@@ -279,15 +277,13 @@ static void lazy_init(void) {
279277
PyOS_InputHook = wait_for_stdin;
280278
#endif
281279

282-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
283280
WindowServerConnectionManager* connectionManager = [WindowServerConnectionManager sharedManager];
284281
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
285282
NSNotificationCenter* notificationCenter = [workspace notificationCenter];
286283
[notificationCenter addObserver: connectionManager
287284
selector: @selector(launch:)
288285
name: NSWorkspaceDidLaunchApplicationNotification
289286
object: nil];
290-
[pool release];
291287
}
292288

293289
static PyObject*
@@ -373,11 +369,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
373369

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

383375
Py_RETURN_NONE;
@@ -513,7 +505,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
513505
close(channel[0]);
514506
}
515507

516-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
517508
NSDate* date =
518509
(timeout > 0.0) ? [NSDate dateWithTimeIntervalSinceNow: timeout]
519510
: [NSDate distantFuture];
@@ -525,7 +516,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
525516
if (!event || [event type]==NSApplicationDefined) break;
526517
[NSApp sendEvent: event];
527518
}
528-
[pool release];
529519

530520
if (py_sigint_handler) PyOS_setsig(SIGINT, py_sigint_handler);
531521

@@ -698,7 +688,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
698688
rect.size.height = height;
699689
rect.size.width = width;
700690

701-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
702691
self->window = [self->window initWithContentRect: rect
703692
styleMask: NSTitledWindowMask
704693
| NSClosableWindowMask
@@ -715,7 +704,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
715704
[window makeFirstResponder: view];
716705
[[window contentView] addSubview: view];
717706

718-
[pool release];
719707
return 0;
720708
}
721709

@@ -732,9 +720,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
732720
Window* window = self->window;
733721
if(window)
734722
{
735-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
736723
[window close];
737-
[pool release];
738724
}
739725
Py_TYPE(self)->tp_free((PyObject*)self);
740726
}
@@ -745,10 +731,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
745731
Window* window = self->window;
746732
if(window)
747733
{
748-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
749734
[window makeKeyAndOrderFront: nil];
750735
[window orderFrontRegardless];
751-
[pool release];
752736
}
753737
Py_RETURN_NONE;
754738
}
@@ -759,9 +743,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
759743
Window* window = self->window;
760744
if(window)
761745
{
762-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
763746
[window close];
764-
[pool release];
765747
self->window = NULL;
766748
}
767749
Py_RETURN_NONE;
@@ -778,12 +760,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
778760
Window* window = self->window;
779761
if(window)
780762
{
781-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
782763
NSString* ns_title = [[[NSString alloc]
783764
initWithCString: title
784765
encoding: NSUTF8StringEncoding] autorelease];
785766
[window setTitle: ns_title];
786-
[pool release];
787767
}
788768
Py_RETURN_NONE;
789769
}
@@ -795,13 +775,11 @@ static CGFloat _get_device_scale(CGContextRef cr)
795775
PyObject* result = NULL;
796776
if(window)
797777
{
798-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
799778
NSString* title = [window title];
800779
if (title) {
801780
const char* cTitle = [title UTF8String];
802781
result = PyUnicode_FromString(cTitle);
803782
}
804-
[pool release];
805783
}
806784
if (result) {
807785
return result;
@@ -1127,9 +1105,9 @@ -(void)save_figure:(id)sender
11271105
const float gap = 2;
11281106
const int height = 36;
11291107
const int imagesize = 24;
1130-
1108+
11311109
self->height = height;
1132-
1110+
11331111
const char* basedir;
11341112

11351113
obj = PyObject_GetAttrString((PyObject*)self, "canvas");
@@ -1154,7 +1132,6 @@ -(void)save_figure:(id)sender
11541132

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

1157-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
11581135
NSRect bounds = [view bounds];
11591136
NSWindow* window = [view window];
11601137

@@ -1257,8 +1234,6 @@ -(void)save_figure:(id)sender
12571234
[messagebox release];
12581235
[[window contentView] display];
12591236

1260-
[pool release];
1261-
12621237
self->messagebox = messagebox;
12631238
return 0;
12641239
}
@@ -1289,24 +1264,22 @@ -(void)save_figure:(id)sender
12891264
NSTextView* messagebox = self->messagebox;
12901265

12911266
if (messagebox)
1292-
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
1267+
{
12931268
NSString* text = [NSString stringWithUTF8String: message];
12941269
[messagebox setString: text];
1295-
1270+
12961271
// Adjust width with the window size
12971272
NSRect rectWindow = [messagebox.superview frame];
12981273
NSRect rect = [messagebox frame];
12991274
rect.size.width = rectWindow.size.width - rect.origin.x;
13001275
[messagebox setFrame: rect];
1301-
1276+
13021277
// Adjust height with the content size
13031278
[messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
13041279
NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
13051280
rect = [messagebox frame];
13061281
rect.origin.y = 0.5 * (self->height - contentSize.size.height);
13071282
[messagebox setFrame: rect];
1308-
1309-
[pool release];
13101283
}
13111284

13121285
Py_RETURN_NONE;
@@ -2323,14 +2296,12 @@ - (int)index
23232296
show(PyObject* self)
23242297
{
23252298
[NSApp activateIgnoringOtherApps: YES];
2326-
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
23272299
NSArray *windowsArray = [NSApp windows];
23282300
NSEnumerator *enumerator = [windowsArray objectEnumerator];
23292301
NSWindow *window;
23302302
while ((window = [enumerator nextObject])) {
23312303
[window orderFront:nil];
23322304
}
2333-
[pool release];
23342305
Py_BEGIN_ALLOW_THREADS
23352306
[NSApp run];
23362307
Py_END_ALLOW_THREADS

0 commit comments

Comments
 (0)