mirror of
https://github.com/python/cpython.git
synced 2026-01-08 00:12:42 +00:00
GH-113655: Lower the C recursion limit on various platforms (GH-113944)
This commit is contained in:
parent
6c502ba809
commit
17b73ab99e
13 changed files with 41 additions and 39 deletions
|
|
@ -2377,7 +2377,10 @@ def _get_c_recursion_limit():
|
|||
return _testcapi.Py_C_RECURSION_LIMIT
|
||||
except (ImportError, AttributeError):
|
||||
# Originally taken from Include/cpython/pystate.h .
|
||||
return 8000
|
||||
if sys.platform == 'win32':
|
||||
return 4000
|
||||
else:
|
||||
return 10000
|
||||
|
||||
# The default C recursion limit.
|
||||
Py_C_RECURSION_LIMIT = _get_c_recursion_limit()
|
||||
|
|
|
|||
|
|
@ -1126,7 +1126,7 @@ def next(self):
|
|||
def test_ast_recursion_limit(self):
|
||||
fail_depth = support.EXCEEDS_RECURSION_LIMIT
|
||||
crash_depth = 100_000
|
||||
success_depth = 1200
|
||||
success_depth = int(support.Py_C_RECURSION_LIMIT * 0.8)
|
||||
if _testinternalcapi is not None:
|
||||
remaining = _testinternalcapi.get_c_recursion_remaining()
|
||||
success_depth = min(success_depth, remaining)
|
||||
|
|
|
|||
|
|
@ -623,12 +623,10 @@ def test_yet_more_evil_still_undecodable(self):
|
|||
@support.cpython_only
|
||||
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
|
||||
def test_compiler_recursion_limit(self):
|
||||
# Expected limit is Py_C_RECURSION_LIMIT * 2
|
||||
# Duplicating the limit here is a little ugly.
|
||||
# Perhaps it should be exposed somewhere...
|
||||
fail_depth = Py_C_RECURSION_LIMIT * 2 + 1
|
||||
# Expected limit is Py_C_RECURSION_LIMIT
|
||||
fail_depth = Py_C_RECURSION_LIMIT + 1
|
||||
crash_depth = Py_C_RECURSION_LIMIT * 100
|
||||
success_depth = int(Py_C_RECURSION_LIMIT * 1.8)
|
||||
success_depth = int(Py_C_RECURSION_LIMIT * 0.8)
|
||||
|
||||
def check_limit(prefix, repeated, mode="single"):
|
||||
expect_ok = prefix + repeated * success_depth
|
||||
|
|
|
|||
|
|
@ -1875,8 +1875,14 @@ def fib(n):
|
|||
return fib(n-1) + fib(n-2)
|
||||
|
||||
if not support.Py_DEBUG:
|
||||
depth = support.Py_C_RECURSION_LIMIT*2//7
|
||||
with support.infinite_recursion():
|
||||
fib(2500)
|
||||
fib(depth)
|
||||
if self.module == c_functools:
|
||||
fib.cache_clear()
|
||||
with support.infinite_recursion():
|
||||
with self.assertRaises(RecursionError):
|
||||
fib(10000)
|
||||
|
||||
|
||||
@py_functools.lru_cache()
|
||||
|
|
|
|||
|
|
@ -3037,10 +3037,8 @@ def test_trace_unpack_long_sequence(self):
|
|||
self.assertEqual(counts, {'call': 1, 'line': 301, 'return': 1})
|
||||
|
||||
def test_trace_lots_of_globals(self):
|
||||
count = 1000
|
||||
if _testinternalcapi is not None:
|
||||
remaining = _testinternalcapi.get_c_recursion_remaining()
|
||||
count = min(count, remaining)
|
||||
|
||||
count = min(1000, int(support.Py_C_RECURSION_LIMIT * 0.8))
|
||||
|
||||
code = """if 1:
|
||||
def f():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue