1
- #if ! __has_feature(objc_arc)
2
- #error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
3
- #endif
4
-
5
1
#define PY_SSIZE_T_CLEAN
6
2
#include < Cocoa/Cocoa.h>
7
3
#include < ApplicationServices/ApplicationServices.h>
@@ -374,14 +370,15 @@ static CGFloat _get_device_scale(CGContextRef cr)
374
370
FigureCanvas_dealloc (FigureCanvas* self)
375
371
{
376
372
[self ->view setCanvas: NULL ];
373
+ [self ->view release ];
377
374
Py_TYPE (self)->tp_free ((PyObject*)self);
378
375
}
379
376
380
377
static PyObject*
381
378
FigureCanvas_repr (FigureCanvas* self)
382
379
{
383
380
return PyUnicode_FromFormat (" FigureCanvas object %p wrapping NSView %p " ,
384
- (void *)self, (__bridge void *)(self->view ));
381
+ (void *)self, (void *)(self->view ));
385
382
}
386
383
387
384
static PyObject*
@@ -585,6 +582,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
585
582
if (!window) { return NULL ; }
586
583
FigureManager *self = (FigureManager*)type->tp_alloc (type, 0 );
587
584
if (!self) {
585
+ [window release ];
588
586
return NULL ;
589
587
}
590
588
self->window = window;
@@ -637,7 +635,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
637
635
FigureManager_repr (FigureManager* self)
638
636
{
639
637
return PyUnicode_FromFormat (" FigureManager object %p wrapping NSWindow %p " ,
640
- (void *) self, (__bridge void *)(self->window ));
638
+ (void *) self, (void *)(self->window ));
641
639
}
642
640
643
641
static void
@@ -687,7 +685,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
687
685
PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
688
686
return NULL ;
689
687
}
690
- NSImage * image = [[NSImage alloc ] initByReferencingFile: ns_icon_path];
688
+ NSImage * image = [[[ NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
691
689
if (!image) {
692
690
PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
693
691
return NULL ;
@@ -802,7 +800,7 @@ @interface NavigationToolbar2Handler : NSObject
802
800
NSButton * zoombutton;
803
801
}
804
802
- (NavigationToolbar2Handler*)initWithToolbar : (PyObject*)toolbar ;
805
- - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *__strong [7 ])buttons ;
803
+ - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *[7 ])buttons ;
806
804
- (void )home : (id )sender ;
807
805
- (void )back : (id )sender ;
808
806
- (void )forward : (id )sender ;
@@ -823,12 +821,12 @@ - (void)save_figure:(id)sender;
823
821
@implementation NavigationToolbar2Handler
824
822
- (NavigationToolbar2Handler*)initWithToolbar : (PyObject*)theToolbar
825
823
{
826
- self = [self init ];
824
+ [self init ];
827
825
toolbar = theToolbar;
828
826
return self;
829
827
}
830
828
831
- - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *__strong [7 ])buttons
829
+ - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *[7 ])buttons
832
830
{
833
831
int i;
834
832
for (i = 0 ; i < 7 ; i++) {
@@ -869,6 +867,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
869
867
if (!handler) { return NULL ; }
870
868
NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc (type, 0 );
871
869
if (!self) {
870
+ [handler release ];
872
871
return NULL ;
873
872
}
874
873
self->handler = handler;
@@ -958,6 +957,8 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
958
957
[buttons[i] setImagePosition: NSImageOnly];
959
958
[buttons[i] setToolTip: tooltip];
960
959
[[window contentView ] addSubview: buttons[i]];
960
+ [buttons[i] release ];
961
+ [image release ];
961
962
rect.origin .x += rect.size .width + gap;
962
963
}
963
964
@@ -970,7 +971,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
970
971
// Make it a zero-width box if we don't have enough room
971
972
rect.size .width = fmax (bounds.size .width - rect.origin .x , 0 );
972
973
rect.origin .x = bounds.size .width - rect.size .width ;
973
- NSTextView * messagebox = [[NSTextView alloc ] initWithFrame: rect];
974
+ NSTextView * messagebox = [[[ NSTextView alloc ] initWithFrame: rect] autorelease ];
974
975
messagebox.textContainer .maximumNumberOfLines = 2 ;
975
976
messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
976
977
messagebox.alignment = NSTextAlignmentRight;
@@ -980,6 +981,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
980
981
/* if selectable, the messagebox can become first responder,
981
982
* which is not supposed to happen */
982
983
[[window contentView ] addSubview: messagebox];
984
+ [messagebox release ];
983
985
[[window contentView ] display ];
984
986
985
987
self->messagebox = messagebox;
@@ -989,6 +991,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
989
991
static void
990
992
NavigationToolbar2_dealloc (NavigationToolbar2 *self)
991
993
{
994
+ [self ->handler release ];
992
995
Py_TYPE (self)->tp_free ((PyObject*)self);
993
996
}
994
997
@@ -1089,6 +1092,36 @@ + (WindowServerConnectionManager *)sharedManager
1089
1092
return sharedWindowServerConnectionManager;
1090
1093
}
1091
1094
1095
+ + (id )allocWithZone : (NSZone *)zone
1096
+ {
1097
+ return [[self sharedManager ] retain ];
1098
+ }
1099
+
1100
+ + (id )copyWithZone : (NSZone *)zone
1101
+ {
1102
+ return self;
1103
+ }
1104
+
1105
+ + (id )retain
1106
+ {
1107
+ return self;
1108
+ }
1109
+
1110
+ - (NSUInteger )retainCount
1111
+ {
1112
+ return NSUIntegerMax; // denotes an object that cannot be released
1113
+ }
1114
+
1115
+ - (oneway void )release
1116
+ {
1117
+ // Don't release a singleton object
1118
+ }
1119
+
1120
+ - (id )autorelease
1121
+ {
1122
+ return self;
1123
+ }
1124
+
1092
1125
- (void )launch : (NSNotification *)notification
1093
1126
{
1094
1127
CFRunLoopRef runloop;
@@ -1166,6 +1199,7 @@ - (void)dealloc
1166
1199
* content view of this window was increased during the call to addSubview,
1167
1200
* and is decreased during the call to [super dealloc].
1168
1201
*/
1202
+ [super dealloc ];
1169
1203
}
1170
1204
@end
1171
1205
@@ -1187,6 +1221,7 @@ - (void)dealloc
1187
1221
{
1188
1222
FigureCanvas* fc = (FigureCanvas*)canvas;
1189
1223
if (fc) { fc->view = NULL ; }
1224
+ [super dealloc ];
1190
1225
}
1191
1226
1192
1227
- (void )setCanvas : (PyObject*)newCanvas
0 commit comments