Skip to content

gh-139231: Fix estimation of available stack size for recursion limit on macOS#139232

Merged
markshannon merged 1 commit intopython:mainfrom
rokm:macos-stack-size-fix
Sep 24, 2025
Merged

gh-139231: Fix estimation of available stack size for recursion limit on macOS#139232
markshannon merged 1 commit intopython:mainfrom
rokm:macos-stack-size-fix

Conversation

@rokm
Copy link
Contributor

@rokm rokm commented Sep 22, 2025

On macOS, use pthread_get_stackaddr_np() and pthread_get_stacksize_np() to determine the stack address and size (used by code handling the recursion limit), rather than falling back to conservative hard-coded default of 4 MB.

Fixes #139231; the output of reproducer script is now:

Stack address: 6089916416 = 0x16AFCC000
Stack size: 16777216 = 16384.0 kB = 16.0 MB
Stack pointer: 0x16AFCA140, depth: 7.69 kB
Testing Recursion Limit
Initial limit: 1000
Recursion level: 1, stack pointer: 0x16AFC9870, depth: 9.89 kB
Recursion level: 2, stack pointer: 0x16AFC8FA0, depth: 12.09 kB
...
Recursion level: 7586, stack pointer: 0x169FD0BA0, depth: 16365.09 kB
Recursion level: 7587, stack pointer: 0x169FD0300, depth: 16367.25 kB
Recursion Limit ok (reached level 7588)

(i.e., stack is fully utilized, as expected).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Under-estimated stack size for recursion limit (macOS + python >= 3.14)

2 participants