Skip to content

Commit 17a8ef3

Browse files
Alexpuxlazka
authored andcommitted
Add support for stdcall without underscore
This is the case used in MINGW Co-authored-by: Алексей <[email protected]>
1 parent e974a9d commit 17a8ef3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,13 +3403,32 @@ static PPROC FindAddress(void *handle, const char *name, PyObject *type)
34033403
mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */
34043404
if (!mangled_name)
34053405
return NULL;
3406+
/* Issue: for stdcall decorated export functions MSVC compiler adds
3407+
* underscore, but GCC compiler create them without. This is
3408+
* visible by example for _ctypes_test.pyd module.
3409+
* As well functions from system libraries are without underscore.
3410+
* Solutions:
3411+
* - If a python module is build with gcc option --add-stdcall-alias
3412+
* the module will contain XXX as alias for function XXX@ as result
3413+
* first search in this method will succeed.
3414+
* - Distutil may use compiler to create def-file, to modify it as
3415+
* add underscore alias and with new def file to create module.
3416+
* - Or may be just to search for function without underscore.
3417+
*/
34063418
for (i = 0; i < 32; ++i) {
34073419
sprintf(mangled_name, "_%s@%d", name, i*4);
34083420
Py_BEGIN_ALLOW_THREADS
34093421
address = (PPROC)GetProcAddress(handle, mangled_name);
34103422
Py_END_ALLOW_THREADS
34113423
if (address)
34123424
return address;
3425+
/* search for function without underscore as weel */
3426+
sprintf(mangled_name, "%s@%d", name, i*4);
3427+
Py_BEGIN_ALLOW_THREADS
3428+
address = (PPROC)GetProcAddress(handle, mangled_name);
3429+
Py_END_ALLOW_THREADS
3430+
if (address)
3431+
return address;
34133432
}
34143433
return NULL;
34153434
#endif

0 commit comments

Comments
 (0)