summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2014-06-30 15:10:29 +0200
committerArmin Rigo <arigo@tunes.org>2014-06-30 15:10:29 +0200
commit7237bc6b6522fdafa0b28ec31e8d095b39ac394d (patch)
tree91413a148e92d7809a488a953f5bce4a1a1c7cc0
parent68d977c08833f2acd840cd532334936f2b94bf2f (diff)
downloadcffi-7237bc6b6522fdafa0b28ec31e8d095b39ac394d.tar.gz
Attempt to copy ctypes' name-mangling capability "_name@num".
-rw-r--r--c/misc_win32.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/c/misc_win32.h b/c/misc_win32.h
index 41601e7..1033b78 100644
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -192,7 +192,27 @@ static void *dlopen(const char *filename, int flag)
static void *dlsym(void *handle, const char *symbol)
{
- return GetProcAddress((HMODULE)handle, symbol);
+ void *address = GetProcAddress((HMODULE)handle, symbol);
+#ifndef MS_WIN64
+ if (!address) {
+ /* If 'symbol' is not found, then try '_symbol@N' for N in
+ (0, 4, 8, 12, ..., 124). Unlike ctypes, we try to do that
+ for any symbol, although in theory it should only be done
+ for __stdcall functions.
+ */
+ int i;
+ char *mangled_name = alloca(1 + strlen(symbol) + 1 + 3 + 1);
+ if (!mangled_name)
+ return NULL;
+ for (i = 0; i < 32; i++) {
+ sprintf(mangled_name, "_%s@%d", symbol, i * 4);
+ address = GetProcAddress((HMODULE)handle, mangled_name);
+ if (address)
+ break;
+ }
+ }
+#endif
+ return address;
}
static void dlclose(void *handle)