8000 MNT: Clean up some UTF strings and memory autorelease by greglucas · Pull Request #21756 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: Clean up some UTF strings and memory autorelease #21756

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

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 10 additions & 26 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
lazy_init();
FigureCanvas *self = (FigureCanvas*)type->tp_alloc(type, 0);
if (!self) { return NULL; }
self->view = [View alloc];
self->view = [[View alloc] autorelease];
return (PyObject*)self;
}

Expand Down Expand Up @@ -337,7 +337,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
{
if (self->view) {
[self->view setCanvas: NULL];
[self->view release];
}
Py_TYPE(self)->tp_free((PyObject*)self);
}
Expand Down Expand Up @@ -603,11 +602,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
FigureManager_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
lazy_init();
Window* window = [Window alloc];
Window* window = [[Window alloc] autorelease];
if (!window) { return NULL; }
FigureManager *self = (FigureManager*)type->tp_alloc(type, 0);
if (!self) {
[window release];
return NULL;
}
self->window = window;
Expand Down Expand Up @@ -719,9 +717,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
}
Window* window = self->window;
if (window) {
NSString* ns_title = [[[NSString alloc]
initWithCString: title
encoding: NSUTF8StringEncoding] autorelease];
NSString* ns_title = [NSString stringWithUTF8String: title];
[window setTitle: ns_title];
}
Py_RETURN_NONE;
Expand Down Expand Up @@ -981,11 +977,10 @@ -(void)save_figure:(id)sender
NavigationToolbar2_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
lazy_init();
NavigationToolbar2Handler* handler = [NavigationToolbar2Handler alloc];
NavigationToolbar2Handler* handler = [[NavigationToolbar2Handler alloc] autorelease];
if (!handler) { return NULL; }
NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc(type, 0);
if (!self) {
[handler release];
return NULL;
}
self->handler = handler;
Expand Down Expand Up @@ -1062,12 +1057,10 @@ -(void)save_figure:(id)sender
rect.origin.y = 0.5*(height - rect.size.height);

for (int i = 0; i < 7; i++) {
NSString* filename = [NSString stringWithCString: images[i]
encoding: NSUTF8StringEncoding];
NSString* tooltip = [NSString stringWithCString: tooltips[i]
encoding: NSUTF8StringEncoding];
NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename];
buttons[i] = [[NSButton alloc] initWithFrame: rect];
NSString* filename = [NSString stringWithUTF8String: images[i]];
NSString* tooltip = [NSString stringWithUTF8String: tooltips[i]];
NSImage* image = [[[NSImage alloc] initWithContentsOfFile: filename] autorelease];
buttons[i] = [[[NSButton alloc] initWithFrame: rect] autorelease];
[image setSize: size];
[buttons[i] setBezelStyle: NSBezelStyleShadowlessSquare];
[buttons[i] setButtonType: buttontypes[i]];
Expand All @@ -1076,8 +1069,6 @@ -(void)save_figure:(id)sender
[buttons[i] setImagePosition: NSImageOnly];
[buttons[i] setToolTip: tooltip];
[[window contentView] addSubview: buttons[i]];
[buttons[i] release];
[image release];
rect.origin.x += rect.size.width + gap;
}

Expand All @@ -1102,7 +1093,6 @@ -(void)save_figure:(id)sender
rect.origin.y = 0.5 * (height - rect.size.height);
[messagebox setFrameOrigin: rect.origin];
[[window contentView] addSubview: messagebox];
[messagebox release];
[[window contentView] display];

self->messagebox = messagebox;
Expand All @@ -1112,7 +1102,6 @@ -(void)save_figure:(id)sender
static void
NavigationToolbar2_dealloc(NavigationToolbar2 *self)
{
[self->handler release];
Py_TYPE(self)->tp_free((PyObject*)self);
}

Expand Down Expand Up @@ -1215,15 +1204,10 @@ -(void)save_figure:(id)sender
return NULL;
}
NSSavePanel* panel = [NSSavePanel savePanel];
[panel setTitle: [NSString stringWithCString: title
encoding: NSASCIIStringEncoding]];
NSString* ns_default_filename =
[[NSString alloc]
initWithCString: default_filename
encoding: NSUTF8StringEncoding];
[panel setTitle: [NSString stringWithUTF8String: title]];
NSString* ns_default_filename = [NSString stringWithUTF8String: default_filename];
[panel setNameFieldStringValue: ns_default_filename];
result = [panel runModal];
[ns_default_filename release];
if (result == NSModalResponseOK) {
NSURL* url = [panel URL];
NSString* filename = [url path];
Expand Down
0