Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
From 2115fe6ff955e128126b6f7f30b9282489608a4b Mon Sep 17 00:00:00 2001
From 954b5861478843b0f7769fce97a2ff11d50c7681 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?=
<alexey.pawlow@gmail.com>
Date: Thu, 17 Jun 2021 18:51:12 +0530
Subject: [PATCH 002/N] build: add --with-nt-threads and make it default on
Subject: [PATCH 001/N] build: add --with-nt-threads and make it default on
mingw
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Expand All @@ -12,31 +12,19 @@ Co-authored-by: Naveen M K <naveen521kk@gmail.com>
Co-authored-by: Алексей <alexey.pawlow@gmail.com>
Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>
---
Include/internal/pycore_condvar.h | 10 ++
Include/internal/pycore_condvar.h | 4 +
Include/internal/pycore_pythread.h | 6 ++
Include/pythread.h | 6 ++
Modules/_multiprocessing/multiprocessing.h | 5 +-
Modules/_multiprocessing/multiprocessing.h | 3 +
configure.ac | 102 ++++++++++++++++++++-
pyconfig.h.in | 3 +
5 files changed, 122 insertions(+), 4 deletions(-)
6 files changed, 121 insertions(+), 3 deletions(-)

diff --git a/Include/internal/pycore_condvar.h b/Include/internal/pycore_condvar.h
index 2177bed..c46486f 100644
index 55271f0..8b23568 100644
--- a/Include/internal/pycore_condvar.h
+++ b/Include/internal/pycore_condvar.h
@@ -5,6 +5,12 @@
# error "this header requires Py_BUILD_CORE define"
#endif

+#ifdef __MINGW32__
+# if !defined(HAVE_PTHREAD_H) || defined(NT_THREADS)
+# undef _POSIX_THREADS
+# endif
+#endif
+
#ifndef _POSIX_THREADS
/* This means pthreads are not implemented in libc headers, hence the macro
not present in unistd.h. But they still can be implemented as an external
@@ -41,6 +47,10 @@
@@ -35,6 +35,10 @@
# define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h> // CRITICAL_SECTION
Expand All @@ -46,9 +34,26 @@ index 2177bed..c46486f 100644
+#endif

/* options */
/* non-emulated condition variables are provided for those that want
/* emulated condition variables are provided for those that want
diff --git a/Include/internal/pycore_pythread.h b/Include/internal/pycore_pythread.h
index bc389a0..bd24235 100644
--- a/Include/internal/pycore_pythread.h
+++ b/Include/internal/pycore_pythread.h
@@ -16,6 +16,12 @@ extern "C" {
&& !defined(_POSIX_SEMAPHORES))
# include <unistd.h> // _POSIX_THREADS, _POSIX_SEMAPHORES
#endif
+#ifdef __MINGW32__
+# if !defined(HAVE_PTHREAD_H) || defined(NT_THREADS)
+# undef _POSIX_THREADS
+# endif
+#endif
+
#if (defined(HAVE_PTHREAD_H) && !defined(_POSIX_THREADS) \
&& !defined(_POSIX_SEMAPHORES))
// This means pthreads are not implemented in libc headers, hence the macro
diff --git a/Include/pythread.h b/Include/pythread.h
index 6371443..5e84e3c 100644
index 4aa221c..af9426a 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -7,6 +7,12 @@ typedef void *PyThread_type_lock;
Expand All @@ -65,26 +70,24 @@ index 6371443..5e84e3c 100644
* backwards compatibility, ie failure -> 0, success -> 1. */
typedef enum PyLockStatus {
diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h
index dfc2a8e..dc92a23 100644
index 099004b..ba80920 100644
--- a/Modules/_multiprocessing/multiprocessing.h
+++ b/Modules/_multiprocessing/multiprocessing.h
@@ -23,7 +23,10 @@
# endif
@@ -31,6 +31,9 @@
# define SEM_HANDLE HANDLE
# define SEM_VALUE_MAX LONG_MAX
-# define HAVE_MP_SEMAPHORE
+# define HAVE_MP_SEMAPHORE
# define HAVE_MP_SEMAPHORE
+# if defined(HAVE_SEM_OPEN) && defined(_POSIX_THREADS)
+# include <semaphore.h>
+# endif
#else
# include <fcntl.h> /* O_CREAT and O_EXCL */
# if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
diff --git a/configure.ac b/configure.ac
index 1a02d19..de008a9 100644
index 597a44b..d6f4105 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2721,6 +2721,53 @@ then
@@ -2832,6 +2832,53 @@ then
BASECFLAGS="$BASECFLAGS $ac_arch_flags"
fi

Expand Down Expand Up @@ -121,7 +124,7 @@ index 1a02d19..de008a9 100644
+if test $with_nt_threads = yes ; then
+AC_MSG_CHECKING([whether linking with nt-threads work])
+AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([[]],[[_beginthread(0, 0, 0);]])
+ AC_LANG_PROGRAM([[#include <process.h>]],[[_beginthread(0, 0, 0);]])
+ ],
+ [AC_MSG_RESULT([yes])],
+ [AC_MSG_ERROR([failed to link with nt-threads])])
Expand All @@ -138,7 +141,7 @@ index 1a02d19..de008a9 100644
# On some compilers, pthreads are available without further options
# (e.g. MacOS X). On some of these systems, the compiler will not
# complain if unaccepted options are passed (e.g. gcc on Mac OS X).
@@ -2832,6 +2879,8 @@ int main(void){
@@ -2943,6 +2990,8 @@ int main(void){
CC="$ac_save_cc"])
fi

Expand All @@ -147,7 +150,7 @@ index 1a02d19..de008a9 100644
# If we have set a CC compiler flag for thread support then
# check if it works for CXX, too.
if test ! -z "$CXX"
@@ -2851,6 +2900,10 @@ elif test "$ac_cv_pthread" = "yes"
@@ -2962,6 +3011,10 @@ elif test "$ac_cv_pthread" = "yes"
then
CXX="$CXX -pthread"
ac_cv_cxx_thread=yes
Expand All @@ -158,9 +161,9 @@ index 1a02d19..de008a9 100644
else
ac_cv_cxx_thread=no
fi
@@ -2892,8 +2945,8 @@ AC_CHECK_HEADERS([ \
alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/limits.h linux/memfd.h \
@@ -3003,8 +3056,8 @@ AC_CHECK_HEADERS([ \
alloca.h asm/types.h bluetooth.h conio.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/limits.h linux/memfd.h \
linux/random.h linux/soundcard.h \
- linux/tipc.h linux/wait.h netdb.h net/ethernet.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
- sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
Expand All @@ -169,7 +172,7 @@ index 1a02d19..de008a9 100644
sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/pidfd.h sys/poll.h \
sys/random.h sys/resource.h sys/select.h sys/sendfile.h sys/socket.h sys/soundcard.h sys/stat.h \
@@ -2904,6 +2957,14 @@ AC_CHECK_HEADERS([ \
@@ -3015,6 +3068,14 @@ AC_CHECK_HEADERS([ \
AC_HEADER_DIRENT
AC_HEADER_MAJOR

Expand All @@ -184,7 +187,7 @@ index 1a02d19..de008a9 100644
# bluetooth/bluetooth.h has been known to not compile with -std=c99.
# http://permalink.gmane.org/gmane.linux.bluez.kernel/22294
SAVE_CFLAGS=$CFLAGS
@@ -3116,6 +3177,10 @@ elif test "$ac_cv_pthread" = "yes"
@@ -3222,6 +3283,10 @@ elif test "$ac_cv_pthread" = "yes"
then CC="$CC -pthread"
fi

Expand All @@ -195,7 +198,7 @@ index 1a02d19..de008a9 100644
AC_CACHE_CHECK([for pthread_t], [ac_cv_have_pthread_t], [
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[@%:@include <pthread.h>]], [[pthread_t x; x = *(pthread_t*)0;]])
@@ -3147,7 +3212,7 @@ AS_VAR_IF([ac_cv_pthread_key_t_is_arithmetic_type], [yes], [
@@ -3253,7 +3318,7 @@ AS_VAR_IF([ac_cv_pthread_key_t_is_arithmetic_type], [yes], [
AC_DEFINE([PTHREAD_KEY_T_IS_COMPATIBLE_WITH_INT], [1],
[Define if pthread_key_t is compatible with int.])
])
Expand All @@ -204,9 +207,9 @@ index 1a02d19..de008a9 100644
CC="$ac_save_cc"

AC_MSG_CHECKING([for --enable-framework])
@@ -3679,10 +3744,15 @@ AS_VAR_IF([have_uuid], [missing], [

AS_VAR_IF([have_uuid], [missing], [have_uuid=no])
@@ -3881,10 +3946,15 @@ then
fi
fi

+if test $with_nt_threads = yes ; then
+ dnl do not search for sem_init if NT-thread model is enabled
Expand All @@ -220,7 +223,7 @@ index 1a02d19..de008a9 100644

# check if we need libintl for locale functions
AC_CHECK_LIB([intl], [textdomain],
@@ -4402,6 +4472,11 @@ then
@@ -4619,6 +4689,11 @@ then
CXX="$CXX -pthread"
fi
posix_threads=yes
Expand All @@ -232,7 +235,7 @@ index 1a02d19..de008a9 100644
else
if test ! -z "$withval" -a -d "$withval"
then LDFLAGS="$LDFLAGS -L$withval"
@@ -4918,6 +4993,15 @@ else
@@ -5215,6 +5290,15 @@ if test "$ac_sys_system" = "Linux-android"; then
fi

# checks for library functions
Expand All @@ -246,9 +249,9 @@ index 1a02d19..de008a9 100644
+ ac_cv_func_sched_setscheduler=skip
+fi
AC_CHECK_FUNCS([ \
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
accept4 alarm bind_textdomain_codeset chmod chown clock closefrom close_range confstr \
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
@@ -5814,6 +5898,10 @@ dnl actually works. For FreeBSD versions <= 7.2,
@@ -6108,6 +6192,10 @@ dnl actually works. For FreeBSD versions <= 7.2,
dnl the kernel module that provides POSIX semaphores
dnl isn't loaded by default, so an attempt to call
dnl sem_open results in a 'Signal 12' error.
Expand All @@ -259,7 +262,7 @@ index 1a02d19..de008a9 100644
AC_CACHE_CHECK([whether POSIX semaphores are enabled], [ac_cv_posix_semaphores_enabled],
AC_RUN_IFELSE([
AC_LANG_SOURCE([
@@ -5847,6 +5935,14 @@ AS_VAR_IF([ac_cv_posix_semaphores_enabled], [no], [
@@ -6141,6 +6229,14 @@ AS_VAR_IF([ac_cv_posix_semaphores_enabled], [no], [
])

dnl Multiprocessing check for broken sem_getvalue
Expand All @@ -275,10 +278,10 @@ index 1a02d19..de008a9 100644
AC_RUN_IFELSE([
AC_LANG_SOURCE([
diff --git a/pyconfig.h.in b/pyconfig.h.in
index df4d29f..b359e13 100644
index e18a642..60daba7 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -1552,6 +1552,9 @@
@@ -1633,6 +1633,9 @@
/* Define if mvwdelch in curses.h is an expression. */
#undef MVWDELCH_IS_EXPRESSION

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
From 0f488f1213d0c730a1d7a422c12da27141775ab4 Mon Sep 17 00:00:00 2001
From 3d52cd67f6d6cd57c6a13a0066a0bf5d21d18457 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?=
<alexey.pawlow@gmail.com>
Date: Thu, 17 Jun 2021 18:51:13 +0530
Subject: [PATCH 003/N] Define `MS_WINDOWS` (and others) when compiling with
MINGW
Subject: [PATCH 002/N] build: Define `MS_WINDOWS` (and others) when
compiling with MINGW
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Expand All @@ -22,10 +22,10 @@ Co-authored-by: Naveen M K <naveen521kk@gmail.com>
1 file changed, 38 insertions(+)

diff --git a/Include/pyport.h b/Include/pyport.h
index e2bac3b..3d70b8e 100644
index 72a157e..eecb181 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -53,6 +53,44 @@
@@ -49,6 +49,44 @@
#endif


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
From db7e6996294cc66d3f9d132267fbc64dd7b97acb Mon Sep 17 00:00:00 2001
From: Alexey Pavlov <alexpux@gmail.com>
Date: Fri, 5 Sep 2025 15:15:15 +0300
Subject: [PATCH 003/N] sysmodule: Implement flags "_is_mingw",
"is_mingw_ucrt" and "_use_alt_sep"

---
Python/sysmodule.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 993763f..e722a59 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -177,6 +177,38 @@ PySys_GetObject(const char *name)
return value;
}

+static int
+use_alt_sep(void)
+{
+#ifdef MS_WINDOWS
+ char* msystem = getenv("MSYSTEM");
+ if (msystem != NULL && strcmp(msystem, "") != 0) {
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+static int
+is_mingw(void)
+{
+#ifdef __MINGW32__
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+static int
+is_mingw_ucrt(void)
+{
+#if defined(__MINGW32__) && defined(_UCRT)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
static int
sys_set_object(PyInterpreterState *interp, PyObject *key, PyObject *v)
{
@@ -3622,6 +3654,10 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS_FROM_STRING("byteorder", "little");
#endif

+ SET_SYS("_is_mingw", PyLong_FromLong(is_mingw()));
+ SET_SYS("_is_mingw_ucrt", PyLong_FromLong(is_mingw_ucrt()));
+ SET_SYS("_use_alt_sep", PyLong_FromLong(use_alt_sep()));
+
#ifdef MS_COREDLL
SET_SYS("dllhandle", PyLong_FromVoidPtr(PyWin_DLLhModule));
SET_SYS_FROM_STRING("winver", PyWin_DLLVersionString);
Loading
Loading