Skip to content

Commit 5c7445b

Browse files
authored
gh-158165: Fix _Py_get_machine_stack_pointer() compilation with MinGW (#158167)
1 parent ee782e6 commit 5c7445b

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
@@ -335,14 +335,16 @@ static uintptr_t return_pointer_as_int(char* p) {
335335
static inline uintptr_t
336336
_Py_get_machine_stack_pointer(void) {
337337
uintptr_t result;
338-
#if defined(_M_ARM64)
338+
#if _Py__has_builtin(__builtin_stack_address)
339+
result = (uintptr_t)__builtin_stack_address();
340+
#elif defined(_MSC_VER) && defined(_M_ARM64)
339341
result = __getReg(31);
340-
#elif defined(_M_X64) || defined(_M_IX86)
342+
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
341343
result = (uintptr_t)_AddressOfReturnAddress();
342344
#elif defined(__aarch64__)
343345
__asm__ ("mov %0, sp" : "=r" (result));
344346
#elif defined(__x86_64__)
345-
__asm__("{movq %%rsp, %0" : "=r" (result));
347+
__asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));
346348
#else
347349
char here;
348350
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)