Skip to content

Commit

Permalink
Add dynamic loading support for MINGW
Browse files Browse the repository at this point in the history
Co-authored-by: Алексей <alexey.pawlow@gmail.com>
  • Loading branch information
Alexpux authored and lazka committed Jul 19, 2023
1 parent b738276 commit 8911010
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,12 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile
-DSHLIB_EXT='"$(EXT_SUFFIX)"' \
-o $@ $(srcdir)/Python/dynload_hpux.c

Python/dynload_win.o: $(srcdir)/Python/dynload_win.c Makefile
$(CC) -c $(PY_CORE_CFLAGS) \
-DSHLIB_SUFFIX='"$(SHLIB_SUFFIX)"' \
-DEXT_SUFFIX='"$(EXT_SUFFIX)"' \
-o $@ $(srcdir)/Python/dynload_win.c

Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h
$(CC) -c $(PY_CORE_CFLAGS) \
-DABIFLAGS='"$(ABIFLAGS)"' \
Expand Down
9 changes: 7 additions & 2 deletions Python/dynload_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"

const char *_PyImport_DynLoadFiletab[] = {
#ifdef EXT_SUFFIX
EXT_SUFFIX, /* include SOABI flags where is encoded debug */
#endif
#ifdef SHLIB_SUFFIX
"-abi" PYTHON_ABI_STRING SHLIB_SUFFIX,
#endif
PYD_TAGGED_SUFFIX,
PYD_UNTAGGED_SUFFIX,
NULL
Expand Down Expand Up @@ -249,8 +255,7 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
ensure DLLs adjacent to the PYD are preferred. */
Py_BEGIN_ALLOW_THREADS
hDLL = LoadLibraryExW(wpathname, NULL,
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
LOAD_WITH_ALTERED_SEARCH_PATH);
Py_END_ALLOW_THREADS
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free(wpathname);
Expand Down
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,9 @@ if test -z "$SHLIB_SUFFIX"; then
CYGWIN*) SHLIB_SUFFIX=.dll;;
*) SHLIB_SUFFIX=.so;;
esac
case $host_os in
mingw*) SHLIB_SUFFIX=.dll;;
esac
fi
AC_MSG_RESULT($SHLIB_SUFFIX)

Expand Down Expand Up @@ -4698,6 +4701,13 @@ then
fi
;;
esac
case $host in
*-*-mingw*)
DYNLOADFILE="dynload_win.o"
extra_machdep_objs="$extra_machdep_objs PC/dl_nt.o"
CFLAGS_NODIST="$CFLAGS_NODIST -DMS_DLL_ID='\"$VERSION\"'"
;;
esac
fi
AC_MSG_RESULT($DYNLOADFILE)
if test "$DYNLOADFILE" != "dynload_stub.o"
Expand Down Expand Up @@ -6483,6 +6493,12 @@ case "$ac_cv_computed_gotos" in yes*)
AC_DEFINE(HAVE_COMPUTED_GOTOS, 1,
[Define if the C compiler supports computed gotos.])
esac
case $host_os in
mingw*)
dnl Synchronized with _PyImport_DynLoadFiletab (dynload_win.c)
dnl Do not use more then one dot on this platform !
EXT_SUFFIX=-$SOABI$SHLIB_SUFFIX;;
esac

case $ac_sys_system in
AIX*)
Expand Down

0 comments on commit 8911010

Please sign in to comment.