From 18d6a75ef7c0d82cbdfadfd1a90e53a119a00d1c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 7 Feb 2024 17:19:00 +0000 Subject: [PATCH] [wasm] Port BlocksRuntime for no dlfcn.h platforms 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. --- Sources/BlocksRuntime/runtime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/BlocksRuntime/runtime.c b/Sources/BlocksRuntime/runtime.c index 1b7945b949..547d832e50 100644 --- a/Sources/BlocksRuntime/runtime.c +++ b/Sources/BlocksRuntime/runtime.c @@ -15,7 +15,7 @@ #if TARGET_OS_WIN32 #include #include -#else +#elif __has_include() #include #endif #if __has_include() @@ -268,7 +268,11 @@ void _Block_use_RR( void (*retain)(const void *), break; } #else +# if __has_include() _Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance"); +# else + _Block_destructInstance = _Block_destructInstance_default; +# endif #endif }