Skip to content

Commit c0bb0ce

Browse files
authored
Merge pull request #1601 from compnerd/closure
closure: port use of dlsym to Windows
2 parents bf2cc1c + e491efb commit c0bb0ce

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

closure/runtime.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414
#include <stdint.h>
15+
#if TARGET_OS_WIN32
16+
#include <Windows.h>
17+
#include <Psapi.h>
18+
#else
1519
#include <dlfcn.h>
20+
#endif
1621
#if __has_include(<os/assumes.h>)
1722
#include <os/assumes.h>
1823
#else
@@ -245,7 +250,26 @@ void _Block_use_RR( void (*retain)(const void *),
245250
void (*release)(const void *)) {
246251
_Block_retain_object = retain;
247252
_Block_release_object = release;
253+
#if TARGET_OS_WIN32
254+
HANDLE hProcess = GetCurrentProcess();
255+
HMODULE hModule[1024];
256+
DWORD cbNeeded = 0;
257+
258+
if (!EnumProcessModules(hProcess, hModule, sizeof(hModule), &cbNeeded))
259+
return;
260+
if (cbNeeded > sizeof(hModule))
261+
return;
262+
263+
for (unsigned I = 0; I < (cbNeeded / sizeof(HMODULE)); ++I) {
264+
_Block_destructInstance =
265+
(void (*)(const void *))GetProcAddress(hModule[I],
266+
"objc_destructInstance");
267+
if (_Block_destructInstance)
268+
break;
269+
}
270+
#else
248271
_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance");
272+
#endif
249273
}
250274

251275
// Called from CF to indicate MRR. Newer version uses a versioned structure, so we can add more functions

0 commit comments

Comments
 (0)