https://github.com/python/cpython/commit/5c7445be431698c6764af1246b2f5d7ca5c5c930
commit: 5c7445be431698c6764af1246b2f5d7ca5c5c930
branch: main
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2026-10-02T14:05:24+09:00
summary:

gh-158165: Fix _Py_get_machine_stack_pointer() compilation with MinGW (#158167)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-09-25-22-34-50.gh-issue-158165.GVPxKy.rst
M Include/internal/pycore_pystate.h

diff --git a/Include/internal/pycore_pystate.h 
b/Include/internal/pycore_pystate.h
index 8b8f0a98bedf76b..16f876140020bb7 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -335,14 +335,16 @@ static uintptr_t return_pointer_as_int(char* p) {
 static inline uintptr_t
 _Py_get_machine_stack_pointer(void) {
     uintptr_t result;
-#if defined(_M_ARM64)
+#if _Py__has_builtin(__builtin_stack_address)
+    result = (uintptr_t)__builtin_stack_address();
+#elif defined(_MSC_VER) && defined(_M_ARM64)
     result = __getReg(31);
-#elif defined(_M_X64) || defined(_M_IX86)
+#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
     result = (uintptr_t)_AddressOfReturnAddress();
 #elif defined(__aarch64__)
     __asm__ ("mov %0, sp" : "=r" (result));
 #elif defined(__x86_64__)
-    __asm__("{movq %%rsp, %0" : "=r" (result));
+    __asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));
 #else
     char here;
     result = (uintptr_t)&here;
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-09-25-22-34-50.gh-issue-158165.GVPxKy.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-25-22-34-50.gh-issue-158165.GVPxKy.rst
new file mode 100644
index 000000000000000..055bfba4688809b
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-25-22-34-50.gh-issue-158165.GVPxKy.rst
@@ -0,0 +1,2 @@
+Fix compilation of ``_Py_get_machine_stack_pointer()`` with MinGW on Windows.
+Patch by Donghee Na.

_______________________________________________
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