From b4fd331ab80d742bfc648e616330ddae776021d6 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 17 Mar 2021 14:03:16 -0700 Subject: [PATCH 01/45] Remove /usr/local/lib and /usr/local/include default compiler paths. --- setup.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 85a2b26357db46..dd4d627a2c9102 100644 --- a/setup.py +++ b/setup.py @@ -680,10 +680,10 @@ def add_multiarch_paths(self): os.unlink(tmpfile) if multiarch_path_component != '': - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) + # add_dir_to_list(self.compiler.library_dirs, + # '/usr/lib/' + multiarch_path_component) + # add_dir_to_list(self.compiler.include_dirs, + # '/usr/include/' + multiarch_path_component) return if not find_executable('dpkg-architecture'): @@ -701,10 +701,10 @@ def add_multiarch_paths(self): if ret == 0: with open(tmpfile) as fp: multiarch_path_component = fp.readline().strip() - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) + # add_dir_to_list(self.compiler.library_dirs, + # '/usr/lib/' + multiarch_path_component) + # add_dir_to_list(self.compiler.include_dirs, + # '/usr/include/' + multiarch_path_component) finally: os.unlink(tmpfile) @@ -825,9 +825,9 @@ def configure_compiler(self): # Ensure that /usr/local is always used, but the local build # directories (i.e. '.' and 'Include') must be first. See issue # 10520. - if not CROSS_COMPILING: - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') + # if not CROSS_COMPILING: + # add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') + # add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') # only change this for cross builds for 3.3, issues on Mageia if CROSS_COMPILING: self.add_cross_compiling_paths() @@ -1163,8 +1163,8 @@ def detect_readline_curses(self): panel_library = 'panel' if curses_library == 'ncursesw': curses_defines.append(('HAVE_NCURSESW', '1')) - if not CROSS_COMPILING: - curses_includes.append('/usr/include/ncursesw') + # if not CROSS_COMPILING: + # curses_includes.append('/usr/include/ncursesw') # Bug 1464056: If _curses.so links with ncursesw, # _curses_panel.so must link with panelw. panel_library = 'panelw' From ce16bb538373d5b57c22953cfe71385f2c0d555e Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 3 Jul 2021 13:32:24 -0700 Subject: [PATCH 02/45] Move ac_sys_release check before os checks. --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index bad619963add87..17beb9c91f405d 100755 --- a/configure +++ b/configure @@ -3334,6 +3334,7 @@ then # ac_sys_system and ac_sys_release are used for setting # a lot of different things including 'define_xopen_source' # in the case statement below. + ac_sys_release= case "$host" in *-*-linux-android*) ac_sys_system=Linux-android @@ -3352,7 +3353,6 @@ then MACHDEP="unknown" as_fn_error $? "cross build not supported for $host" "$LINENO" 5 esac - ac_sys_release= else ac_sys_system=`uname -s` if test "$ac_sys_system" = "AIX" \ diff --git a/configure.ac b/configure.ac index cc69015b102bb7..5d5538974047bb 100644 --- a/configure.ac +++ b/configure.ac @@ -390,6 +390,7 @@ then # ac_sys_system and ac_sys_release are used for setting # a lot of different things including 'define_xopen_source' # in the case statement below. + ac_sys_release= case "$host" in *-*-linux-android*) ac_sys_system=Linux-android @@ -408,7 +409,6 @@ then MACHDEP="unknown" AC_MSG_ERROR([cross build not supported for $host]) esac - ac_sys_release= else ac_sys_system=`uname -s` if test "$ac_sys_system" = "AIX" \ From 3ccbd9cbf6a8c23afdc84d75c269de045e1fcbb1 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 3 Jul 2021 13:37:44 -0700 Subject: [PATCH 03/45] Add detection support for macos12/darwin21. --- Python/dynload_shlib.c | 2 ++ configure | 28 ++++++++++++++++++++++++++-- configure.ac | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 60 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 17beb9c91f405d..26387696cacca1 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 <) +#include +#endif #undef bfin #undef cris #undef fr30 @@ -854,8 +864,14 @@ cat >> conftest.c <&1 < /dev/null` in +case `"$ac_prog" -Wl,-V 2>&1 < /dev/null` in *GNU*) GNULD=yes;; *) @@ -2503,6 +2519,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 +2558,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 +2658,7 @@ if test -z "$SHLIB_SUFFIX"; then *) SHLIB_SUFFIX=.sl;; esac ;; + Darwin*) SHLIB_SUFFIX=.dylib;; CYGWIN*) SHLIB_SUFFIX=.dll;; *) SHLIB_SUFFIX=.so;; esac From b231d73cb0ce1e0bf31cdd2bdcea7f55b04f1430 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 20 Aug 2021 23:21:32 -0700 Subject: [PATCH 04/45] 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 3244deca913163..ca4588b9a215b6 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 ;; @@ -1101,7 +1110,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";; @@ -1151,9 +1160,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' @@ -1201,7 +1212,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' ;; @@ -1250,7 +1261,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 @@ -2659,7 +2670,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 @@ -2784,6 +2795,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 @@ -2876,7 +2890,7 @@ then LINKFORSHARED="-Xlinker --export-dynamic" fi;; esac;; - CYGWIN*) + CYGWIN*|MinGW*) if test $enable_shared = "no" then LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)' @@ -2900,7 +2914,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='';; @@ -3390,7 +3404,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.]) ;; @@ -4871,15 +4885,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 dd4d627a2c9102..af5d4e41ec7ce6 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 d95ebd72a470563cf0b463e33345865db8f0d26e Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:21:22 -0800 Subject: [PATCH 05/45] 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 45cc589c160852a17d65515a4eea0fcd3f26b54d Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 18 Nov 2021 09:19:08 -0800 Subject: [PATCH 06/45] 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 ca4588b9a215b6..083239f4541a44 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 @@ -881,6 +881,22 @@ cat >> conftest.c < Date: Wed, 10 Nov 2021 18:33:13 -0800 Subject: [PATCH 07/45] 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 42b08e63c6657ef1d8d2d303142c5e17888b0a9f Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:33:35 -0800 Subject: [PATCH 08/45] 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 22a4fbe7760c5181609d3b00c90db8274f4bad3c Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:56:46 -0800 Subject: [PATCH 09/45] 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 6a9ac2ceb734e8..1c7591ff4e902a 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 8c6ea80812c439f034750a438a1756cdce9c7715 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:42:16 -0800 Subject: [PATCH 10/45] 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 af19b29a233ceb82dd8712a9bacb232992011cc8 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:34:32 -0800 Subject: [PATCH 11/45] 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 68fd8e7366a74064f83ff44705b69e6d3880a563 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:40:41 -0800 Subject: [PATCH 12/45] 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 a64c5df5aa2d4b95d2a9f15636b2346449dcbfe3 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:18:38 -0800 Subject: [PATCH 13/45] 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 1c7591ff4e902a..d5718932cfc940 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 23fb9134f8ba716962c226cd2290df2ef2696d36 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:20:18 -0800 Subject: [PATCH 14/45] 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 c2e2d60ebbe340ddf9ac73168cd42b56bb2116d9 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 23:55:55 -0800 Subject: [PATCH 15/45] 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 0d2077a6573d36..05a5a540a36a3e 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -2729,12 +2729,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 1271e9c342c92b8094352a14ad207b759088efac Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:11:49 -0800 Subject: [PATCH 16/45] 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 0f13e7c0b7970e70c215bde2d953a0f1846bb0e3 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:43:40 -0800 Subject: [PATCH 17/45] 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 5f1ee275e8307f71607fc31f6e51caa4c7b3d8ef Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:36:02 -0800 Subject: [PATCH 18/45] 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 3d74b22f7288a6..bb94d45e98ecbb 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 28a83b80d980af1ded4960500b3e3041ed0204df Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 23:47:29 -0800 Subject: [PATCH 19/45] 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 0ca8ad684f5921ba1a0945e7ff96964c570bd533 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:57:59 -0800 Subject: [PATCH 20/45] 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 f13bc4b8d873be48ff56e30671a471e79650226d Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:43:01 -0800 Subject: [PATCH 21/45] 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 f72ce4a1f061d0395867e6c598005e59e29dc9a7 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 02:01:42 -0800 Subject: [PATCH 22/45] 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 e043f747310b6d..364f46e2e59f11 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 31b5aa09e0cc478da80ffa1cdc3a32483f5de955 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:40:05 -0800 Subject: [PATCH 23/45] 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 0f68f93addac3c403a947245fa7d975c5fbabd10 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Wed, 10 Nov 2021 18:39:25 -0800 Subject: [PATCH 24/45] 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 34c44120a20129..f7981dc22ea21c 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1878,10 +1878,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 912dfb5e471fd9b29f4354c8d67fea8858fb2028 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:52:59 -0800 Subject: [PATCH 25/45] 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 9333fb7862c91472572c2145696d59b60de3c99c Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 11 Nov 2021 00:53:18 -0800 Subject: [PATCH 26/45] 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 526f017acbd5f1..b454cc9ec9473f 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 87c018f6d9f6553fcd03e7d6daa9f46bef9993f8 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:08:57 -0800 Subject: [PATCH 27/45] 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 1d5a06a6b4787e..a8cbfd257187b5 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -37,6 +37,7 @@ Data members: #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN #include +#define MS_COREDLL 1 #endif /* MS_WINDOWS */ #ifdef MS_COREDLL From 1e6b0d962a5b87337eefe910a1a5864974f2be93 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:11:00 -0800 Subject: [PATCH 28/45] 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 083239f4541a44..1913b18d551fbc 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 0370a5f41f2372906368ad265ee9169299877751 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 10:35:12 -0800 Subject: [PATCH 29/45] 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 7b770e3defc700d793b44c1664cfbcb533ecc801 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 13:19:26 -0800 Subject: [PATCH 30/45] 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 6e4e973adf5a6acfdc153fa8c98d7d3472aed46a Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 16:25:26 -0800 Subject: [PATCH 31/45] 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 a50ef34543cec18f306d5eb1f22819f649cf15b0 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 19 Nov 2021 16:27:19 -0800 Subject: [PATCH 32/45] 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 f84d2d94db2b27981f0a34cde680523ea97de778 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:16:23 -0800 Subject: [PATCH 33/45] 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 706791907dc6510ec1107533632e2f57c70cee5a Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:17:24 -0800 Subject: [PATCH 34/45] 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 5c59903613b162f948e196fdd167cc221f6326e1 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 00:45:14 -0800 Subject: [PATCH 35/45] 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 25557ea04097ba20bd50cd8bc752bac429389e11 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sat, 20 Nov 2021 01:21:12 -0800 Subject: [PATCH 36/45] 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 f1bb39f57b2298..268821f0f033e0 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -5312,7 +5312,7 @@ _ssl_nid2obj_impl(PyObject *module, int nid) return result; } -#ifdef _MSC_VER +#ifdef MS_WINDOWS static PyObject* certEncodingType(DWORD encodingType) @@ -5631,7 +5631,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 8d29a1acad098272310249b00987a64eac4a0ec3 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Tue, 14 Dec 2021 00:21:22 -0800 Subject: [PATCH 37/45] Add musl detection support to configure.ac. --- configure.ac | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1913b18d551fbc..34787a299a3408 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 #if __has_include() #include #endif @@ -751,7 +757,29 @@ cat >> conftest.c < Date: Tue, 8 Feb 2022 20:16:51 -0800 Subject: [PATCH 38/45] 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 ffdb30742d949e1040b9aa4c897d676b378a4ee3 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Thu, 10 Feb 2022 22:45:12 -0800 Subject: [PATCH 39/45] 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 2f03359b6a5e398696351becf65afa766713e23a Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Sun, 13 Mar 2022 20:46:14 -0700 Subject: [PATCH 40/45] 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 34787a299a3408..6c7e0be2cae068 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 b7e1b29def31e59da34b3ec254261fdd7710cc3f Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Fri, 24 Jun 2022 19:25:30 +0000 Subject: [PATCH 41/45] Add i486-i786 32-bit x86 variant detection to configure.ac for linux targets. --- configure.ac | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6c7e0be2cae068..0557ea085377d6 100644 --- a/configure.ac +++ b/configure.ac @@ -766,7 +766,7 @@ cat >> conftest.c <> conftest.c < Date: Fri, 24 Jun 2022 19:26:29 +0000 Subject: [PATCH 42/45] 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 0557ea085377d6..ad92c4a8076648 100644 --- a/configure.ac +++ b/configure.ac @@ -928,6 +928,14 @@ cat >> conftest.c < Date: Fri, 22 Jul 2022 00:03:00 +0000 Subject: [PATCH 43/45] Skip MULTIARCH check for linux and mingw targets and assume PLATFORM_TRIPLET. --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index ad92c4a8076648..81ba4ce11bfb67 100644 --- a/configure.ac +++ b/configure.ac @@ -960,6 +960,8 @@ rm -f conftest.c conftest.out AC_MSG_CHECKING([for multiarch]) AS_CASE([$ac_sys_system], [Darwin*], [MULTIARCH=""], + [Linux*], [MULTIARCH=""], + [MinGW*], [MULTIARCH=""], [FreeBSD*], [MULTIARCH=""], [MULTIARCH=$($CC --print-multiarch 2>/dev/null)] ) From 63d3eb25594bc4104c7f163b87caa294e9403c03 Mon Sep 17 00:00:00 2001 From: Aaditya Chandrasekhar Date: Tue, 26 Jul 2022 20:50:07 +0000 Subject: [PATCH 44/45] Add MULTIARCH detection for android targets in configure.ac. --- configure.ac | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 81ba4ce11bfb67..711487350bb5ae 100644 --- a/configure.ac +++ b/configure.ac @@ -738,10 +738,10 @@ fi AC_MSG_CHECKING([for the platform triplet based on compiler characteristics]) cat >> conftest.c <) +#if !defined(__ANDROID__) && __has_include() #include #endif -#if __has_include() +#if defined(__APPLE__) && __has_include() #include #endif #undef bfin @@ -756,7 +756,27 @@ cat >> conftest.c < Date: Sat, 1 Oct 2022 06:02:45 +0000 Subject: [PATCH 45/45] Bump actions/stale from 5 to 6 Bumps [actions/stale](https://github.com/actions/stale) from 5 to 6. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 4a08ef0d8dac5f..1e5facf50ec319 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -14,7 +14,7 @@ jobs: steps: - name: "Check PRs" - uses: actions/stale@v5 + uses: actions/stale@v6 with: repo-token: ${{ secrets.GITHUB_TOKEN }} stale-pr-message: 'This PR is stale because it has been open for 30 days with no activity.'