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

MNT: Change objective C code to Automatic Reference Counting (ARC)#23060

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
greglucas merged 2 commits intomatplotlib:mainfromgreglucas:macosx-ARC
Jun 26, 2022

Conversation

greglucas
Copy link
Contributor

PR Summary

This updates the objective C macosx backend to use automatic reference counting instead of relying on manual tracking and releasing of the memory. It seems like this is recommended now, but I am definitely not an expert in this.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (andpytest passes).
  • [N/A] IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

@greglucasgreglucas added this to thev3.6.0 milestoneMay 18, 2022
@jklymak
Copy link
Member

The backend seems to continue to function after this. However, I'm not sure how you would like it tested.

@greglucas
Copy link
ContributorAuthor

I'm not sure it is "testable"... Here is the traceback I was using to make it compatible if I enable ARC on main currently. This was in an effort to trace down the memory leaks.

Here is the ARC recommendation:https://microsoft.github.io/objc-guide/MethodsAndImplementations/AutomaticReferenceCounting.html#convention

expand for traceback
    src/_macosx.m:336:17: error: 'release' is unavailable: not available in automatic reference counting mode        [self->view release];                    ^    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:37:1: note: 'release' has been explicitly marked unavailable here    - (oneway void)release OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:336:17: error: ARC forbids explicit message send of 'release'        [self->view release];         ~~~~~~~~~~ ^    src/_macosx.m:344:45: error: cast of Objective-C pointer type 'View *' to C pointer type 'void *' requires a bridged cast                                   (void*)self, (void*)(self->view));                                                ^~~~~~~~~~~~~~~~~~~    src/_macosx.m:344:46: note: use __bridge to convert directly (no change in ownership)                                   (void*)self, (void*)(self->view));                                                 ^                                                 __bridge    src/_macosx.m:344:52: note: use CFBridgingRetain call to make an ARC object available as a +1 'void *'                                   (void*)self, (void*)(self->view));                                                       ^                                                       CFBridgingRetain    src/_macosx.m:548:17: error: 'release' is unavailable: not available in automatic reference counting mode            [window release];                    ^    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:37:1: note: 'release' has been explicitly marked unavailable here    - (oneway void)release OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:548:17: error: ARC forbids explicit message send of 'release'            [window release];             ~~~~~~ ^    src/_macosx.m:601:46: error: cast of Objective-C pointer type 'Window *' to C pointer type 'void *' requires a bridged cast                                   (void*) self, (void*)(self->window));                                                 ^~~~~~~~~~~~~~~~~~~~~    src/_macosx.m:601:47: note: use __bridge to convert directly (no change in ownership)                                   (void*) self, (void*)(self->window));                                                  ^                                                  __bridge    src/_macosx.m:601:53: note: use CFBridgingRetain call to make an ARC object available as a +1 'void *'                                   (void*) self, (void*)(self->window));                                                        ^                                                        CFBridgingRetain    src/_macosx.m:651:81: error: ARC forbids explicit message send of 'autorelease'            NSImage* image = [[[NSImage alloc] initByReferencingFile: ns_icon_path] autorelease];                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^    src/_macosx.m:651:81: error: 'autorelease' is unavailable: not available in automatic reference counting mode    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:38:1: note: 'autorelease' has been explicitly marked unavailable here    - (instancetype)autorelease OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:682:60: error: ARC forbids explicit message send of 'autorelease'                               encoding: NSUTF8StringEncoding] autorelease];                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^    src/_macosx.m:682:60: error: 'autorelease' is unavailable: not available in automatic reference counting mode    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:38:1: note: 'autorelease' has been explicitly marked unavailable here    - (instancetype)autorelease OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:769:67: error: must explicitly describe intended ownership of an object array parameter    - (void)installCallbacks:(SEL[7])actions forButtons:(NSButton*[7])buttons;                                                                      ^    src/_macosx.m:795:67: error: must explicitly describe intended ownership of an object array parameter    - (void)installCallbacks:(SEL[7])actions forButtons:(NSButton*[7])buttons                                                                      ^    src/_macosx.m:790:5: error: the result of a delegate init call must be immediately returned or assigned to 'self'        [self init];        ^~~~~~~~~~~    src/_macosx.m:836:18: error: 'release' is unavailable: not available in automatic reference counting mode            [handler release];                     ^    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:37:1: note: 'release' has been explicitly marked unavailable here    - (oneway void)release OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:836:18: error: ARC forbids explicit message send of 'release'            [handler release];             ~~~~~~~ ^    src/_macosx.m:928:21: error: 'release' is unavailable: not available in automatic reference counting mode            [buttons[i] release];                        ^    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:37:1: note: 'release' has been explicitly marked unavailable here    - (oneway void)release OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:928:21: error: ARC forbids explicit message send of 'release'            [buttons[i] release];             ~~~~~~~~~~ ^    src/_macosx.m:929:16: error: 'release' is unavailable: not available in automatic reference counting mode            [image release];                   ^    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/objc/NSObject.h:37:1: note: 'release' has been explicitly marked unavailable here    - (oneway void)release OBJC_ARC_UNAVAILABLE;    ^    src/_macosx.m:929:16: error: ARC forbids explicit message send of 'release'            [image release];             ~~~~~ ^    fatal error: too many errors emitted, stopping now [-ferror-limit=]    20 errors generated.    error: command '/usr/bin/clang' failed with exit code 1

@QuLogicQuLogic added the CI: Run cibuildwheelRun wheel building tests on a PR labelMay 20, 2022
Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know anything about this, other than that this PR works on my machine and it doesn't appear to do anything malicious. Is there anyone else who ha sufficient macOS experience to vouch for this? Also is ARC sufficiently back compatible?

@greglucas
Copy link
ContributorAuthor

Also is ARC sufficiently back compatible?

It came in MacOSX 10.7, so it has been around for quite a while now. Note that I did put a check at the top of the file as well so this will throw an error during compile if ARC is not enabled.

@jklymak
Copy link
Member

marking as merge w/ one review unless another Mac user wants to review I will merge in a week or so...

@@ -1064,36 +1060,6 @@ + (WindowServerConnectionManager *)sharedManager
return sharedWindowServerConnectionManager;
}

+ (id)allocWithZone:(NSZone *)zone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

https://developer.apple.com/documentation/objectivec/nsobject/1571945-allocwithzone

Do not override allocWithZone: to include any initialization code. Instead, class-specific versions of init... methods.

OK, good thing we are deleting it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

it is also not clear we used this as the actual call site just above uses[[super allocWithZone:Null] init] ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This all came in via7bacdc5 with the commit message

This patch allows interrupts to be delivered once Python is fixed.

greglucasand others added2 commitsJune 24, 2022 20:08
This updates the objective C macosx backend to use automatic referencecounting instead of relying on manual tracking and releasing of the memory.
@tacaswell
Copy link
Member

I took the liberty of rebasing and removing the line that was breaking the wheel build.

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please merge this@greglucas if you are happy with the commit I added.

@greglucas
Copy link
ContributorAuthor

Yes, that commit looks good, it must have come in since the last rebase. Thanks for fixing it!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Labels
CI: Run cibuildwheelRun wheel building tests on a PRGUI: MacOSX
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

4 participants
@greglucas@jklymak@tacaswell@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp