Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2f87e8

Browse files
authored
Merge pull request#23060 from greglucas/macosx-ARC
MNT: Change objective C code to Automatic Reference Counting (ARC)
2 parents3eadeac +ec0a325 commitd2f87e8

File tree

2 files changed

+15
-50
lines changed

2 files changed

+15
-50
lines changed

‎setupext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ def get_extensions(self):
762762
'matplotlib.backends._macosx', [
763763
'src/_macosx.m'
764764
])
765-
ext.extra_compile_args.extend(['-Werror'])
765+
ext.extra_compile_args.extend(['-Werror','-fobjc-arc'])
766766
ext.extra_link_args.extend(['-framework','Cocoa'])
767767
ifplatform.python_implementation().lower()=='pypy':
768768
ext.extra_compile_args.append('-DPYPY=1')

‎src/_macosx.m

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
#definePY_SSIZE_T_CLEAN
26
#include<Cocoa/Cocoa.h>
37
#include<ApplicationServices/ApplicationServices.h>
@@ -333,15 +337,14 @@ static CGFloat _get_device_scale(CGContextRef cr)
333337
FigureCanvas_dealloc(FigureCanvas* self)
334338
{
335339
[self->viewsetCanvas:NULL];
336-
[self->viewrelease];
337340
Py_TYPE(self)->tp_free((PyObject*)self);
338341
}
339342

340343
static PyObject*
341344
FigureCanvas_repr(FigureCanvas* self)
342345
{
343346
returnPyUnicode_FromFormat("FigureCanvas object%p wrapping NSView%p",
344-
(void*)self, (void*)(self->view));
347+
(void*)self, (__bridgevoid*)(self->view));
345348
}
346349

347350
static PyObject*
@@ -545,7 +548,6 @@ static CGFloat _get_device_scale(CGContextRef cr)
545548
if (!window) {returnNULL; }
546549
FigureManager *self = (FigureManager*)type->tp_alloc(type,0);
547550
if (!self) {
548-
[windowrelease];
549551
returnNULL;
550552
}
551553
self->window = window;
@@ -598,7 +600,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
598600
FigureManager_repr(FigureManager* self)
599601
{
600602
returnPyUnicode_FromFormat("FigureManager object%p wrapping NSWindow%p",
601-
(void*) self, (void*)(self->window));
603+
(void*) self, (__bridgevoid*)(self->window));
602604
}
603605

604606
staticvoid
@@ -648,7 +650,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
648650
PyErr_SetString(PyExc_RuntimeError,"Could not convert to NSString*");
649651
returnNULL;
650652
}
651-
NSImage* image = [[[NSImagealloc]initByReferencingFile: ns_icon_path]autorelease];
653+
NSImage* image = [[NSImagealloc]initByReferencingFile: ns_icon_path];
652654
if (!image) {
653655
PyErr_SetString(PyExc_RuntimeError,"Could not create NSImage*");
654656
returnNULL;
@@ -677,9 +679,9 @@ static CGFloat _get_device_scale(CGContextRef cr)
677679
if (!PyArg_ParseTuple(args,"s", &title)) {
678680
returnNULL;
679681
}
680-
NSString* ns_title = [[[NSStringalloc]
681-
initWithCString: title
682-
encoding: NSUTF8StringEncoding]autorelease];
682+
NSString* ns_title = [[NSStringalloc]
683+
initWithCString: title
684+
encoding: NSUTF8StringEncoding];
683685
[self->windowsetTitle: ns_title];
684686
Py_RETURN_NONE;
685687
}
@@ -766,7 +768,7 @@ @interface NavigationToolbar2Handler : NSObject
766768
NSButton* zoombutton;
767769
}
768770
- (NavigationToolbar2Handler*)initWithToolbar:(PyObject*)toolbar;
769-
- (void)installCallbacks:(SEL[7])actionsforButtons:(NSButton*[7])buttons;
771+
- (void)installCallbacks:(SEL[7])actionsforButtons:(NSButton*__strong[7])buttons;
770772
- (void)home:(id)sender;
771773
- (void)back:(id)sender;
772774
- (void)forward:(id)sender;
@@ -787,12 +789,12 @@ - (void)save_figure:(id)sender;
787789
@implementationNavigationToolbar2Handler
788790
- (NavigationToolbar2Handler*)initWithToolbar:(PyObject*)theToolbar
789791
{
790-
[selfinit];
792+
self =[selfinit];
791793
toolbar = theToolbar;
792794
return self;
793795
}
794796

795-
- (void)installCallbacks:(SEL[7])actionsforButtons:(NSButton*[7])buttons
797+
- (void)installCallbacks:(SEL[7])actionsforButtons:(NSButton*__strong[7])buttons
796798
{
797799
int i;
798800
for (i =0; i <7; i++) {
@@ -833,7 +835,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
833835
if (!handler) {returnNULL; }
834836
NavigationToolbar2 *self = (NavigationToolbar2*)type->tp_alloc(type,0);
835837
if (!self) {
836-
[handlerrelease];
837838
returnNULL;
838839
}
839840
self->handler = handler;
@@ -925,8 +926,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
925926
[buttons[i]setImagePosition: NSImageOnly];
926927
[buttons[i]setToolTip: tooltip];
927928
[[windowcontentView]addSubview: buttons[i]];
928-
[buttons[i]release];
929-
[imagerelease];
930929
rect.origin.x += rect.size.width + gap;
931930
}
932931

@@ -939,7 +938,7 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
939938
// Make it a zero-width box if we don't have enough room
940939
rect.size.width =fmax(bounds.size.width - rect.origin.x,0);
941940
rect.origin.x = bounds.size.width - rect.size.width;
942-
NSTextView* messagebox = [[[NSTextViewalloc]initWithFrame: rect]autorelease];
941+
NSTextView* messagebox = [[NSTextViewalloc]initWithFrame: rect];
943942
messagebox.textContainer.maximumNumberOfLines =2;
944943
messagebox.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
945944
messagebox.alignment = NSTextAlignmentRight;
@@ -949,7 +948,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
949948
/* if selectable, the messagebox can become first responder,
950949
* which is not supposed to happen*/
951950
[[windowcontentView]addSubview: messagebox];
952-
[messageboxrelease];
953951
[[windowcontentView]display];
954952

955953
self->messagebox = messagebox;
@@ -959,7 +957,6 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
959957
staticvoid
960958
NavigationToolbar2_dealloc(NavigationToolbar2 *self)
961959
{
962-
[self->handlerrelease];
963960
Py_TYPE(self)->tp_free((PyObject*)self);
964961
}
965962

@@ -1060,36 +1057,6 @@ + (WindowServerConnectionManager *)sharedManager
10601057
return sharedWindowServerConnectionManager;
10611058
}
10621059

1063-
+ (id)allocWithZone:(NSZone *)zone
1064-
{
1065-
return [[selfsharedManager]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-
- (onewayvoid)release
1084-
{
1085-
// Don't release a singleton object
1086-
}
1087-
1088-
- (id)autorelease
1089-
{
1090-
return self;
1091-
}
1092-
10931060
- (void)launch:(NSNotification*)notification
10941061
{
10951062
CFRunLoopRef runloop;
@@ -1167,7 +1134,6 @@ - (void)dealloc
11671134
* content view of this window was increased during the call to addSubview,
11681135
* and is decreased during the call to [super dealloc].
11691136
*/
1170-
[superdealloc];
11711137
}
11721138
@end
11731139

@@ -1189,7 +1155,6 @@ - (void)dealloc
11891155
{
11901156
FigureCanvas* fc = (FigureCanvas*)canvas;
11911157
if (fc) { fc->view =NULL; }
1192-
[superdealloc];
11931158
}
11941159

11951160
- (void)setCanvas: (PyObject*)newCanvas

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp