From aa9050ead923d73ce2665972aa3a3083958e48a6 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 3 Jul 2021 13:37:44 -0700 Subject: [PATCH 01/42] Add detection support for macos12/darwin21. --- Python/dynload_shlib.c | 2 ++ configure | 28 ++++++++++++++++++++++++++-- configure.ac | 33 +++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index 23828898d35a5d..90509947b20a33 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -37,6 +37,8 @@ const char *_PyImport_DynLoadFiletab[] = { #ifdef __CYGWIN__ ".dll", +#elif defined(__APPLE__) + "." SOABI ".dylib", #else /* !__CYGWIN__ */ "." SOABI ".so", #ifdef ALT_SOABI diff --git a/configure b/configure index 9de3047134ba83..5274beb0e821f1 100755 --- a/configure +++ b/configure @@ -3345,6 +3345,10 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; + *-*-darwin*) + ac_sys_system=Darwin + ac_sys_release=20.0 + ;; *-*-vxworks*) ac_sys_system=VxWorks ;; @@ -3394,6 +3398,9 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; + *-*-darwin*) + _host_cpu=$host_cpu + ;; *-*-vxworks*) _host_cpu=$host_cpu ;; @@ -5364,8 +5371,14 @@ cat >> conftest.c <> conftest.c <&1 < /dev/null` in +case `"$ac_prog" -Wl,-V 2>&1 < /dev/null` in *GNU*) GNULD=yes;; *) @@ -2503,6 +2516,16 @@ case $ac_sys_system/$ac_sys_release in } ]])],[ac_osx_32bit=yes],[ac_osx_32bit=no],[ac_osx_32bit=yes]) +if test "$cross_compiling" = yes; then : + case $cpu in + aarch64|arm64) + MACOSX_DEFAULT_ARCH="arm64" + ;; + x86_64) + MACOSX_DEFAULT_ARCH="x86_64" + ;; + esac +else if test "${ac_osx_32bit}" = "yes"; then case `/usr/bin/arch` in i386) @@ -2532,6 +2555,7 @@ case $ac_sys_system/$ac_sys_release in esac fi +fi LIBTOOL_CRUFT=$LIBTOOL_CRUFT" -lSystem -lSystemStubs -arch_only ${MACOSX_DEFAULT_ARCH}" LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)' @@ -2631,6 +2655,7 @@ if test -z "$SHLIB_SUFFIX"; then *) SHLIB_SUFFIX=.sl;; esac ;; + Darwin*) SHLIB_SUFFIX=.dylib;; CYGWIN*) SHLIB_SUFFIX=.dll;; *) SHLIB_SUFFIX=.so;; esac From 4ec256869ace584a523a33cf51c37cb7345a56be Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 20 Aug 2021 23:21:32 -0700 Subject: [PATCH 02/42] Fix test for darwin in setup.py. --- configure.ac | 35 ++++++++++++++++++++++++----------- setup.py | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 819586c463f489..29ef11c791ab43 100644 --- a/configure.ac +++ b/configure.ac @@ -401,6 +401,11 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; + *-*-mingw32*) + ac_sys_system=MinGW32 + CFLAGS_NODIST="${CFLAGS_NODIST} -DMS_WINDOWS -DMS_WIN64 -DPY3_DLLNAME=python${VERSION}" + LDFLAGS_NODIST="${LDFLAGS} -municode" + ;; *-*-darwin*) ac_sys_system=Darwin ac_sys_release=21.0 @@ -432,6 +437,7 @@ then aix*) MACHDEP="aix";; linux*) MACHDEP="linux";; cygwin*) MACHDEP="cygwin";; + mingw32*) MACHDEP="windows";; darwin*) MACHDEP="darwin";; '') MACHDEP="unknown";; esac @@ -453,6 +459,9 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; + *-*-mingw32*) + _host_cpu=$host_cpu + ;; *-*-darwin*) _host_cpu=$host_cpu ;; @@ -1098,7 +1107,7 @@ AC_ARG_ENABLE(shared, if test -z "$enable_shared" then case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) enable_shared="yes";; *) enable_shared="no";; @@ -1148,9 +1157,11 @@ if test $enable_shared = "yes"; then PY_ENABLE_SHARED=1 AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.]) case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) + BLDLIBRARY='-L. -lpython$(LDVERSION)' LDLIBRARY='libpython$(LDVERSION).dll.a' DLLLIBRARY='libpython$(LDVERSION).dll' + PY3LIBRARY='$(LDLIBRARY)' ;; SunOS*) LDLIBRARY='libpython$(LDVERSION).so' @@ -1198,7 +1209,7 @@ if test $enable_shared = "yes"; then else # shared is disabled PY_ENABLE_SHARED=0 case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) BLDLIBRARY='$(LIBRARY)' LDLIBRARY='libpython$(LDVERSION).dll.a' ;; @@ -1247,7 +1258,7 @@ AC_PROG_MKDIR_P AC_SUBST(LN) if test -z "$LN" ; then case $ac_sys_system in - CYGWIN*) LN="ln -s";; + CYGWIN*|MinGW*) LN="ln -s";; *) LN=ln;; esac fi @@ -2656,7 +2667,7 @@ if test -z "$SHLIB_SUFFIX"; then esac ;; Darwin*) SHLIB_SUFFIX=.dylib;; - CYGWIN*) SHLIB_SUFFIX=.dll;; + CYGWIN*|MinGW*) SHLIB_SUFFIX=.dll;; *) SHLIB_SUFFIX=.so;; esac fi @@ -2781,6 +2792,9 @@ then CYGWIN*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base" LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";; + MinGW*) + LDSHARED='$(CC) -shared' + LDCXXSHARED='$(CXX) -shared';; *) LDSHARED="ld";; esac fi @@ -2873,7 +2887,7 @@ then LINKFORSHARED="-Xlinker --export-dynamic" fi;; esac;; - CYGWIN*) + CYGWIN*|MinGW*) if test $enable_shared = "no" then LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)' @@ -2897,7 +2911,7 @@ AC_MSG_CHECKING(CFLAGSFORSHARED) if test ! "$LIBRARY" = "$LDLIBRARY" then case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) # Cygwin needs CCSHARED when building extension DLLs # but not when building the interpreter DLL. CFLAGSFORSHARED='';; @@ -3387,7 +3401,7 @@ if test "$posix_threads" = "yes"; then fi AC_CHECK_FUNCS(pthread_sigmask, [case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) AC_DEFINE(HAVE_BROKEN_PTHREAD_SIGMASK, 1, [Define if pthread_sigmask() does not work on your system.]) ;; @@ -4868,15 +4882,14 @@ AC_MSG_CHECKING(LDVERSION) LDVERSION='$(VERSION)$(ABIFLAGS)' AC_MSG_RESULT($LDVERSION) -# On Android and Cygwin the shared libraries must be linked with libpython. +# On Android and Cygwin/MinGW the shared libraries must be linked with libpython. AC_SUBST(LIBPYTHON) -if test -n "$ANDROID_API_LEVEL" -o "$MACHDEP" = "cygwin"; then +if test -n "$ANDROID_API_LEVEL" -o "$MACHDEP" = "cygwin" -o "$MACHDEP" = "windows"; then LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" else LIBPYTHON='' fi - AC_SUBST(BINLIBDEST) BINLIBDEST='$(LIBDIR)/python$(VERSION)' diff --git a/setup.py b/setup.py index 7cfcbf4ab205ef..e4e42c83696dfb 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ def get_platform(): HOST_PLATFORM = get_platform() MS_WINDOWS = (HOST_PLATFORM == 'win32') CYGWIN = (HOST_PLATFORM == 'cygwin') -MACOS = (HOST_PLATFORM == 'darwin') +MACOS = (HOST_PLATFORM.startswith('darwin')) AIX = (HOST_PLATFORM.startswith('aix')) VXWORKS = ('vxworks' in HOST_PLATFORM) CC = os.environ.get("CC") From 68a31be07606e2796b7eeb0699c8723576a9f7c2 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:21:22 -0800 Subject: [PATCH 03/42] Forward LIBPYTHON if specified to module builds. --- Makefile.pre.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index ee85f35b10da41..06130d38db978e 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -626,10 +626,10 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ - echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) $(LIBPYTHON)' OPT='$(OPT)' \ _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \ - $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) $(LIBPYTHON)' OPT='$(OPT)' \ _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build From fa31b2592a8809a17fbb71fbb5c647b1c86342c6 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 18 Nov 2021 09:19:08 -0800 Subject: [PATCH 04/42] Add platform triple definitions for mingw targets. --- configure.ac | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 29ef11c791ab43..caa3ec4c5344d3 100644 --- a/configure.ac +++ b/configure.ac @@ -437,7 +437,7 @@ then aix*) MACHDEP="aix";; linux*) MACHDEP="linux";; cygwin*) MACHDEP="cygwin";; - mingw32*) MACHDEP="windows";; + mingw32*) MACHDEP="win32";; darwin*) MACHDEP="darwin";; '') MACHDEP="unknown";; esac @@ -878,6 +878,22 @@ cat >> conftest.c < Date: Wed, 10 Nov 2021 18:33:13 -0800 Subject: [PATCH 05/42] Add missing winerror.h include in PC/errmap.h. --- PC/errmap.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PC/errmap.h b/PC/errmap.h index a7489ab75c6561..1c98440fea889e 100644 --- a/PC/errmap.h +++ b/PC/errmap.h @@ -1,3 +1,5 @@ +#include + int winerror_to_errno(int winerror) { From c46043d0da35d7563e3af0c87ecd3595cc6c75e4 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:33:35 -0800 Subject: [PATCH 06/42] Fix path to errmap.h (PC/errmap.h) in Objects/exceptions.c. --- Objects/exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 9639b4436a078b..2041f2e7c07d50 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -791,7 +791,7 @@ MiddlingExtendsException(PyExc_ImportError, ModuleNotFoundError, ImportError, */ #ifdef MS_WINDOWS -#include "errmap.h" +#include "PC/errmap.h" #endif /* Where a function has a single filename, such as open() or some From 23be75ab9587c10a3379d7c4ab0e8a4c97b3b244 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:56:46 -0800 Subject: [PATCH 07/42] Fix missing import of netioapi.h in Modules.socketmodule.c. --- Modules/socketmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 392cc32f7fa2f6..8dc90eeff52eb2 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -302,6 +302,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\ #include // For if_nametoindex() and if_indextoname() #include +#include /* remove some flags on older version Windows during run-time. https://msdn.microsoft.com/en-us/library/windows/desktop/ms738596.aspx */ From ee5a845501166b7cda6c7fca05fb5ba61d699369 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:42:16 -0800 Subject: [PATCH 08/42] Add equivalent for setenv::LC_TYPE for windows via setlocale::LC_TYPE. --- Python/pylifecycle.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index eeaf20b4617a20..2254ac8e0ecdf2 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -316,7 +316,11 @@ _coerce_default_locale_settings(int warn, const _LocaleCoercionTarget *target) _Py_SetLocaleFromEnv(LC_ALL); /* Set the relevant locale environment variable */ +#ifdef _WIN32 + if (setlocale(LC_CTYPE, newloc)) { +#else if (setenv("LC_CTYPE", newloc, 1)) { +#endif fprintf(stderr, "Error setting LC_CTYPE, skipping C locale coercion\n"); return 0; From 3be4dac11dc9cb3ebe322b3ba5a1ba14d05baf48 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:34:32 -0800 Subject: [PATCH 09/42] Add winconsoleio.c to _io module build. --- Makefile.pre.in | 3 ++- Modules/Setup | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 06130d38db978e..263fed84d0bccb 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -302,7 +302,8 @@ IO_OBJS= \ Modules/_io/bufferedio.o \ Modules/_io/textio.o \ Modules/_io/bytesio.o \ - Modules/_io/stringio.o + Modules/_io/stringio.o \ + Modules/_io/winconsoleio.o ########################################################################## diff --git a/Modules/Setup b/Modules/Setup index 87c6a152f86eac..bc104c6ec3c2b0 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -123,7 +123,7 @@ _thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c # l _locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl # Standard I/O baseline -_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c +_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c _io/winconsoleio.c # faulthandler module faulthandler faulthandler.c From eec23b8b5663dc6f610262bbbedafe82f13fd7d6 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:40:41 -0800 Subject: [PATCH 10/42] Add implementation for PyThread_get_thread_native_id on windows. --- Python/thread_pthread.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 35b9810aa377f2..57216c94f74105 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -359,6 +359,9 @@ PyThread_get_thread_native_id(void) #elif defined(__NetBSD__) lwpid_t native_id; native_id = _lwp_self(); +#elif defined(_WIN32) + void *native_id; + native_id = pthread_gethandle(pthread_self()); #endif return (unsigned long) native_id; } From 3e2de847f17a58340159c5b589d290036432eec6 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:18:38 -0800 Subject: [PATCH 11/42] Remove incorrect IPPROTO enum definition block and instead rely on winsock2.h definitions. --- Modules/socketmodule.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8dc90eeff52eb2..c9d9a45e4dce4e 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -264,40 +264,6 @@ shutdown(how) -- shut down traffic in one or both directions\n\ # include # endif -/* Macros based on the IPPROTO enum, see: https://bugs.python.org/issue29515 */ -#ifdef MS_WINDOWS -#define IPPROTO_ICMP IPPROTO_ICMP -#define IPPROTO_IGMP IPPROTO_IGMP -#define IPPROTO_GGP IPPROTO_GGP -#define IPPROTO_TCP IPPROTO_TCP -#define IPPROTO_PUP IPPROTO_PUP -#define IPPROTO_UDP IPPROTO_UDP -#define IPPROTO_IDP IPPROTO_IDP -#define IPPROTO_ND IPPROTO_ND -#define IPPROTO_RAW IPPROTO_RAW -#define IPPROTO_MAX IPPROTO_MAX -#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS -#define IPPROTO_IPV4 IPPROTO_IPV4 -#define IPPROTO_IPV6 IPPROTO_IPV6 -#define IPPROTO_ROUTING IPPROTO_ROUTING -#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT -#define IPPROTO_ESP IPPROTO_ESP -#define IPPROTO_AH IPPROTO_AH -#define IPPROTO_ICMPV6 IPPROTO_ICMPV6 -#define IPPROTO_NONE IPPROTO_NONE -#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS -#define IPPROTO_EGP IPPROTO_EGP -#define IPPROTO_PIM IPPROTO_PIM -#define IPPROTO_ICLFXBM IPPROTO_ICLFXBM // WinSock2 only -#define IPPROTO_ST IPPROTO_ST // WinSock2 only -#define IPPROTO_CBT IPPROTO_CBT // WinSock2 only -#define IPPROTO_IGP IPPROTO_IGP // WinSock2 only -#define IPPROTO_RDP IPPROTO_RDP // WinSock2 only -#define IPPROTO_PGM IPPROTO_PGM // WinSock2 only -#define IPPROTO_L2TP IPPROTO_L2TP // WinSock2 only -#define IPPROTO_SCTP IPPROTO_SCTP // WinSock2 only -#endif /* MS_WINDOWS */ - /* Provides the IsWindows7SP1OrGreater() function */ #include // For if_nametoindex() and if_indextoname() From bc016d57b938c9501653e735d7acda1b7fc226a2 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:20:18 -0800 Subject: [PATCH 12/42] Remove undefined PyInitFrozenExtensions function and compile PC/frozen_dllmain.c PC for PyWinFreeze_ExeInit/Term routines. --- Makefile.pre.in | 3 ++- PC/frozen_dllmain.c | 4 +++- Python/frozenmain.c | 4 ---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 263fed84d0bccb..74b467a28376c7 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -457,7 +457,8 @@ LIBRARY_OBJS_OMIT_FROZEN= \ LIBRARY_OBJS= \ $(LIBRARY_OBJS_OMIT_FROZEN) \ - Python/frozen.o + Python/frozen.o \ + PC/frozen_dllmain.o ########################################################################## # DTrace diff --git a/PC/frozen_dllmain.c b/PC/frozen_dllmain.c index 0156c5008bc93a..17d013492cc029 100644 --- a/PC/frozen_dllmain.c +++ b/PC/frozen_dllmain.c @@ -44,6 +44,8 @@ changed, here is a snippet from the pythoncom extension module. // end of example code from pythoncom's DllMain.cpp ***************************************************************************/ +#ifdef MS_WINDOWS +#include "pymacro.h" #include "windows.h" static char *possibleModules[] = { @@ -131,4 +133,4 @@ BOOL CallModuleDllMain(char *modName, DWORD dwReason) } return (*pfndllmain)(hmod, dwReason, NULL); } - +#endif diff --git a/Python/frozenmain.c b/Python/frozenmain.c index dd04d609d24f93..a6855033334dde 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -8,7 +8,6 @@ #ifdef MS_WINDOWS extern void PyWinFreeze_ExeInit(void); extern void PyWinFreeze_ExeTerm(void); -extern int PyInitFrozenExtensions(void); #endif /* Main program */ @@ -75,9 +74,6 @@ Py_FrozenMain(int argc, char **argv) PyMem_RawFree(oldloc); oldloc = NULL; -#ifdef MS_WINDOWS - PyInitFrozenExtensions(); -#endif /* MS_WINDOWS */ if (argc >= 1) Py_SetProgramName(argv_copy[0]); From adc1095d6637c1909376b86ee38dd9cf90e8d068 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 23:55:55 -0800 Subject: [PATCH 13/42] Enable _Py_isabs on windows targets and implement via PathIsRelativeW win32 API. --- Include/cpython/fileutils.h | 2 -- Python/fileutils.c | 7 +++++-- Python/initconfig.c | 2 -- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Include/cpython/fileutils.h b/Include/cpython/fileutils.h index ccf37e9468d615..ff840263fe9ffd 100644 --- a/Include/cpython/fileutils.h +++ b/Include/cpython/fileutils.h @@ -135,9 +135,7 @@ PyAPI_FUNC(wchar_t*) _Py_wrealpath( size_t resolved_path_len); #endif -#ifndef MS_WINDOWS PyAPI_FUNC(int) _Py_isabs(const wchar_t *path); -#endif PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p); diff --git a/Python/fileutils.c b/Python/fileutils.c index 3b53baa00eeb10..863f88b51167c5 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -6,6 +6,7 @@ #ifdef MS_WINDOWS # include +# include # include extern int winerror_to_errno(int); #endif @@ -1976,13 +1977,15 @@ _Py_wrealpath(const wchar_t *path, #endif -#ifndef MS_WINDOWS int _Py_isabs(const wchar_t *path) { +#ifdef MS_WINDOWS + return !PathIsRelativeW(path); +#else return (path[0] == SEP); -} #endif +} /* Get an absolute path. diff --git a/Python/initconfig.c b/Python/initconfig.c index 0341e7baa210c9..e2c92b6ef9a87b 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -2668,12 +2668,10 @@ config_run_filename_abspath(PyConfig *config) return _PyStatus_OK(); } -#ifndef MS_WINDOWS if (_Py_isabs(config->run_filename)) { /* path is already absolute */ return _PyStatus_OK(); } -#endif wchar_t *abs_filename; if (_Py_abspath(config->run_filename, &abs_filename) < 0) { From bf9d15cbf280b462336388a9495f82291003b3cc Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:11:49 -0800 Subject: [PATCH 14/42] Guard out ./ prefix to bare filename on windows targets in Python/dynload_shlib.c. --- Python/dynload_shlib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index 90509947b20a33..b191a73d6cc102 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -69,11 +69,13 @@ _PyImport_FindSharedFuncptr(const char *prefix, char pathbuf[260]; int dlopenflags=0; +#ifndef MS_WINDOWS if (strchr(pathname, '/') == NULL) { /* Prefix bare filename with "./" */ PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); pathname = pathbuf; } +#endif PyOS_snprintf(funcname, sizeof(funcname), LEAD_UNDERSCORE "%.20s_%.200s", prefix, shortname); From 73b8af04f088a6b8a39db8abe2d8f8e310f6979f Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:43:40 -0800 Subject: [PATCH 15/42] Guard out usages of resolve_symlinks in Modules/getpath.c. --- Modules/getpath.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/getpath.c b/Modules/getpath.c index ef6dd59a084d8d..8c2e217eda0c60 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -1191,10 +1191,12 @@ calculate_argv0_path(PyCalculatePath *calculate, } #endif +#ifndef MS_WINDOWS status = resolve_symlinks(&calculate->argv0_path); if (_PyStatus_EXCEPTION(status)) { return status; } +#endif reduce(calculate->argv0_path); From 21961e99805e6e6e86999f23219aecebaa7b6cce Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:36:02 -0800 Subject: [PATCH 16/42] Guard windows specific paths in posixmodule.c with _WIN32 instead of _MSC_VER. --- Modules/posixmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 26c8e7bc2804d1..3c6acf00bedb0d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -303,7 +303,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_SYSTEM 1 # include #else -# ifdef _MSC_VER +# ifdef _WIN32 /* Microsoft compiler */ # define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 @@ -336,7 +336,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_SYSTEM 1 # define HAVE_WAIT 1 # define HAVE_TTYNAME 1 -# endif /* _MSC_VER */ +# endif /* _WIN32 */ #endif /* ! __WATCOMC__ || __QNX__ */ _Py_IDENTIFIER(__fspath__); @@ -416,7 +416,7 @@ extern char *ctermid_r(char *); # endif #endif -#ifdef _MSC_VER +#ifdef _WIN32 # ifdef HAVE_DIRECT_H # include # endif @@ -438,7 +438,7 @@ extern char *ctermid_r(char *); # include // ShellExecute() # include // UNLEN # define HAVE_SYMLINK -#endif /* _MSC_VER */ +#endif /* _WIN32 */ #ifndef MAXPATHLEN # if defined(PATH_MAX) && PATH_MAX > 1024 From 40f81b1db02e7c5f49f6f8b623452a1f5ae3d42c Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 23:47:29 -0800 Subject: [PATCH 17/42] Use wcsncasecmp in place of _wcsnicmp on windows targets. --- Modules/getpath.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/getpath.c b/Modules/getpath.c index 8c2e217eda0c60..0989c93428a245 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -418,7 +418,11 @@ add_exe_suffix(wchar_t **progpath_p) /* Check for already have an executable suffix */ size_t n = wcslen(progpath); size_t s = wcslen(EXE_SUFFIX); +#ifndef MS_WINDOWS if (wcsncasecmp(EXE_SUFFIX, progpath + n - s, s) == 0) { +#else + if (_wcsnicmp(EXE_SUFFIX, progpath + n - s, s) == 0) { +#endif return _PyStatus_OK(); } From 3a941d274bd17d90396c76daf25fffb0ea205c1a Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:57:59 -0800 Subject: [PATCH 18/42] Convert MS_WIN32 -> MS_WINDOWS to port ctypes module to windows targets. --- Modules/_ctypes/_ctypes.c | 42 +++++++++++++++++----------------- Modules/_ctypes/callproc.c | 36 ++++++++++++++--------------- Modules/_ctypes/ctypes.h | 11 +++++---- Modules/_ctypes/ctypes_dlfcn.h | 2 +- 4 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 84378c40357b07..40fd6555d4df69 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -105,7 +105,7 @@ bytes(cdata) #include "structmember.h" // PyMemberDef #include -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #include #ifndef IS_INTRESOURCE @@ -129,7 +129,7 @@ static PyTypeObject Simple_Type; strong reference to _ctypes._unpickle() function */ static PyObject *_unpickle; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyObject *ComError; // Borrowed reference to: &PyComError_Type #endif @@ -754,7 +754,7 @@ CDataType_in_dll(PyObject *type, PyObject *args) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS address = (void *)GetProcAddress(handle, name); Py_END_ALLOW_THREADS @@ -3365,7 +3365,7 @@ static PyGetSetDef PyCFuncPtr_getsets[] = { { NULL, NULL } }; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PPROC FindAddress(void *handle, const char *name, PyObject *type) { PPROC address; @@ -3515,7 +3515,7 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags) static int _get_name(PyObject *obj, const char **pname) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (PyLong_Check(obj)) { /* We have to use MAKEINTRESOURCEA for Windows CE. Works on Windows as well, of course. @@ -3567,7 +3567,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (PySys_Audit("ctypes.dlsym", ((uintptr_t)name & ~0xFFFF) ? "Os" : "On", dll, name) < 0) { @@ -3602,7 +3602,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS address = FindAddress(handle, name, (PyObject *)type); if (!address) { if (!IS_INTRESOURCE(name)) @@ -3658,7 +3658,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * PyCFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -3714,7 +3714,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (1 <= PyTuple_GET_SIZE(args) && PyTuple_Check(PyTuple_GET_ITEM(args, 0))) return PyCFuncPtr_FromDll(type, args, kwds); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (2 <= PyTuple_GET_SIZE(args) && PyLong_Check(PyTuple_GET_ITEM(args, 0))) return PyCFuncPtr_FromVtblIndex(type, args, kwds); #endif @@ -3894,7 +3894,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, /* Trivial cases, where we either return inargs itself, or a slice of it. */ if (argtypes == NULL || paramflags == NULL || PyTuple_GET_SIZE(argtypes) == 0) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) return PyTuple_GetSlice(inargs, 1, PyTuple_GET_SIZE(inargs)); #endif @@ -3907,7 +3907,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, if (callargs == NULL) return NULL; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS /* For a COM method, skip the first arg */ if (self->index) { inargs_index = 1; @@ -4112,7 +4112,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) PyObject *result; PyObject *callargs; PyObject *errcheck; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *piunk = NULL; #endif void *pProc = NULL; @@ -4131,7 +4131,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) pProc = *(void **)self->b_ptr; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) { /* It's a COM method */ CDataObject *this; @@ -4200,7 +4200,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) result = _ctypes_callproc(pProc, callargs, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS piunk, self->iid, #endif @@ -4271,7 +4271,7 @@ PyCFuncPtr_dealloc(PyCFuncPtrObject *self) static PyObject * PyCFuncPtr_repr(PyCFuncPtrObject *self) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) return PyUnicode_FromFormat("", self->index - 0x1000, @@ -4287,7 +4287,7 @@ static int PyCFuncPtr_bool(PyCFuncPtrObject *self) { return ((*(void **)self->b_ptr != NULL) -#ifdef MS_WIN32 +#ifdef MS_WINDOWS || (self->index != 0) #endif ); @@ -5472,7 +5472,7 @@ PyTypeObject PyCPointer_Type = { PyDoc_STRVAR(_ctypes__doc__, "Create and manipulate C compatible data types in Python."); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyDoc_STRVAR(comerror_doc, "Raised when a COM method call failed."); @@ -5552,7 +5552,7 @@ static PyTypeObject PyComError_Type = { 0, /* tp_alloc */ 0, /* tp_new */ }; -#endif // MS_WIN32 +#endif // MS_WINDOWS static PyObject * string_at(const char *ptr, int size) @@ -5744,7 +5744,7 @@ _ctypes_add_types(PyObject *mod) TYPE_READY(&DictRemover_Type); TYPE_READY(&StructParam_Type); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS TYPE_READY_BASE(&PyComError_Type, (PyTypeObject*)PyExc_Exception); #endif @@ -5773,7 +5773,7 @@ _ctypes_add_objects(PyObject *mod) MOD_ADD("_pointer_type_cache", Py_NewRef(_ctypes_ptrtype_cache)); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS MOD_ADD("COMError", Py_NewRef(ComError)); MOD_ADD("FUNCFLAG_HRESULT", PyLong_FromLong(FUNCFLAG_HRESULT)); MOD_ADD("FUNCFLAG_STDCALL", PyLong_FromLong(FUNCFLAG_STDCALL)); @@ -5829,7 +5829,7 @@ _ctypes_mod_exec(PyObject *mod) if (_ctypes_add_types(mod) < 0) { return -1; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS ComError = (PyObject*)&PyComError_Type; #endif diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 48694760dbedf1..a95d48131f4527 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -59,7 +59,7 @@ #include -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #include #else @@ -70,7 +70,7 @@ #include #endif -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #endif @@ -234,7 +234,7 @@ set_errno(PyObject *self, PyObject *args) return set_error_internal(self, args, 0); } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * get_last_error(PyObject *self, PyObject *args) @@ -737,7 +737,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) } } -#if defined(MS_WIN32) && !defined(_WIN32_WCE) +#if defined(MS_WINDOWS) && !defined(_WIN32_WCE) /* Per: https://msdn.microsoft.com/en-us/library/7572ztz4.aspx To be returned by value in RAX, user-defined types must have a length @@ -768,7 +768,7 @@ ffi_type *_ctypes_get_ffi_type(PyObject *obj) dict = PyType_stgdict(obj); if (dict == NULL) return &ffi_type_sint; -#if defined(MS_WIN32) && !defined(_WIN32_WCE) +#if defined(MS_WINDOWS) && !defined(_WIN32_WCE) /* This little trick works correctly with MSVC. It returns small structures in registers */ @@ -809,7 +809,7 @@ static int _call_function_pointer(int flags, int *space; ffi_cif cif; int cc; -#if defined(MS_WIN32) && !defined(DONT_USE_SEH) +#if defined(MS_WINDOWS) && !defined(DONT_USE_SEH) DWORD dwExceptionCode = 0; EXCEPTION_RECORD record; #endif @@ -903,7 +903,7 @@ static int _call_function_pointer(int flags, space[0] = errno; errno = temp; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (flags & FUNCFLAG_USE_LASTERROR) { int temp = space[1]; space[1] = GetLastError(); @@ -914,7 +914,7 @@ static int _call_function_pointer(int flags, #endif #endif ffi_call(&cif, (void *)pProc, resmem, avalues); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #ifndef DONT_USE_SEH } __except (HandleException(GetExceptionInformation(), @@ -936,7 +936,7 @@ static int _call_function_pointer(int flags, if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS Py_XDECREF(error_object); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #ifndef DONT_USE_SEH if (dwExceptionCode) { SetException(dwExceptionCode, &record); @@ -1040,7 +1040,7 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...) } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) @@ -1135,7 +1135,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) */ PyObject *_ctypes_callproc(PPROC pProc, PyObject *argtuple, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *pIunk, GUID *iid, #endif @@ -1155,7 +1155,7 @@ PyObject *_ctypes_callproc(PPROC pProc, PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS /* an optional COM object this pointer */ if (pIunk) ++argcount; @@ -1175,7 +1175,7 @@ PyObject *_ctypes_callproc(PPROC pProc, } memset(args, 0, sizeof(struct argument) * argcount); argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (pIunk) { args[0].ffi_type = &ffi_type_pointer; args[0].value.p = pIunk; @@ -1281,7 +1281,7 @@ PyObject *_ctypes_callproc(PPROC pProc, } #endif -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (iid && pIunk) { if (*(int *)resbuf & 0x80000000) retval = GetComError(*(HRESULT *)resbuf, iid, pIunk); @@ -1310,7 +1310,7 @@ _parse_voidp(PyObject *obj, void **address) return 1; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyDoc_STRVAR(format_error_doc, "FormatError([integer]) -> string\n\ @@ -1600,7 +1600,7 @@ call_function(PyObject *self, PyObject *args) result = _ctypes_callproc((PPROC)func, arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS NULL, NULL, #endif @@ -1635,7 +1635,7 @@ call_cdeclfunction(PyObject *self, PyObject *args) result = _ctypes_callproc((PPROC)func, arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS NULL, NULL, #endif @@ -2001,7 +2001,7 @@ PyMethodDef _ctypes_module_methods[] = { {"_unpickle", unpickle, METH_VARARGS }, {"buffer_info", buffer_info, METH_O, "Return buffer interface information"}, {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"}, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS {"get_last_error", get_last_error, METH_NOARGS}, {"set_last_error", set_last_error, METH_VARARGS}, {"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc}, diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 9600ddc7413b2e..b2039eaded4810 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -2,7 +2,10 @@ # include #endif -#ifndef MS_WIN32 +#ifdef MS_WINDOWS +#include +#include +#else #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -94,7 +97,7 @@ typedef struct { PyObject *restype; PyObject *checker; PyObject *errcheck; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS int index; GUID *iid; #endif @@ -269,7 +272,7 @@ typedef int(* PPROC)(void); PyObject *_ctypes_callproc(PPROC pProc, PyObject *arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *pIUnk, GUID *iid, #endif @@ -358,7 +361,7 @@ extern int _ctypes_simple_instance(PyObject *obj); extern PyObject *_ctypes_ptrtype_cache; PyObject *_ctypes_get_errobj(int **pspace); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS extern PyObject *ComError; #endif diff --git a/Modules/_ctypes/ctypes_dlfcn.h b/Modules/_ctypes/ctypes_dlfcn.h index 54cdde9a4fdb02..ec1cade201ca00 100644 --- a/Modules/_ctypes/ctypes_dlfcn.h +++ b/Modules/_ctypes/ctypes_dlfcn.h @@ -5,7 +5,7 @@ extern "C" { #endif /* __cplusplus */ -#ifndef MS_WIN32 +#ifndef MS_WINDOWS #include From b9bc70865afc00455dc130c0ece4d65d03153403 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:43:01 -0800 Subject: [PATCH 19/42] Stub out pwdmodule on windows targets. --- Modules/pwdmodule.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index 14d3f9dcb1c60f..23cbdec2480490 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -4,7 +4,9 @@ #include "Python.h" #include "posixmodule.h" +#ifndef MS_WINDOWS #include +#endif #include "clinic/pwdmodule.c.h" /*[clinic input] @@ -84,6 +86,7 @@ mkpwent(PyObject *module, struct passwd *p) if (v == NULL) return NULL; +#ifndef MS_WINDOWS #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val)) #define SETS(i,val) sets(v, i, val) @@ -105,6 +108,7 @@ mkpwent(PyObject *module, struct passwd *p) #undef SETS #undef SETI +#endif if (PyErr_Occurred()) { Py_XDECREF(v); @@ -129,6 +133,9 @@ static PyObject * pwd_getpwuid(PyObject *module, PyObject *uidobj) /*[clinic end generated code: output=c4ee1d4d429b86c4 input=ae64d507a1c6d3e8]*/ { +#ifdef MS_WINDOWS + return NULL; +#else PyObject *retval = NULL; uid_t uid; int nomem = 0; @@ -197,6 +204,7 @@ pwd_getpwuid(PyObject *module, PyObject *uidobj) PyMem_RawFree(buf); #endif return retval; +#endif } /*[clinic input] @@ -260,7 +268,9 @@ pwd_getpwnam_impl(PyObject *module, PyObject *name) Py_END_ALLOW_THREADS #else +#ifndef MS_WINDOWS p = getpwnam(name_chars); +#endif #endif if (p == NULL) { if (nomem == 1) { From c4f3fdf5d9eeefa49cc39a212c5f1301a64a0b88 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:01:42 -0800 Subject: [PATCH 20/42] Import windows.h in curses module when targeting windows. --- Modules/_cursesmodule.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index a1de43599c99de..6626dc46630f53 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -126,6 +126,10 @@ static const char PyCursesVersion[] = "2.2"; #include #endif +#if defined(MS_WINDOWS) +#include +#endif + #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ typedef chtype attr_t; /* No attr_t type is available */ From 048d546f8ab27d6f8525df33c58c68b877de1347 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:40:05 -0800 Subject: [PATCH 21/42] Properly stringify PY3_DLLNAME argument to GetModuleHandleW in _PyPathConfig_AsDict. --- PC/getpathp.c | 10 ++++++---- Python/pathconfig.c | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/PC/getpathp.c b/PC/getpathp.c index 7c0eeab5dbab4a..307da4d0735616 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -1,4 +1,4 @@ - +#ifdef MS_WINDOWS /* Return the initial module search path. */ /* Used by DOS, Windows 3.1, Windows 95/98, Windows NT. */ @@ -1111,11 +1111,12 @@ _Py_CheckPython3(void) } python3_checked = 1; +#define STRINGIFY(x) #x /* If there is a python3.dll next to the python3y.dll, use that DLL */ if (!get_dllpath(py3path)) { reduce(py3path); - join(py3path, PY3_DLLNAME); + join(py3path, STRINGIFY(PY3_DLLNAME)); hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); if (hPython3 != NULL) { return 1; @@ -1124,7 +1125,7 @@ _Py_CheckPython3(void) /* If we can locate python3.dll in our application dir, use that DLL */ - hPython3 = LoadLibraryExW(PY3_DLLNAME, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + hPython3 = LoadLibraryExW(STRINGIFY(PY3_DLLNAME), NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); if (hPython3 != NULL) { return 1; } @@ -1133,8 +1134,9 @@ _Py_CheckPython3(void) that has not been a normal install layout for a while */ wcscpy(py3path, Py_GetPrefix()); if (py3path[0]) { - join(py3path, L"DLLs\\" PY3_DLLNAME); + join(py3path, L"DLLs\\" STRINGIFY(PY3_DLLNAME)); hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); } return hPython3 != NULL; } +#endif diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 1017a571f2b829..c6a3d7e69bc5fd 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -227,7 +227,9 @@ _PyPathConfig_AsDict(void) { wchar_t py3path[MAX_PATH]; - HMODULE hPython3 = GetModuleHandleW(PY3_DLLNAME); +#define STRINGIFY(x) #x + HMODULE hPython3 = GetModuleHandleW(STRINGIFY(PY3_DLLNAME)); +#undef STRINGIFY PyObject *obj; if (hPython3 && GetModuleFileNameW(hPython3, py3path, Py_ARRAY_LENGTH(py3path))) From 8abab105f7ba8b48b7353338df73f6c32d7510ba Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:39:25 -0800 Subject: [PATCH 22/42] Fix windows build for _testembed internal program. --- Programs/_testembed.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Programs/_testembed.c b/Programs/_testembed.c index b7d4675a955a50..0865f81f5ca618 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1876,10 +1876,20 @@ static struct TestCase TestCases[] = { {NULL, NULL} }; +#ifdef MS_WINDOWS +int wmain(int argc, wchar_t *argv[]) +#else int main(int argc, char *argv[]) +#endif { if (argc > 1) { for (struct TestCase *tc = TestCases; tc && tc->name; tc++) { +#ifdef MS_WINDOWS + char arg[1024]; + mbstowcs(argv[1], arg, sizeof(arg)); +#else + char *arg = argv[1]; +#endif if (strcmp(argv[1], tc->name) == 0) return (*tc->func)(); } From aabe5ac46fd0e599a0e4dc899a83e796313cfb03 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:52:59 -0800 Subject: [PATCH 23/42] Cast arguments to putenv/unsetenv on windows targets to strings in Lib/os.py. --- Lib/os.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index d26cfc99939f39..5d5373a430cc28 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -682,12 +682,18 @@ def __getitem__(self, key): def __setitem__(self, key, value): key = self.encodekey(key) value = self.encodevalue(value) - putenv(key, value) + if sys.platform.startswith('win'): + putenv(str(key), str(value)) + else: + putenv(key, value) self._data[key] = value def __delitem__(self, key): encodedkey = self.encodekey(key) - unsetenv(encodedkey) + if sys.platform.startswith('win'): + unsetenv(str(encodedkey)) + else: + unsetenv(encodedkey) try: del self._data[encodedkey] except KeyError: From 168fdd2632c558c67fbc0f52fa7af6b8b1c14df3 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:53:18 -0800 Subject: [PATCH 24/42] Avoid using getpwuid on windows targets in Lib/posixpath.py. --- Lib/posixpath.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 195374613a779f..d68d2c8bca5be0 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -243,11 +243,13 @@ def expanduser(path): if 'HOME' not in os.environ: import pwd try: - userhome = pwd.getpwuid(os.getuid()).pw_dir + if not sys.platform.startswith('win'): + userhome = pwd.getpwuid(os.getuid()).pw_dir except KeyError: # bpo-10496: if the current user identifier doesn't exist in the # password database, return the path unchanged return path + return path else: userhome = os.environ['HOME'] else: From 50b3a563a4252ad49a943ff0bfa96045e4606600 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:08:57 -0800 Subject: [PATCH 25/42] Define MS_COREDLL in Python/sysmodule.c to export version helpers for windows. --- Python/sysmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ac49f7867a5cb3..5eeea60223b9e7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -36,6 +36,7 @@ Data members: #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN #include +#define MS_COREDLL 1 #endif /* MS_WINDOWS */ #ifdef MS_COREDLL From 15e9d49fcd17b3faaf79cbaca14529d5c442ab13 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:11:00 -0800 Subject: [PATCH 26/42] Enable PC/dl_nt.c on windows targets. --- Makefile.pre.in | 3 ++- PC/dl_nt.c | 22 +++++++++++++++++++--- PC/frozen_dllmain.c | 4 +++- configure.ac | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 74b467a28376c7..9d7223bd432c52 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -458,7 +458,8 @@ LIBRARY_OBJS_OMIT_FROZEN= \ LIBRARY_OBJS= \ $(LIBRARY_OBJS_OMIT_FROZEN) \ Python/frozen.o \ - PC/frozen_dllmain.o + PC/frozen_dllmain.o \ + PC/dl_nt.o ########################################################################## # DTrace diff --git a/PC/dl_nt.c b/PC/dl_nt.c index 7f17ee168727f0..7a1d56cec4b3a4 100644 --- a/PC/dl_nt.c +++ b/PC/dl_nt.c @@ -8,18 +8,29 @@ forgotten) from the programmer. */ +#ifdef MS_WINDOWS + #include "Python.h" #include "windows.h" #ifdef Py_ENABLE_SHARED +#if defined(__aarch64_) +#define PY_EXT "-arm64" +#elif defined(__x86_64__) +#define PY_EXT "" +#endif + +#define _STRINGIFY(x) #x +#define STRINGIFY(x) _STRINGIFY(x) +#define MS_DLL_ID STRINGIFY(PYTHON_VERSION) STRINGIFY(PY_EXT) + // Python Globals HMODULE PyWin_DLLhModule = NULL; const char *PyWin_DLLVersionString = MS_DLL_ID; -BOOL WINAPI DllMain (HANDLE hInst, - ULONG ul_reason_for_call, - LPVOID lpReserved) +BOOL RegisterInstance(HANDLE hInst, + ULONG ul_reason_for_call) { switch (ul_reason_for_call) { @@ -33,4 +44,9 @@ BOOL WINAPI DllMain (HANDLE hInst, return TRUE; } +#undef STRINGIFY +#undef _STRINGIFY + #endif /* Py_ENABLE_SHARED */ + +#endif diff --git a/PC/frozen_dllmain.c b/PC/frozen_dllmain.c index 17d013492cc029..b6f84116d6264b 100644 --- a/PC/frozen_dllmain.c +++ b/PC/frozen_dllmain.c @@ -56,6 +56,8 @@ static char *possibleModules[] = { }; BOOL CallModuleDllMain(char *modName, DWORD dwReason); +BOOL RegisterInstance(HANDLE hInst, + ULONG ul_reason_for_call); /* @@ -89,7 +91,7 @@ void PyWinFreeze_ExeTerm(void) BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { - BOOL ret = TRUE; + BOOL ret = RegisterInstance(hInstance, dwReason); switch (dwReason) { case DLL_PROCESS_ATTACH: { diff --git a/configure.ac b/configure.ac index caa3ec4c5344d3..64c78e3d007929 100644 --- a/configure.ac +++ b/configure.ac @@ -403,7 +403,7 @@ then ;; *-*-mingw32*) ac_sys_system=MinGW32 - CFLAGS_NODIST="${CFLAGS_NODIST} -DMS_WINDOWS -DMS_WIN64 -DPY3_DLLNAME=python${VERSION}" + CFLAGS_NODIST="${CFLAGS_NODIST} -DMS_WINDOWS -DMS_WIN64 -DPY3_DLLNAME=python${VERSION} -DPYTHON_VERSION=${VERSION}" LDFLAGS_NODIST="${LDFLAGS} -municode" ;; *-*-darwin*) From 254449cbb2aaff6487c740d9291a3cc6872a0846 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:35:12 -0800 Subject: [PATCH 27/42] Disable builtin posix module by default so nt/posix can be chosen via local Modules/Setup.local during build. --- Modules/Setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Setup b/Modules/Setup index bc104c6ec3c2b0..f3ab5b407105ea 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -101,7 +101,7 @@ PYTHONPATH=$(COREPYTHONPATH) # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. -posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls +# posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls errno errnomodule.c # posix (UNIX) errno values pwd pwdmodule.c # this is needed to find out the user's home dir # if $HOME is not set From 6e4777dbaecf29be09a896a66979dd36d255ead7 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 13:19:26 -0800 Subject: [PATCH 28/42] Add dll import lib detection to distutils. --- Lib/distutils/ccompiler.py | 4 ++-- Lib/distutils/unixccompiler.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 4c47f2ed245d4f..1ddf382280afef 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -876,9 +876,9 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''): def library_filename(self, libname, lib_type='static', # or 'shared' strip_dir=0, output_dir=''): assert output_dir is not None - if lib_type not in ("static", "shared", "dylib", "xcode_stub"): + if lib_type not in ("static", "shared", "dll", "dylib", "xcode_stub"): raise ValueError( - "'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"") + "'lib_type' must be \"static\", \"shared\", \"dll\", \"dylib\", or \"xcode_stub\"") fmt = getattr(self, lib_type + "_lib_format") ext = getattr(self, lib_type + "_lib_extension") diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index d00c48981eb6d6..ebea9129e86207 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -75,9 +75,10 @@ class UnixCCompiler(CCompiler): obj_extension = ".o" static_lib_extension = ".a" shared_lib_extension = ".so" + dll_lib_extension = ".dll.a" dylib_lib_extension = ".dylib" xcode_stub_lib_extension = ".tbd" - static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" + static_lib_format = shared_lib_format = dll_lib_format = dylib_lib_format = "lib%s%s" xcode_stub_lib_format = dylib_lib_format if sys.platform == "cygwin": exe_extension = ".exe" @@ -265,6 +266,7 @@ def library_option(self, lib): def find_library_file(self, dirs, lib, debug=0): shared_f = self.library_filename(lib, lib_type='shared') + dll_f = self.library_filename(lib, lib_type='dll') dylib_f = self.library_filename(lib, lib_type='dylib') xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub') static_f = self.library_filename(lib, lib_type='static') @@ -299,6 +301,7 @@ def find_library_file(self, dirs, lib, debug=0): for dir in dirs: shared = os.path.join(dir, shared_f) + dll = os.path.join(dir, dll_f) dylib = os.path.join(dir, dylib_f) static = os.path.join(dir, static_f) xcode_stub = os.path.join(dir, xcode_stub_f) @@ -316,7 +319,9 @@ def find_library_file(self, dirs, lib, debug=0): # data to go on: GCC seems to prefer the shared library, so I'm # assuming that *all* Unix C compilers do. And of course I'm # ignoring even GCC's "-static" option. So sue me. - if os.path.exists(dylib): + if os.path.exists(dll): + return dll + elif os.path.exists(dylib): return dylib elif os.path.exists(xcode_stub): return xcode_stub From 7b38a339cc9d557f1006b47e28099183516d99d7 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 16:25:26 -0800 Subject: [PATCH 29/42] Fix naming convention for mingw32 dlls in Python/dynload_win.c. --- Python/dynload_win.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 5702ab2cd71ba1..57b199522dc432 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -119,14 +119,14 @@ static char *GetPythonImport (HINSTANCE hModule) import_off); while (DWORD_AT(import_data)) { import_name = dllbase + DWORD_AT(import_data+12); - if (strlen(import_name) >= 6 && - !strncmp(import_name,"python",6)) { + if (strlen(import_name) >= 9 && + !strncmp(import_name,"libpython",9)) { char *pch; #ifndef _DEBUG /* In a release version, don't claim that python3.dll is a Python DLL. */ - if (strcmp(import_name, "python3.dll") == 0) { + if (strcmp(import_name, "libpython3.dll") == 0) { import_data += 20; continue; } @@ -136,11 +136,11 @@ static char *GetPythonImport (HINSTANCE hModule) by numbers to the end of the basename */ pch = import_name + 6; #ifdef _DEBUG - while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { + while (*pch && pch[0] != '_' && pch[1] != 'd') { #else - while (*pch && *pch != '.') { + while (*pch) { #endif - if (*pch >= '0' && *pch <= '9') { + if ((*pch >= '0' && *pch <= '9') || (*pch == '.')) { pch++; } else { pch = NULL; @@ -260,9 +260,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, PyOS_snprintf(buffer, sizeof(buffer), #ifdef _DEBUG - "python%d%d_d.dll", + "libpython%d.%d_d.dll", #else - "python%d%d.dll", + "libpython%d.%d.dll", #endif PY_MAJOR_VERSION,PY_MINOR_VERSION); import_python = GetPythonImport(hDLL); From d8d0bf1d238292da9ab69b755f098a32f431f398 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 16:27:19 -0800 Subject: [PATCH 30/42] Fix importing naming convention for python dll modules in Python/dynload_win.c. --- Makefile.pre.in | 5 +++++ Python/dynload_win.c | 1 + 2 files changed, 6 insertions(+) diff --git a/Makefile.pre.in b/Makefile.pre.in index 9d7223bd432c52..35ff7a08bea87f 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -826,6 +826,11 @@ 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) \ + -DSOABI='"$(SOABI)"' \ + -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)"' \ diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 57b199522dc432..b935c17085dbe5 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -27,6 +27,7 @@ #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" const char *_PyImport_DynLoadFiletab[] = { + "." SOABI ".dll", PYD_TAGGED_SUFFIX, PYD_UNTAGGED_SUFFIX, NULL From 1edbda08cdebc8bad1bd370d089655fd909abf55 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:16:23 -0800 Subject: [PATCH 31/42] Unify unix and windows target handling of module imports. --- Python/importdl.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Python/importdl.c b/Python/importdl.c index 6d2554741f9822..52c9828f0d144b 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -12,16 +12,9 @@ #include "importdl.h" -#ifdef MS_WINDOWS -extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, - const char *shortname, - PyObject *pathname, - FILE *fp); -#else extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, const char *shortname, const char *pathname, FILE *fp); -#endif static const char * const ascii_only_prefix = "PyInit"; static const char * const nonascii_prefix = "PyInitU"; @@ -92,9 +85,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { PyObject * _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) { -#ifndef MS_WINDOWS PyObject *pathbytes = NULL; -#endif PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL; const char *name_buf, *hook_prefix; const char *oldcontext; @@ -127,10 +118,6 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) goto error; } -#ifdef MS_WINDOWS - exportfunc = _PyImport_FindSharedFuncptrWindows(hook_prefix, name_buf, - path, fp); -#else pathbytes = PyUnicode_EncodeFSDefault(path); if (pathbytes == NULL) goto error; @@ -138,7 +125,6 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) PyBytes_AS_STRING(pathbytes), fp); Py_DECREF(pathbytes); -#endif if (exportfunc == NULL) { if (!PyErr_Occurred()) { From 36fbdb44351c104eeeec1f10f1481b142a15ce2d Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:17:24 -0800 Subject: [PATCH 32/42] Add dynload_shlib.c port for mingw32 windows target. --- Python/dynload_shlib.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index b191a73d6cc102..81888fff009ab5 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -20,6 +20,22 @@ #ifdef HAVE_DLFCN_H #include +#else +static const char *dlerror() +{ + return ""; +} + +static void *dlopen(const char *path, int flags) +{ + return LoadLibrary(path); +} + +static void *dlsym(void *handle, const char *name) +{ + return GetProcAddress(handle, name); +} + #endif #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__) @@ -39,7 +55,9 @@ const char *_PyImport_DynLoadFiletab[] = { ".dll", #elif defined(__APPLE__) "." SOABI ".dylib", -#else /* !__CYGWIN__ */ +#elif defined(__MINGW32__) + "." SOABI ".dll", +#else /* !__CYGWIN__ && !__APPLE__ && !__MINGW32__ */ "." SOABI ".so", #ifdef ALT_SOABI "." ALT_SOABI ".so", @@ -99,7 +117,9 @@ _PyImport_FindSharedFuncptr(const char *prefix, } } +#if HAVE_DLFCN_H dlopenflags = _PyInterpreterState_GET()->dlopenflags; +#endif handle = dlopen(pathname, dlopenflags); From 511d186039708dbd1f6d616f1bb382c2b4f20a86 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:45:14 -0800 Subject: [PATCH 33/42] Unify site-packages calculation on unix and windows targets by using unix environment specification. --- Lib/site.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index 939893eb5ee93b..907cba1fec3f38 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -288,10 +288,6 @@ def joinuser(*args): def _get_path(userbase): version = sys.version_info - if os.name == 'nt': - ver_nodot = sys.winver.replace('.', '') - return f'{userbase}\\Python{ver_nodot}\\site-packages' - if sys.platform == 'darwin' and sys._framework: return f'{userbase}/lib/python/site-packages' @@ -365,18 +361,11 @@ def getsitepackages(prefixes=None): if sys.platlibdir != "lib": libdirs.append("lib") - if os.sep == '/': - for libdir in libdirs: - path = os.path.join(prefix, libdir, - "python%d.%d" % sys.version_info[:2], - "site-packages") - sitepackages.append(path) - else: - sitepackages.append(prefix) - - for libdir in libdirs: - path = os.path.join(prefix, libdir, "site-packages") - sitepackages.append(path) + for libdir in libdirs: + path = os.path.join(prefix, libdir, + "python%d.%d" % sys.version_info[:2], + "site-packages") + sitepackages.append(path) return sitepackages def addsitepackages(known_paths, prefixes=None): From 228cd089fbf11e3a1da1769489f76ae3216adca9 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 01:21:12 -0800 Subject: [PATCH 34/42] Use MS_WINDOWS instead of _MSC_VER in Modules/_ssl.c. --- Modules/_ssl.c | 4 ++-- Modules/clinic/_ssl.c.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_ssl.c b/Modules/_ssl.c index af2520432a64e7..75fd233e206e7a 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -5307,7 +5307,7 @@ _ssl_nid2obj_impl(PyObject *module, int nid) return result; } -#ifdef _MSC_VER +#ifdef MS_WINDOWS static PyObject* certEncodingType(DWORD encodingType) @@ -5626,7 +5626,7 @@ _ssl_enum_crls_impl(PyObject *module, const char *store_name) } } -#endif /* _MSC_VER */ +#endif /* MS_WINDOWS */ /* List of functions exported by this module. */ static PyMethodDef PySSL_methods[] = { diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index b59b129af8a095..27cc4da5beaa07 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -1244,7 +1244,7 @@ _ssl_nid2obj(PyObject *module, PyObject *arg) return return_value; } -#if defined(_MSC_VER) +#if defined(MS_WINDOWS) PyDoc_STRVAR(_ssl_enum_certificates__doc__, "enum_certificates($module, /, store_name)\n" @@ -1296,9 +1296,9 @@ _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } -#endif /* defined(_MSC_VER) */ +#endif /* defined(MS_WINDOWS) */ -#if defined(_MSC_VER) +#if defined(MS_WINDOWS) PyDoc_STRVAR(_ssl_enum_crls__doc__, "enum_crls($module, /, store_name)\n" @@ -1349,7 +1349,7 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return return_value; } -#endif /* defined(_MSC_VER) */ +#endif /* defined(MS_WINDOWS) */ #ifndef _SSL_ENUM_CERTIFICATES_METHODDEF #define _SSL_ENUM_CERTIFICATES_METHODDEF From 5e8e90f2b20525d0995e66dd0cf66a79e1b6b407 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Tue, 14 Dec 2021 00:21:22 -0800 Subject: [PATCH 35/42] Add musl detection support to configure.ac. --- configure.ac | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 64c78e3d007929..d11c1cecfadd2f 100644 --- a/configure.ac +++ b/configure.ac @@ -395,6 +395,9 @@ then *-*-linux-android*) ac_sys_system=Linux-android ;; + *-*-linux-musl*) + ac_sys_system=Linux-musl + ;; *-*-linux*) ac_sys_system=Linux ;; @@ -735,6 +738,9 @@ fi AC_MSG_CHECKING([for the platform triplet based on compiler characteristics]) cat >> conftest.c <) +#include +#endif #undef bfin #undef cris #undef fr30 @@ -748,7 +754,7 @@ cat >> conftest.c <> conftest.c < Date: Fri, 21 Jan 2022 21:36:57 -0800 Subject: [PATCH 36/42] Remove resetting MULTIARCH to empty on darwin targets. --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index d11c1cecfadd2f..cff114f08fbd29 100644 --- a/configure.ac +++ b/configure.ac @@ -924,7 +924,6 @@ rm -f conftest.c conftest.out AC_MSG_CHECKING([for multiarch]) AS_CASE([$ac_sys_system], - [Darwin*], [MULTIARCH=""], [FreeBSD*], [MULTIARCH=""], [MULTIARCH=$($CC --print-multiarch 2>/dev/null)] ) From 7e880293f106a64cd0fa6d8ff60fb931f09dc111 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Tue, 8 Feb 2022 20:16:51 -0800 Subject: [PATCH 37/42] Fix BUILDPYTHON specification in Makefiles for Mac and Mac/PythonLauncher targets. --- Mac/Makefile.in | 4 ++-- Mac/PythonLauncher/Makefile.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Mac/Makefile.in b/Mac/Makefile.in index f9691288414538..4b48462ac809ab 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -13,7 +13,7 @@ exec_prefix=@exec_prefix@ LIBDEST=$(prefix)/lib/python$(VERSION) RUNSHARED=@RUNSHARED@ BUILDEXE=@BUILDEXEEXT@ -BUILDPYTHON=$(builddir)/python$(BUILDEXE) +BUILDPYTHON=python$(BUILDEXE) DESTDIR= LDFLAGS=@LDFLAGS@ FRAMEWORKUNIXTOOLSPREFIX=@FRAMEWORKUNIXTOOLSPREFIX@ @@ -226,7 +226,7 @@ install_Python: esac; \ done; \ done - $(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)" + $(INSTALL_PROGRAM) $(STRIPFLAG) $(builddir)/$(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)" sed -e "s!%bundleid%!$(PYTHONFRAMEWORKIDENTIFIER)!g" \ -e "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) \ -c 'import platform; print(platform.python_version())'`!g" \ diff --git a/Mac/PythonLauncher/Makefile.in b/Mac/PythonLauncher/Makefile.in index 4c05f26e8358bc..7a3e1ea61acaec 100644 --- a/Mac/PythonLauncher/Makefile.in +++ b/Mac/PythonLauncher/Makefile.in @@ -11,7 +11,7 @@ builddir= ../.. RUNSHARED= @RUNSHARED@ BUILDEXE= @BUILDEXEEXT@ -BUILDPYTHON= $(builddir)/python$(BUILDEXE) +BUILDPYTHON= python$(BUILDEXE) PYTHONFRAMEWORK=@PYTHONFRAMEWORK@ # Deployment target selected during configure, to be checked From c0c23072fa70f7b49713032c5c6b9734ec8d7baa Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 10 Feb 2022 22:45:12 -0800 Subject: [PATCH 38/42] Replace use of FRAMEWORKALTINSTALLFIRST/FRAMEWORKALTINSTALLLAST with FRAMEWORKINSTALLFIRST/FRAMEWORKINSTALLLAST for commoninstall in Makefile.pre.in. --- Makefile.pre.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 35ff7a08bea87f..8d55d4c2b96b08 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1292,10 +1292,10 @@ altinstall: commoninstall $$ensurepip --root=$(DESTDIR)/ ; \ fi -commoninstall: check-clean-src @FRAMEWORKALTINSTALLFIRST@ \ +commoninstall: check-clean-src @FRAMEWORKINSTALLFIRST@ \ altbininstall libinstall inclinstall libainstall \ sharedinstall oldsharedinstall altmaninstall \ - @FRAMEWORKALTINSTALLLAST@ + @FRAMEWORKINSTALLLAST@ # Install shared libraries enabled by Setup DESTDIRS= $(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED) From 4a0189233dd46fd66d8514c24fd099d13461266c Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sun, 13 Mar 2022 20:46:14 -0700 Subject: [PATCH 39/42] Expand check for windows from mingw32 to mingw* to allow mingw64 specifications in configure.ac. --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index cff114f08fbd29..c2e8959297942e 100644 --- a/configure.ac +++ b/configure.ac @@ -404,7 +404,7 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; - *-*-mingw32*) + *-*-mingw*) ac_sys_system=MinGW32 CFLAGS_NODIST="${CFLAGS_NODIST} -DMS_WINDOWS -DMS_WIN64 -DPY3_DLLNAME=python${VERSION} -DPYTHON_VERSION=${VERSION}" LDFLAGS_NODIST="${LDFLAGS} -municode" @@ -440,7 +440,7 @@ then aix*) MACHDEP="aix";; linux*) MACHDEP="linux";; cygwin*) MACHDEP="cygwin";; - mingw32*) MACHDEP="win32";; + mingw*) MACHDEP="win32";; darwin*) MACHDEP="darwin";; '') MACHDEP="unknown";; esac @@ -462,7 +462,7 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; - *-*-mingw32*) + *-*-mingw*) _host_cpu=$host_cpu ;; *-*-darwin*) From 028632479f925d722c5b6bf68fbea5f367111b84 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 24 Jun 2022 19:25:30 +0000 Subject: [PATCH 40/42] Add i486-i786 32-bit x86 variant detection to configure.ac for linux targets. --- configure.ac | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configure.ac b/configure.ac index c2e8959297942e..850d94faa84f7b 100644 --- a/configure.ac +++ b/configure.ac @@ -759,6 +759,14 @@ cat >> conftest.c < Date: Fri, 24 Jun 2022 19:26:29 +0000 Subject: [PATCH 41/42] Add i486-i786 32-bit x86 variant detection to configure.ac for windows targets. --- configure.ac | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configure.ac b/configure.ac index 850d94faa84f7b..81080251ebddfa 100644 --- a/configure.ac +++ b/configure.ac @@ -909,6 +909,14 @@ cat >> conftest.c < Date: Fri, 1 Jul 2022 06:02:46 +0000 Subject: [PATCH 42/42] build(deps): bump actions/cache from 3.0.2 to 3.0.4 Bumps [actions/cache](https://github.com/actions/cache) from 3.0.2 to 3.0.4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3.0.2...v3.0.4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61cbef982a9ef1..ce9a89bd2eb5b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -196,7 +196,7 @@ jobs: echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}/lib" >> $GITHUB_ENV - name: 'Restore OpenSSL build' id: cache-openssl - uses: actions/cache@v3.0.2 + uses: actions/cache@v3.0.4 with: path: ./multissl/openssl/${{ env.OPENSSL_VER }} key: ${{ runner.os }}-multissl-openssl-${{ env.OPENSSL_VER }} @@ -244,7 +244,7 @@ jobs: echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/multissl/openssl/${OPENSSL_VER}/lib" >> $GITHUB_ENV - name: 'Restore OpenSSL build' id: cache-openssl - uses: actions/cache@v3.0.2 + uses: actions/cache@v3.0.4 with: path: ./multissl/openssl/${{ env.OPENSSL_VER }} key: ${{ runner.os }}-multissl-openssl-${{ env.OPENSSL_VER }}