Skip to content

Commit 13af007

Browse files
committed
gh-158165: Fix _Py_get_machine_stack_pointer() compilation with MinGW
1 parent 4f3be1b commit 13af007

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎Include/internal/pycore_pystate.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,16 @@ static uintptr_t return_pointer_as_int(char* p) {
317317
static inline uintptr_t
318318
_Py_get_machine_stack_pointer(void) {
319319
uintptr_t result;
320-
#if defined(_M_ARM64)
320+
#if _Py__has_builtin(__builtin_stack_address)
321+
result = (uintptr_t)__builtin_stack_address();
322+
#elif defined(_MSC_VER) && defined(_M_ARM64)
321323
result = __getReg(31);
322-
#elif defined(_M_X64) || defined(_M_IX86)
324+
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
323325
result = (uintptr_t)_AddressOfReturnAddress();
324326
#elif defined(__aarch64__)
325327
__asm__ ("mov %0, sp" : "=r" (result));
326328
#elif defined(__x86_64__)
327-
__asm__("{movq %%rsp, %0" : "=r" (result));
329+
__asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));
328330
#else
329331
char here;
330332
result = (uintptr_t)&here;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix compilation of ``_Py_get_machine_stack_pointer()` with MinGW on Windows.
2+
Patch by Donghee Na.

0 commit comments

Comments
 (0)