From 4618c0e5e60067025fd4e3ffeec494af68534862 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:58:36 +0200 Subject: [PATCH] [3.13] gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (GH-124663) (#124698) gh-124609: Fix _Py_ThreadId for Windows builds using MinGW (GH-124663) (cherry picked from commit 0881e2d3b1212d988733f1d3acca4011ce5e6280) Co-authored-by: Tony Roberts --- Include/Python.h | 4 ++++ Include/object.h | 6 ++++++ Misc/ACKS | 1 + .../Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst | 1 + 4 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2024-09-27-13-40-25.gh-issue-124609.WaKk8G.rst diff --git a/Include/Python.h b/Include/Python.h index 882b96b73a7..fb2d32d7110 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -55,6 +55,10 @@ # include // __readgsqword() #endif +#if defined(Py_GIL_DISABLED) && defined(__MINGW32__) +# include // __readgsqword() +#endif + // Include Python header files #include "pyport.h" #include "pymacro.h" diff --git a/Include/object.h b/Include/object.h index b4db7fb204f..78aa7ad0f45 100644 --- a/Include/object.h +++ b/Include/object.h @@ -247,6 +247,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 dff73bba013..a4a73709fae 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1550,6 +1550,7 @@ Lisa Roach Carl Robben Ben Roberts Mark Roberts +Tony Roberts Andy Robinson Jim Robinson Yolanda Robla 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 00000000000..203868a8fee --- /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.