Skip to content

Commit 5e50b7e

Browse files
committed
Try increasing the C recursion limit
1 parent de8a4e5 commit 5e50b7e

File tree

6 files changed

+10
-21
lines changed

6 files changed

+10
-21
lines changed

Include/cpython/pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct _ts {
225225
# define Py_C_RECURSION_LIMIT 500
226226
#else
227227
// This value is duplicated in Lib/test/support/__init__.py
228-
# define Py_C_RECURSION_LIMIT 1500
228+
# define Py_C_RECURSION_LIMIT 4500
229229
#endif
230230

231231

Lib/test/support/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,19 +2122,8 @@ def set_recursion_limit(limit):
21222122
sys.setrecursionlimit(original_limit)
21232123

21242124
def infinite_recursion(max_depth=None):
2125-
"""Set a lower limit for tests that interact with infinite recursions
2126-
(e.g test_ast.ASTHelpers_Test.test_recursion_direct) since on some
2127-
debug windows builds, due to not enough functions being inlined the
2128-
stack size might not handle the default recursion limit (1000). See
2129-
bpo-11105 for details."""
21302125
if max_depth is None:
2131-
if not python_is_optimized() or Py_DEBUG:
2132-
# Python built without compiler optimizations or in debug mode
2133-
# usually consumes more stack memory per function call.
2134-
# Unoptimized number based on what works under a WASI debug build.
2135-
max_depth = 50
2136-
else:
2137-
max_depth = 100
2126+
max_depth = 20_000
21382127
elif max_depth < 3:
21392128
raise ValueError("max_depth must be at least 3, got {max_depth}")
21402129
depth = get_recursion_depth()
@@ -2374,15 +2363,15 @@ def adjust_int_max_str_digits(max_digits):
23742363
sys.set_int_max_str_digits(current)
23752364

23762365
#For recursion tests, easily exceeds default recursion limit
2377-
EXCEEDS_RECURSION_LIMIT = 5000
2366+
EXCEEDS_RECURSION_LIMIT = 10_000
23782367

23792368
def _get_c_recursion_limit():
23802369
try:
23812370
import _testcapi
23822371
return _testcapi.Py_C_RECURSION_LIMIT
23832372
except (ImportError, AttributeError):
23842373
# Originally taken from Include/cpython/pystate.h .
2385-
return 1500
2374+
return 4500
23862375

23872376
# The default C recursion limit.
23882377
Py_C_RECURSION_LIMIT = _get_c_recursion_limit()

Lib/test/test_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from test import support
2121
from test.support.import_helper import import_fresh_module
22-
from test.support import os_helper, script_helper
22+
from test.support import os_helper, script_helper, Py_DEBUG
2323
from test.support.ast_helper import ASTTestMixin
2424

2525
def to_tuple(t):

Lib/test/test_json/test_recursion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def test_highly_nested_objects_encoding(self):
8585
for x in range(100000):
8686
l, d = [l], {'k':d}
8787
with self.assertRaises(RecursionError):
88-
with support.infinite_recursion():
88+
with support.infinite_recursion(5000):
8989
self.dumps(l)
9090
with self.assertRaises(RecursionError):
91-
with support.infinite_recursion():
91+
with support.infinite_recursion(5000):
9292
self.dumps(d)
9393

9494
def test_endless_recursion(self):
@@ -99,7 +99,7 @@ def default(self, o):
9999
return [o]
100100

101101
with self.assertRaises(RecursionError):
102-
with support.infinite_recursion():
102+
with support.infinite_recursion(1000):
103103
EndlessJSONEncoder(check_circular=False).encode(5j)
104104

105105

Lib/test/test_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ def recursive_function(depth):
630630
if depth:
631631
recursive_function(depth - 1)
632632

633-
for max_depth in (5, 25, 250):
633+
for max_depth in (5, 25, 250, 2500):
634634
with support.infinite_recursion(max_depth):
635635
available = support.get_recursion_available()
636636

Lib/test/test_xml_etree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,7 @@ def __eq__(self, o):
25352535
e.extend([ET.Element('bar')])
25362536
self.assertRaises(ValueError, e.remove, X('baz'))
25372537

2538-
@support.infinite_recursion(25)
2538+
@support.infinite_recursion()
25392539
def test_recursive_repr(self):
25402540
# Issue #25455
25412541
e = ET.Element('foo')

0 commit comments

Comments
 (0)