Repository navigation
gh-159879: Do not limit the C stack below what the interpreter assumes - #159883
Draft
serhiy-storchaka wants to merge 1 commit into
Draft
serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
serhiy-storchaka
force-pushed
the
gh-159879-limited-c-stack
branch
from
October 20, 2026 12:47
10eb693 to
72165f3
Compare
…assumes Where a thread's stack size cannot be queried, the interpreter assumes Py_C_STACK_SIZE, and a smaller thread overflows instead of raising RecursionError. run_with_limited_c_stack() now raises such a size to C_STACK_SIZE. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
serhiy-storchaka
force-pushed
the
gh-159879-limited-c-stack
branch
from
October 20, 2026 12:49
72165f3 to
b65f636
Compare
serhiy-storchaka
marked this pull request as draft
October 20, 2026 12:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Where
hardware_stack_limits()cannot query the running thread's stack (AIX, NetBSD, non-glibc Linux), the interpreter assumesPy_C_STACK_SIZE. A test thread created with less than that overflows before the recursion guard notices, so the test crashes instead of gettingRecursionError.test_lazy_importasks for 256 KiB and does exactly that on Alpine.run_with_limited_c_stack()now probes once whether the real size is visible — two threads of different sizes report the same headroom only when the fixed estimate is in use — and raises a too-small size toC_STACK_SIZEwhen it is not.Verified both ways: on Alpine the probe returns False, the clamp applies and
test_lazy_importpasses with an unpatchedceval.c; on glibc it returns True, nothing is clamped, and the tests using the helper are unaffected.Independent of #159882, which fixes the detection itself.
🤖 Generated with Claude Code