GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)

* Implement C recursion protection with limit pointers

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
This commit is contained in:
Mark Shannon 2025-02-19 11:44:57 +00:00 committed by GitHub
parent c637bce20a
commit 2498c22fa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 1217 additions and 1463 deletions

View file

@ -21,7 +21,7 @@ except ImportError:
from test import support
from test.support import (script_helper, requires_debug_ranges, run_code,
requires_specialization, get_c_recursion_limit)
requires_specialization)
from test.support.bytecode_helper import instructions_with_positions
from test.support.os_helper import FakePath
@ -123,7 +123,7 @@ class TestSpecifics(unittest.TestCase):
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
@support.skip_emscripten_stack_overflow()
def test_extended_arg(self):
repeat = int(get_c_recursion_limit() * 0.9)
repeat = 100
longexpr = 'x = x or ' + '-x' * repeat
g = {}
code = textwrap.dedent('''
@ -712,11 +712,11 @@ class TestSpecifics(unittest.TestCase):
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
@support.skip_emscripten_stack_overflow()
def test_compiler_recursion_limit(self):
# Expected limit is Py_C_RECURSION_LIMIT
limit = get_c_recursion_limit()
fail_depth = limit + 1
crash_depth = limit * 100
success_depth = int(limit * 0.8)
# Compiler frames are small
limit = 100
fail_depth = limit * 1000
crash_depth = limit * 2000
success_depth = limit
def check_limit(prefix, repeated, mode="single"):
expect_ok = prefix + repeated * success_depth