https://github.com/python/cpython/commit/0881e2d3b1212d988733f1d3acca4011ce5e6280
commit: 0881e2d3b1212d988733f1d3acca4011ce5e6280
branch: main
author: Tony Roberts <[email protected]>
committer: colesbury <[email protected]>
date: 2024-09-27T18:52:23Z
summary:

gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (#124663)

files:
A Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst
M Include/Python.h
M Include/object.h
M Misc/ACKS

diff --git a/Include/Python.h b/Include/Python.h
index 8fffa22df9da48..e1abdd16f031fb 100644
--- a/Include/Python.h
+++ b/Include/Python.h
@@ -55,6 +55,10 @@
 #  include <intrin.h>             // __readgsqword()
 #endif
 
+#if defined(Py_GIL_DISABLED) && defined(__MINGW32__)
+#  include <intrin.h>             // __readgsqword()
+#endif
+
 // Include Python header files
 #include "pyport.h"
 #include "pymacro.h"
diff --git a/Include/object.h b/Include/object.h
index 7124f58f6bdb37..418f2196062df7 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -180,6 +180,12 @@ _Py_ThreadId(void)
     tid = __readfsdword(24);
 #elif defined(_MSC_VER) && defined(_M_ARM64)
     tid = __getReg(18);
+#elif defined(__MINGW32__) && defined(_M_X64)
+    tid = __readgsqword(48);
+#elif defined(__MINGW32__) && defined(_M_IX86)
+    tid = __readfsdword(24);
+#elif defined(__MINGW32__) && defined(_M_ARM64)
+    tid = __getReg(18);
 #elif defined(__i386__)
     __asm__("movl %%gs:0, %0" : "=r" (tid));  // 32-bit always uses GS
 #elif defined(__MACH__) && defined(__x86_64__)
diff --git a/Misc/ACKS b/Misc/ACKS
index b2529601a2f71a..d94cbacf888468 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1552,6 +1552,7 @@ Lisa Roach
 Carl Robben
 Ben Roberts
 Mark Roberts
+Tony Roberts
 Andy Robinson
 Izan "TizzySaurus" Robinson
 Jim Robinson
diff --git 
a/Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst 
b/Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst
new file mode 100644
index 00000000000000..203868a8fee39c
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst
@@ -0,0 +1 @@
+Fix ``_Py_ThreadId`` for Windows builds using MinGW. Patch by Tony Roberts.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to