Skip to content

Commit ad1dfe8

Browse files
[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.
1 parent dbca8c7 commit ad1dfe8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/BlocksRuntime/runtime.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#if TARGET_OS_WIN32
1616
#include <Windows.h>
1717
#include <Psapi.h>
18-
#else
18+
#elif __has_include(<dlfcn.h>)
1919
#include <dlfcn.h>
2020
#endif
2121
#if __has_include(<os/assumes.h>)
@@ -268,7 +268,11 @@ void _Block_use_RR( void (*retain)(const void *),
268268
break;
269269
}
270270
#else
271+
# if __has_include(<dlfcn.h>)
271272
_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance");
273+
# else
274+
assert(0 && "No way to find objc_destructInstance on this platform");
275+
# endif
272276
#endif
273277
}
274278

0 commit comments

Comments
 (0)