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
+
1
5
#define PY_SSIZE_T_CLEAN
2
6
#include < Cocoa/Cocoa.h>
3
7
#include < ApplicationServices/ApplicationServices.h>
@@ -333,15 +337,14 @@ static CGFloat _get_device_scale(CGContextRef cr)
333
337
FigureCanvas_dealloc (FigureCanvas* self)
334
338
{
335
339
[self ->view setCanvas: NULL ];
336
- [self ->view release ];
337
340
Py_TYPE (self)->tp_free ((PyObject*)self);
338
341
}
339
342
340
343
static PyObject*
341
344
FigureCanvas_repr (FigureCanvas* self)
342
345
{
343
346
return PyUnicode_FromFormat (" FigureCanvas object %p wrapping NSView %p " ,
344
- (void *)self, (void *)(self->view ));
347
+ (void *)self, (__bridge void *)(self->view ));
345
348
}
346
349
347
350
static PyObject*
@@ -545,7 +548,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
545
548
if (!window) { return NULL ; }
546
549
FigureManager *self = (FigureManager*)type->tp_alloc (type, 0 );
547
550
if (!self) {
548
- [window release ];
549
551
return NULL ;
550
552
}
551
553
self->window = window;
@@ -598,7 +600,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
598
600
FigureManager_repr (FigureManager* self)
599
601
{
600
602
return PyUnicode_FromFormat (" FigureManager object %p wrapping NSWindow %p " ,
601
- (void *) self, (void *)(self->window ));
603
+ (void *) self, (__bridge void *)(self->window ));
602
604
}
603
605
604
606
static void
@@ -648,7 +650,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
648
650
PyErr_SetString (PyExc_RuntimeError, " Could not convert to NSString*" );
649
651
return NULL ;
650
652
}
651
- NSImage * image = [[[ NSImage alloc ] initByReferencingFile: ns_icon_path] autorelease ];
653
+ NSImage * image = [[NSImage alloc ] initByReferencingFile: ns_icon_path];
652
654
if (!image) {
653
655
PyErr_SetString (PyExc_RuntimeError, " Could not create NSImage*" );
654
656
return NULL ;
@@ -677,9 +679,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
677
679
if (!PyArg_ParseTuple (args, " s" , &title)) {
678
680
return NULL ;
679
681
}
680
- NSString * ns_title = [[[ NSString alloc ]
681
- initWithCString: title
682
- encoding: NSUTF8StringEncoding] autorelease ];
682
+ NSString * ns_title = [[NSString alloc ]
683
+ initWithCString: title
684
+ encoding: NSUTF8StringEncoding];
683
685
[self ->window setTitle: ns_title];
684
686
Py_RETURN_NONE;
685
687
}
@@ -766,7 +768,7 @@ @interface NavigationToolbar2Handler : NSObject
766
768
NSButton * zoombutton;
767
769
}
768
770
- (NavigationToolbar2Handler*)initWithToolbar : (PyObject*)toolbar ;
769
- - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *[7 ])buttons ;
771
+ - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *__strong [7 ])buttons ;
770
772
- (void )home : (id )sender ;
771
773
- (void )back : (id )sender ;
772
774
- (void )forward : (id )sender ;
@@ -787,12 +789,12 @@ - (void)save_figure:(id)sender;
787
789
@implementation NavigationToolbar2Handler
788
790
- (NavigationToolbar2Handler*)initWithToolbar : (PyObject*)theToolbar
789
791
{
790
- [self init ];
792
+ self = [self init ];
791
793
toolbar = theToolbar;
792
794
return self;
793
795
}
794
796
795
- - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *[7 ])buttons
797
+ - (void )installCallbacks : (SEL [7 ])actions forButtons : (NSButton *__strong [7 ])buttons
796
798
{
797
799
int i;
798
800
for (i = 0 ; i < 7 ; i++) {
@@ -833,7 +835,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
833
835
if (!handler) { return NULL ; }
834
836
NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc (type, 0 );
835
837
if (!self) {
836
- [handler release ];
837
838
return NULL ;
838
839
}
839
840
self->handler = handler;
@@ -925,8 +926,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
925
926
[buttons[i] setImagePosition: NSImageOnly];
926
927
[buttons[i] setToolTip: tooltip];
927
928
[[window contentView ] addSubview: buttons[i]];
928
- [buttons[i] release ];
929
- [image release ];
930
929
rect.origin .x += rect.size .width + gap;
931
930
}
932
931
@@ -939,7 +938,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
939
938
// Make it a zero-width box if we don't have enough room
940
939
rect.size .width = fmax (bounds.size .width - rect.origin .x , 0 );
941
940
rect.origin .x = bounds.size .width - rect.size .width ;
942
- NSTextView * messagebox = [[[ NSTextView alloc ] initWithFrame: rect] autorelease ];
941
+ NSTextView * messagebox = [[NSTextView alloc ] initWithFrame: rect];
943
942
messagebox.textContainer .maximumNumberOfLines = 2 ;
944
943
messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
945
944
messagebox.alignment = NSTextAlignmentRight;
@@ -949,7 +948,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
949
948
/* if selectable, the messagebox can become first responder,
950
949
* which is not supposed to happen */
951
950
[[window contentView ] addSubview: messagebox];
952
- [messagebox release ];
953
951
[[window contentView ] display ];
954
952
955
953
self->messagebox = messagebox;
@@ -959,7 +957,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
959
957
static void
960
958
NavigationToolbar2_dealloc (NavigationToolbar2 *self)
961
959
{
962
- [self ->handler release ];
963
960
Py_TYPE (self)->tp_free ((PyObject*)self);
964
961
}
965
962
@@ -1060,36 +1057,6 @@ + (WindowServerConnectionManager *)sharedManager
1060
1057
return sharedWindowServerConnectionManager;
1061
1058
}
1062
1059
1063
- + (id )allocWithZone : (NSZone *)zone
1064
- {
1065
- return [[self sharedManager ] retain ];
1066
- }
1067
-
1068
- + (id )copyWithZone : (NSZone *)zone
1069
- {
1070
- return self;
1071
- }
1072
-
1073
- + (id )retain
1074
- {
1075
- return self;
1076
- }
1077
-
1078
- - (NSUInteger )retainCount
1079
- {
1080
- return NSUIntegerMax; // denotes an object that cannot be released
1081
- }
1082
-
1083
- - (oneway void )release
1084
- {
1085
- // Don't release a singleton object
1086
- }
1087
-
1088
- - (id )autorelease
1089
- {
1090
- return self;
1091
- }
1092
-
1093
1060
- (void )launch : (NSNotification *)notification
1094
1061
{
1095
1062
CFRunLoopRef runloop;
@@ -1167,7 +1134,6 @@ - (void)dealloc
1167
1134
* content view of this window was increased during the call to addSubview,
1168
1135
* and is decreased during the call to [super dealloc].
1169
1136
*/
1170
- [super dealloc ];
1171
1137
}
1172
1138
@end
1173
1139
@@ -1189,7 +1155,6 @@ - (void)dealloc
1189
1155
{
1190
1156
FigureCanvas* fc = (FigureCanvas*)canvas;
1191
1157
if (fc) { fc->view = NULL ; }
1192
- [super dealloc ];
1193
1158
}
1194
1159
1195
1160
- (void )setCanvas : (PyObject*)newCanvas
0 commit comments