Skip to content

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).

… limit on macOS

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.
@python-cla-bot
Copy link

python-cla-bot bot commented Sep 22, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Sep 22, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@markshannon markshannon merged commit 7016044 into python:main Sep 24, 2025
87 of 89 checks passed
@markshannon markshannon added the needs backport to 3.14 bugs and security fixes label Sep 24, 2025
@miss-islington-app
Copy link

Thanks @rokm for the PR, and @markshannon for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 24, 2025
… limit on macOS (pythonGH-139232)

Use `pthread_get_stackaddr_np()` and `pthread_get_stacksize_np()` to determine the stack address and size.
(cherry picked from commit 7016044)

Co-authored-by: Rok Mandeljc <rok.mandeljc@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Sep 24, 2025

GH-139290 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Sep 24, 2025
@rokm rokm deleted the macos-stack-size-fix branch September 24, 2025 11:03
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