summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Roberts <tony@pyxll.com>2024-09-27 18:52:23 (GMT)
committerGitHub <noreply@github.com>2024-09-27 18:52:23 (GMT)
commit0881e2d3b1212d988733f1d3acca4011ce5e6280 (patch)
tree7afc9664bcb62f1ab54a43f59d7789bb4ef64dc1
parent2e155536caf8a090c06d62dd92647abc62362463 (diff)
downloadcpython-0881e2d3b1212d988733f1d3acca4011ce5e6280.zip
cpython-0881e2d3b1212d988733f1d3acca4011ce5e6280.tar.gz
cpython-0881e2d3b1212d988733f1d3acca4011ce5e6280.tar.bz2
gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (#124663)
-rw-r--r--Include/Python.h4
-rw-r--r--Include/object.h6
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst1
4 files changed, 12 insertions, 0 deletions
diff --git a/Include/Python.h b/Include/Python.h
index 8fffa22..e1abdd1 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 7124f58..418f219 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 b252960..d94cbac 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 0000000..203868a
--- /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.