summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-01-16 09:32:01 (GMT)
committerGitHub <noreply@github.com>2024-01-16 09:32:01 (GMT)
commit17b73ab99ef12f89d41acec7500a244e68b1aaa4 (patch)
treebcde8fca4dc4dae4f9ed5369a4ea23bb825f15bb /Lib/test
parent6c502ba809ff662a5eebf8c6778dec6bd28918fb (diff)
downloadcpython-17b73ab99ef12f89d41acec7500a244e68b1aaa4.zip
cpython-17b73ab99ef12f89d41acec7500a244e68b1aaa4.tar.gz
cpython-17b73ab99ef12f89d41acec7500a244e68b1aaa4.tar.bz2
GH-113655: Lower the C recursion limit on various platforms (GH-113944)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/__init__.py5
-rw-r--r--Lib/test/test_ast.py2
-rw-r--r--Lib/test/test_compile.py8
-rw-r--r--Lib/test/test_functools.py8
-rw-r--r--Lib/test/test_sys_settrace.py6
5 files changed, 17 insertions, 12 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index e5fb725..8344dd1 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -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()
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 64fcb02..3789ac2 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -1126,7 +1126,7 @@ class AST_Tests(unittest.TestCase):
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)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 50629b2..9c36f05 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -623,12 +623,10 @@ class TestSpecifics(unittest.TestCase):
@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
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 0ef45d3..7c66b90 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1875,8 +1875,14 @@ class TestLRU:
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()
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index fc5ca72..ae6e192 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -3037,10 +3037,8 @@ class TestExtendedArgs(unittest.TestCase):
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():