GH-112215: Increase C recursion limit for non debug builds (GH-113397)

This commit is contained in:
Mark Shannon 2023-12-22 14:25:25 +00:00 committed by GitHub
parent 5f665e99e0
commit 45e09f921b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 21 deletions

View file

@ -2122,19 +2122,11 @@ def set_recursion_limit(limit):
sys.setrecursionlimit(original_limit)
def infinite_recursion(max_depth=None):
"""Set a lower limit for tests that interact with infinite recursions
(e.g test_ast.ASTHelpers_Test.test_recursion_direct) since on some
debug windows builds, due to not enough functions being inlined the
stack size might not handle the default recursion limit (1000). See
bpo-11105 for details."""
if max_depth is None:
if not python_is_optimized() or Py_DEBUG:
# Python built without compiler optimizations or in debug mode
# usually consumes more stack memory per function call.
# Unoptimized number based on what works under a WASI debug build.
max_depth = 50
else:
max_depth = 100
# Pick a number large enough to cause problems
# but not take too long for code that can handle
# very deep recursion.
max_depth = 20_000
elif max_depth < 3:
raise ValueError("max_depth must be at least 3, got {max_depth}")
depth = get_recursion_depth()
@ -2373,8 +2365,6 @@ def adjust_int_max_str_digits(max_digits):
finally:
sys.set_int_max_str_digits(current)
#For recursion tests, easily exceeds default recursion limit
EXCEEDS_RECURSION_LIMIT = 5000
def _get_c_recursion_limit():
try:
@ -2382,11 +2372,14 @@ def _get_c_recursion_limit():
return _testcapi.Py_C_RECURSION_LIMIT
except (ImportError, AttributeError):
# Originally taken from Include/cpython/pystate.h .
return 1500
return 8000
# The default C recursion limit.
Py_C_RECURSION_LIMIT = _get_c_recursion_limit()
#For recursion tests, easily exceeds default recursion limit
EXCEEDS_RECURSION_LIMIT = Py_C_RECURSION_LIMIT * 3
#Windows doesn't have os.uname() but it doesn't support s390x.
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
'skipped on s390x')