Blame 0462-MINGW-support-stdcall-without-underscore.patch

ddb6764
diff -rupN Python-2.7.13/Modules/_ctypes/_ctypes.c Python-2.7.13-new/Modules/_ctypes/_ctypes.c
ddb6764
--- Python-2.7.13/Modules/_ctypes/_ctypes.c	2016-12-17 21:05:07.000000000 +0100
ddb6764
+++ Python-2.7.13-new/Modules/_ctypes/_ctypes.c	2017-01-21 01:46:08.854582487 +0100
ddb6764
@@ -3216,11 +3216,28 @@ static PPROC FindAddress(void *handle, c
ddb6764
     mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */
ddb6764
     if (!mangled_name)
ddb6764
         return NULL;
ddb6764
+    /* Issue: for stdcall decorated export functions MSVC compiler adds
ddb6764
+     * underscore, but GCC compiler create them without. This is
ddb6764
+     * visible by example for _ctypes_test.pyd module.
ddb6764
+     * As well functions from system libraries are without underscore.
ddb6764
+     * Solutions:
ddb6764
+     * - If a python module is build with gcc option --add-stdcall-alias
ddb6764
+     * the module will contain XXX as alias for function XXX@ as result
ddb6764
+     * first search in this method will succeed.
ddb6764
+     * - Distutil may use compiler to create def-file, to modify it as
ddb6764
+     * add underscore alias and with new def file to create module.
ddb6764
+     * - Or may be just to search for function without underscore.
ddb6764
+     */
ddb6764
     for (i = 0; i < 32; ++i) {
ddb6764
         sprintf(mangled_name, "_%s@%d", name, i*4);
ddb6764
         address = (PPROC)GetProcAddress(handle, mangled_name);
ddb6764
         if (address)
ddb6764
             return address;
ddb6764
+        /* search for function without underscore as weel */
ddb6764
+        sprintf(mangled_name, "%s@%d", name, i*4);
ddb6764
+        address = (PPROC)GetProcAddress(handle, mangled_name);
ddb6764
+        if (address)
ddb6764
+            return address;
ddb6764
     }
ddb6764
     return NULL;
ddb6764
 #endif