Skip to content

Commit

Permalink
Add support for stdcall without underscore
Browse files Browse the repository at this point in the history
This is the case used in MINGW

Co-authored-by: Алексей <alexey.pawlow@gmail.com>
  • Loading branch information
Alexpux authored and lazka committed Aug 25, 2023
1 parent e974a9d commit 17a8ef3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3403,13 +3403,32 @@ static PPROC FindAddress(void *handle, const char *name, PyObject *type)
mangled_name = alloca(strlen(name) + 1 + 1 + 1 + 3); /* \0 _ @ %d */
if (!mangled_name)
return NULL;
/* Issue: for stdcall decorated export functions MSVC compiler adds
* underscore, but GCC compiler create them without. This is
* visible by example for _ctypes_test.pyd module.
* As well functions from system libraries are without underscore.
* Solutions:
* - If a python module is build with gcc option --add-stdcall-alias
* the module will contain XXX as alias for function XXX@ as result
* first search in this method will succeed.
* - Distutil may use compiler to create def-file, to modify it as
* add underscore alias and with new def file to create module.
* - Or may be just to search for function without underscore.
*/
for (i = 0; i < 32; ++i) {
sprintf(mangled_name, "_%s@%d", name, i*4);
Py_BEGIN_ALLOW_THREADS
address = (PPROC)GetProcAddress(handle, mangled_name);
Py_END_ALLOW_THREADS
if (address)
return address;
/* search for function without underscore as weel */
sprintf(mangled_name, "%s@%d", name, i*4);
Py_BEGIN_ALLOW_THREADS
address = (PPROC)GetProcAddress(handle, mangled_name);
Py_END_ALLOW_THREADS
if (address)
return address;
}
return NULL;
#endif
Expand Down

0 comments on commit 17a8ef3

Please sign in to comment.