Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV (Address boundary error) on Apple Silicon M1, Big Sur 11.5.2 #12

Closed
psobolewskiPhD opened this issue Sep 12, 2021 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@psobolewskiPhD
Copy link

psobolewskiPhD commented Sep 12, 2021

This is related to:
#11
I reported crashes on Big Sur, but it seems my issue wasn't related to Big Sur per se, but to architecture (arm64, Apple Silicon M1). In fact the version detection added in 0.4 doesn't seem to be needed in my environment (Big Sur 11.5.2, python 3.9.6/7)

I've narrowed down the fault to the mismatch in args between:

objc.objc_msgSend.argtypes = [void_p, void_p]

and
key = msg(NSString, n("stringWithUTF8String:"), _utf8('AppleInterfaceStyle'))
appearanceNS = msg(stdUserDef, n('stringForKey:'), void_p(key))

I believe this is due to arch changes, based on:
https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code

As a simple test, add at line 41: (after C is defined)

NSString = C('NSString')
objc.objc_msgSend(NSString, n("stringWithUTF8String:"), _utf8("reason"))

with: objc.objc_msgSend.argtypes = [void_p, void_p] this crashes.
with: objc.objc_msgSend.argtypes = [void_p, void_p, void_p] this runs.

As such, I was able to patch this locally by changing the number of argtypes and args for all msg. I can do a PR, but it will for sure need some extra testing/review.

Edit: I have a more elegant fix, where just the .argtypes is changed just for the 3 arg msg lines.

@albertosottile
Copy link
Owner

albertosottile commented Sep 12, 2021

Thanks for narrowing this down. Could you try the code I just pushed in https://github.com/albertosottile/darkdetect/tree/cfunctype and check if it works on your M1 Mac?

EDIT: I did not realize you also had a fix to avoid passing None as third argument or change the other lines... I apologize if you still want to open a PR.

@psobolewskiPhD
Copy link
Author

Works for both light and dark!

@albertosottile albertosottile added the bug Something isn't working label Sep 12, 2021
@psobolewskiPhD
Copy link
Author

EDIT: I did not realize you also had a fix to avoid passing None as third argument or change the other lines... I apologize if you still want to open a PR.

It's not a problem! I was just hacking at it to see how/why. Your solution seems much more elegant!

@albertosottile
Copy link
Owner

Ok, I will then proceed with tests (for what I can run, though, as I still do not own a M1 Mac :( ) and release this fix as soon as possible.

Once again, thanks for finding and debugging this issue. I wonder how this code had worked with x86_64 up to now...

@albertosottile
Copy link
Owner

Fixed in 0.5.0.

@psobolewskiPhD
Copy link
Author

Yup! And live on pip

Successfully installed darkdetect-0.5.0
╭─ ~ ···································································· ✔ ─╮
╰─ ipython                                                      (napari-test) ─╯
Python 3.9.7 | packaged by conda-forge | (default, Sep  2 2021, 17:55:16) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import darkdetect

In [2]: darkdetect.theme()
Out[2]: 'Light'
<<<SWITCH TO DARK>>>
In [3]: darkdetect.theme()
Out[3]: 'Dark'

Ahsoka added a commit to Ahsoka/beskar that referenced this issue Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants