Skip to content

Commit 03fc52e

Browse files
committed
Remove exceeds_recursion_limit and get_c_recursion_limit. Use platform independent constants
1 parent a9be141 commit 03fc52e

File tree

15 files changed

+22
-39
lines changed

15 files changed

+22
-39
lines changed

Include/cpython/pystate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ struct _ts {
235235
// higher stack memory usage than a release build: use a lower limit.
236236
# if defined(__has_feature) /* Clang */
237237
// Clang debug builds use a lot of stack space
238-
# define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 2000)
238+
# define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 4000)
239239
# else
240-
# define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 1000)
240+
# define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 2000)
241241
# endif
242242
#elif defined(_Py_ADDRESS_SANITIZER)
243243
# define Py_C_RECURSION_LIMIT (Py_C_STACK_SIZE / 600)

Lib/test/list_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from functools import cmp_to_key
77

88
from test import seq_tests
9-
from test.support import ALWAYS_EQ, NEVER_EQ, get_c_recursion_limit, skip_emscripten_stack_overflow
9+
from test.support import ALWAYS_EQ, NEVER_EQ, skip_emscripten_stack_overflow
1010

1111

1212
class CommonTest(seq_tests.CommonTest):

Lib/test/mapping_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tests common to dict and UserDict
22
import unittest
33
import collections
4-
from test.support import get_c_recursion_limit, skip_emscripten_stack_overflow
4+
from test.support import skip_emscripten_stack_overflow
55

66

77
class BasicTestMappingProtocol(unittest.TestCase):

Lib/test/support/__init__.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"run_with_tz", "PGO", "missing_compiler_executable",
5757
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
5858
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
59-
"Py_DEBUG", "exceeds_recursion_limit", "get_c_recursion_limit",
59+
"Py_DEBUG"
6060
"skip_on_s390x",
6161
"requires_jit_enabled",
6262
"requires_jit_disabled",
@@ -2623,20 +2623,6 @@ def adjust_int_max_str_digits(max_digits):
26232623
finally:
26242624
sys.set_int_max_str_digits(current)
26252625

2626-
2627-
def get_c_recursion_limit():
2628-
try:
2629-
import _testcapi
2630-
return _testcapi.Py_C_RECURSION_LIMIT
2631-
except ImportError:
2632-
raise unittest.SkipTest('requires _testcapi')
2633-
2634-
2635-
def exceeds_recursion_limit():
2636-
"""For recursion tests, easily exceeds default recursion limit."""
2637-
return get_c_recursion_limit() * 20
2638-
2639-
26402626
# Windows doesn't have os.uname() but it doesn't support s390x.
26412627
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
26422628
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')

Lib/test/test_ast/test_ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ def next(self):
747747
@support.cpython_only
748748
@skip_emscripten_stack_overflow()
749749
def test_ast_recursion_limit(self):
750-
fail_depth = support.exceeds_recursion_limit() * 2
750+
fail_depth = 20_000
751751
crash_depth = 200_000
752-
success_depth = support.get_c_recursion_limit()
752+
success_depth = 200
753753
if _testinternalcapi is not None:
754754
remaining = _testinternalcapi.get_c_recursion_remaining()
755755
success_depth = min(success_depth, remaining)

Lib/test/test_capi/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def test_trashcan_subclass(self):
408408
# activated when its tp_dealloc is being called by a subclass
409409
from _testcapi import MyList
410410
L = None
411-
for i in range(support.get_c_recursion_limit()):
411+
for i in range(100):
412412
L = MyList((L,))
413413

414414
@support.requires_resource('cpu')

Lib/test/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def test_odd_sizes(self):
542542
self.assertEqual(Dot(1)._replace(d=999), (999,))
543543
self.assertEqual(Dot(1)._fields, ('d',))
544544

545-
n = support.exceeds_recursion_limit()
545+
n = 100_000
546546
names = list(set(''.join([choice(string.ascii_letters)
547547
for j in range(10)]) for i in range(n)))
548548
n = len(names)

Lib/test/test_compile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from test import support
2323
from test.support import (script_helper, requires_debug_ranges, run_code,
24-
requires_specialization, get_c_recursion_limit)
24+
requires_specialization)
2525
from test.support.bytecode_helper import instructions_with_positions
2626
from test.support.os_helper import FakePath
2727

@@ -123,7 +123,7 @@ def __getitem__(self, key):
123123
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
124124
@support.skip_emscripten_stack_overflow()
125125
def test_extended_arg(self):
126-
repeat = int(get_c_recursion_limit() * 0.9)
126+
repeat = 100
127127
longexpr = 'x = x or ' + '-x' * repeat
128128
g = {}
129129
code = textwrap.dedent('''
@@ -713,7 +713,7 @@ def test_yet_more_evil_still_undecodable(self):
713713
@support.skip_emscripten_stack_overflow()
714714
def test_compiler_recursion_limit(self):
715715
# Compiler frames are small
716-
limit = get_c_recursion_limit() * 3 // 2
716+
limit = 100
717717
fail_depth = limit * 50
718718
crash_depth = limit * 200
719719
success_depth = limit

Lib/test/test_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import unittest
99
import weakref
1010
from test import support
11-
from test.support import import_helper, get_c_recursion_limit
11+
from test.support import import_helper
1212

1313

1414
class DictTest(unittest.TestCase):

Lib/test/test_dictviews.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import copy
33
import pickle
44
import unittest
5-
from test.support import exceeds_recursion_limit, skip_emscripten_stack_overflow
5+
from test.support import skip_emscripten_stack_overflow
66

77
class DictSetTest(unittest.TestCase):
88

@@ -280,7 +280,7 @@ def test_recursive_repr(self):
280280
@skip_emscripten_stack_overflow()
281281
def test_deeply_nested_repr(self):
282282
d = {}
283-
for i in range(exceeds_recursion_limit() * 2):
283+
for i in range(100_000):
284284
d = {42: d.values()}
285285
self.assertRaises(RecursionError, repr, d)
286286

0 commit comments

Comments
 (0)