Skip to content

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

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

markshannon merged 1 commit into
python:mainfrom
rokm:macos-stack-size-fix

Conversation

@rokm

@rokm rokm commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

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

python-cla-bot Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Sep 22, 2025

Copy link
Copy Markdown

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.

Comment thread Python/ceval.c Resolved
@markshannon
markshannon merged commit 7016044 into python:main Sep 24, 2025
@markshannon markshannon added the needs backport to 3.14 bugs and security fixes label Sep 24, 2025
@miss-islington-app

Copy link
Copy Markdown

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

bedevere-app Bot commented Sep 24, 2025

Copy link
Copy Markdown

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
zanieb added a commit to astral-sh/python-build-standalone that referenced this pull request Oct 15, 2025
encukou pushed a commit to encukou/cpython that referenced this pull request Nov 17, 2025
… limit on macOS (pythonGH-139232)

Use `pthread_get_stackaddr_np()` and `pthread_get_stacksize_np()` to determine the stack address and size.
hroncok pushed a commit to hroncok/cpython that referenced this pull request Nov 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants