8000 MNT: Clean up some UTF strings and memory autorelease · greglucas/matplotlib@955054a · GitHub
[go: up one dir, main page]

Skip to content

Commit 955054a

Browse files
committed
MNT: Clean up some UTF strings and memory autorelease
Use UTF-8 strings instead of C strings with encodings. Use autorelease semantics instead of explicitly releasing.
1 parent 7c4e9a1 commit 955054a

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

src/_macosx.m

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
303303
lazy_init();
304304
FigureCanvas *self = (FigureCanvas*)type->tp_alloc(type, 0);
305305
if (!self) { return NULL; }
306-
self->view = [View alloc];
306+
self->view = [[View alloc] autorelease];
307307
return (PyObject*)self;
308308
}
309309

@@ -337,7 +337,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
337337
{
338338
if (self->view) {
339339
[self->view setCanvas: NULL];
340-
[self->view release];
341340
}
342341
Py_TYPE(self)->tp_free((PyObject*)self);
343342
}
@@ -603,11 +602,10 @@ static CGFloat _get_device_scale(CGContextRef cr)
603602
FigureManager_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
604603
{
605604
lazy_init();
606-
Window* window = [Window alloc];
605+
Window* window = [[Window alloc] autorelease];
607606
if (!window) { return NULL; }
608607
FigureManager *self = (FigureManager*)type->tp_alloc(type, 0);
609608
if (!self) {
610-
[window release];
611609
return NULL;
612610
}
613611
self->window = window;
@@ -719,9 +717,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
719717
}
720718
Window* window = self->window;
721719
if (window) {
722-
NSString* ns_title = [[[NSString alloc]
723-
initWithCString: title
724-
encoding: NSUTF8StringEncoding] autorelease];
720+
NSString* ns_title = [NSString stringWithUTF8String: title];
725721
[window setTitle: ns_title];
726722
}
727723
Py_RETURN_NONE;
@@ -981,11 +977,10 @@ -(void)save_figure:(id)sender
981977
NavigationToolbar2_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
982978
{
983979
lazy_init();
984-
NavigationToolbar2Handler* handler = [NavigationToolbar2Handler alloc];
980+
NavigationToolbar2Handler* handler = [[NavigationToolbar2Handler alloc] autorelease];
985981
if (!handler) { return NULL; }
986982
NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc(type, 0);
987983
if (!self) {
988-
[handler release];
989984
return NULL;
990985
}
991986
self->handler = handler;
@@ -1062,12 +1057,10 @@ -(void)save_figure:(id)sender
10621057
rect.origin.y = 0.5*(height - rect.size.height);
10631058

10641059
for (int i = 0; i < 7; i++) {
1065-
NSString* filename = [NSString stringWithCString: images[i]
1066-
encoding: NSUTF8StringEncoding];
1067-
NSString* tooltip = [NSString stringWithCString: tooltips[i]
1068-
encoding: NSUTF8StringEncoding];
1069-
NSImage* image = [[NSImage alloc] initWithContentsOfFile: filename];
1070-
buttons[i] = [[NSButton alloc] initWithFrame: rect];
1060+
NSString* filename = [NSString stringWithUTF8String: images[i]];
1061+
NSString* tooltip = [NSString stringWithUTF8String: tooltips[i]];
1062+
NSImage* image = [[[NSImage alloc] initWithContentsOfFile: filename] autorelease];
1063+
buttons[i] = [[[NSButton alloc] initWithFrame: rect] autorelease];
10711064
[image setSize: size];
10721065
[buttons[i] setBezelStyle: NSBezelStyleShadowlessSquare];
10731066
[buttons[i] setButtonType: buttontypes[i]];
@@ -1076,8 +1069,6 @@ -(void)save_figure:(id)sender
10761069
[buttons[i] setImagePosition: NSImageOnly];
10771070
[buttons[i] setToolTip: tooltip];
10781071
[[window contentView] addSubview: buttons[i]];
1079-
[buttons[i] release];
1080-
[image release];
10811072
rect.origin.x += rect.size.width + gap;
10821073
}
10831074

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

11081098
self->messagebox = messagebox;
@@ -1112,7 +1102,6 @@ -(void)save_figure:(id)sender
11121102
static void
11131103
NavigationToolbar2_dealloc(NavigationToolbar2 *self)
11141104
{
1115-
[self->handler release];
11161105
Py_TYPE(self)->tp_free((PyObject*)self);
11171106
}
11181107

@@ -1215,15 +1204,10 @@ -(void)save_figure:(id)sender
12151204
return NULL;
12161205
}
12171206
NSSavePanel* panel = [NSSavePanel savePanel];
1218-
[panel setTitle: [NSString stringWithCString: title
1219-
encoding: NSASCIIStringEncoding]];
1220-
NSString* ns_default_filename =
1221-
[[NSString alloc]
1222-
initWithCString: default_filename
1223-
encoding: NSUTF8StringEncoding];
1207+
[panel setTitle: [NSString stringWithUTF8String: title]];
1208+
NSString* ns_default_filename = [NSString stringWithUTF8String: default_filename];
12241209
[panel setNameFieldStringValue: ns_default_filename];
12251210
result = [panel runModal];
1226-
[ns_default_filename release];
12271211
if (result == NSModalResponseOK) {
12281212
NSURL* url = [panel URL];
12291213
NSString* filename = [url path];

0 commit comments

Comments
 (0)
0