Skip to content

Commit

Permalink
pythonGH-111808: Make the default value for `test.support.infinite_re…
Browse files Browse the repository at this point in the history
…cursion()` conditional on compiler optimizations
  • Loading branch information
brettcannon committed Nov 17, 2023
1 parent 0c61d02 commit 840fcfc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2108,13 +2108,16 @@ def set_recursion_limit(limit):
finally:
sys.setrecursionlimit(original_limit)

def infinite_recursion(max_depth=100):
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 < 3:
if max_depth is None:
# Unoptimized number based on what works under a WASI debug build.
max_depth = 100 if python_is_optimized() else 50
elif max_depth < 3:
raise ValueError("max_depth must be at least 3, got {max_depth}")
depth = get_recursion_depth()
depth = max(depth - 1, 1) # Ignore infinite_recursion() frame.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_richcmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def do(bad):
self.assertRaises(Exc, func, Bad())

@support.no_tracing
@support.infinite_recursion(25)
@support.infinite_recursion()
def test_recursion(self):
# Check that comparison for recursive objects fails gracefully
from collections import UserList
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5621,7 +5621,7 @@ def fun(x: a): pass
def cmp(o1, o2):
return o1 == o2

with infinite_recursion(25): # magic number, small but reasonable
with infinite_recursion():
r1 = namespace1()
r2 = namespace2()
self.assertIsNot(r1, r2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Make the default value of ``test.support.infinite_recursion()`` to be
conditional based on whether optimizations were used when compiling the
interpreter. This helps with platforms like WASI whose stack size is greatly
restricted in debug builds.

0 comments on commit 840fcfc

Please sign in to comment.