Skip to content

Commit d1abed5

Browse files
committed
Address gps's review comments.
1 parent d75797c commit d1abed5

File tree

8 files changed

+15
-8
lines changed

8 files changed

+15
-8
lines changed

Include/cpython/pystate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ struct _ts {
207207
/* WASI has limited call stack. Python's recursion limit depends on code
208208
layout, optimization, and WASI runtime. Wasmtime can handle about 700
209209
recursions, sometimes less. 500 is a more conservative limit. */
210-
#ifndef Py_DEFAULT_RECURSION_LIMIT
210+
#ifndef C_RECURSION_LIMIT
211211
# ifdef __wasi__
212212
# define C_RECURSION_LIMIT 500
213213
# else

Include/internal/pycore_ceval.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ extern "C" {
1212
struct pyruntimestate;
1313
struct _ceval_runtime_state;
1414

15-
#define Py_DEFAULT_RECURSION_LIMIT 1000
15+
#ifndef Py_DEFAULT_RECURSION_LIMIT
16+
# define Py_DEFAULT_RECURSION_LIMIT 1000
17+
#endif
1618

1719
#include "pycore_interp.h" // PyInterpreterState.eval_frame
1820
#include "pycore_pystate.h" // _PyThreadState_GET()

Lib/test/support/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"run_with_tz", "PGO", "missing_compiler_executable",
6161
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
6262
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
63-
"Py_DEBUG",
63+
"Py_DEBUG", "EXCEEDS_RECURSION_LIMIT",
6464
]
6565

6666

@@ -2352,3 +2352,6 @@ def adjust_int_max_str_digits(max_digits):
23522352
yield
23532353
finally:
23542354
sys.set_int_max_str_digits(current)
2355+
2356+
#For recursion tests, easily exceeds default recursion limit
2357+
EXCEEDS_RECURSION_LIMIT = 5000

Lib/test/test_ast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def next(self):
825825

826826
@support.cpython_only
827827
def test_ast_recursion_limit(self):
828-
fail_depth = 5000
828+
fail_depth = support.EXCEEDS_RECURSION_LIMIT
829829
crash_depth = 100_000
830830
success_depth = 1200
831831

Lib/test/test_collections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def test_odd_sizes(self):
545545
self.assertEqual(Dot(1)._replace(d=999), (999,))
546546
self.assertEqual(Dot(1)._fields, ('d',))
547547

548-
n = 5000
548+
n = support.EXCEEDS_RECURSION_LIMIT
549549
names = list(set(''.join([choice(string.ascii_letters)
550550
for j in range(10)]) for i in range(n)))
551551
n = len(names)

Lib/test/test_exceptions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ def test_recursion_normalizing_exception(self):
13721372
code = """if 1:
13731373
import sys
13741374
from _testinternalcapi import get_recursion_depth
1375+
from test import support
13751376
13761377
class MyException(Exception): pass
13771378
@@ -1400,7 +1401,7 @@ def gen():
14001401
next(generator)
14011402
recursionlimit = sys.getrecursionlimit()
14021403
try:
1403-
recurse(5000)
1404+
recurse(support.EXCEEDS_RECURSION_LIMIT)
14041405
finally:
14051406
sys.setrecursionlimit(recursionlimit)
14061407
print('Done.')

Lib/test/test_isinstance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def blowstack(fxn, arg, compare_to):
353353
# Make sure that calling isinstance with a deeply nested tuple for its
354354
# argument will raise RecursionError eventually.
355355
tuple_arg = (compare_to,)
356-
for cnt in range(5000):
356+
for cnt in range(support.EXCEEDS_RECURSION_LIMIT):
357357
tuple_arg = (tuple_arg,)
358358
fxn(arg, tuple_arg)
359359

Lib/test/test_marshal.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def test_code(self):
117117

118118
def test_many_codeobjects(self):
119119
# Issue2957: bad recursion count on code objects
120-
count = 5000 # more than MAX_MARSHAL_STACK_DEPTH
120+
# more than MAX_MARSHAL_STACK_DEPTH
121+
count = support.EXCEEDS_RECURSION_LIMIT
121122
codes = (ExceptionTestCase.test_exceptions.__code__,) * count
122123
marshal.loads(marshal.dumps(codes))
123124

0 commit comments

Comments
 (0)