-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wasm] Port BlocksRuntime for no dlfcn.h platforms #4869
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
[wasm] Port BlocksRuntime for no dlfcn.h platforms #4869
Conversation
@swift-ci test |
Sources/BlocksRuntime/runtime.c
Outdated
_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance"); | ||
# else | ||
assert(0 && "No way to find objc_destructInstance on this platform"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just set _Block_destructInstance
to NULL
? IIRC, _Block_destructInstance(...)
should do nothing if the pointer is NULL (this is how weak pointers work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Block_destructInstance
can be called without null guard https://github.com/apple/swift-corelibs-foundation/blob/dbca8c7ddcfd19f7f6f6e1b60fd3ee3f748e263c/Sources/BlocksRuntime/runtime.c#L530, so _Block_destructInstance_default
might be safer here
BlocksRuntime uses dlsym to find objc_destructInstance, which is not available on all platforms. This change adds a check for dlfcn.h and only uses dlsym if it is available and otherwise crashes the program. The crash will not usually happen, as `_Block_use_RR` is only called from objc-auto, which is not available for such platforms.
ad1dfe8
to
18d6a75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me. Does this actually get used? We have too many copies of blocks runtime (compiler-rt, libdispatch, and Foundation). I believe on Windows at least, we use the libdispatch copy universally.
Thanks @compnerd! Right, this change needs to be also applied to those copies eventually. |
@swift-ci please test |
This seems to suggest the CF code is not being compiled with the correct flags on Darwin. |
@parkera Yes, would you mind checking if the upstream has already fixed it or not? #4866 (comment) |
@kateinoigakukun I don't think that |
@compnerd Sorry, I don't understand why you mentioned assemblers here. Would you mind elaborating a little bit more? |
Oh, I saw the old version of the comment where |
Ah, that's my bad, sorry for confusion 😓 |
@swift-ci test Windows platform |
BlocksRuntime uses dlsym to find objc_destructInstance, which is not available on all platforms. This change adds a check for dlfcn.h and only uses dlsym if it is available and otherwise crashes the program.
The crash will not usually happen, as
_Block_use_RR
is only called from objc-auto, which is not available for such platforms.