Skip to content

Commit 82acac8

Browse files
committed
Remove COMPILER_STACK_FRAME_SCALE and tweak recursion limits
1 parent eaadfd0 commit 82acac8

File tree

12 files changed

+52
-34
lines changed

12 files changed

+52
-34
lines changed

Include/cpython/pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct _ts {
228228
#elif defined(_WIN32)
229229
# define Py_C_RECURSION_LIMIT 4000
230230
#elif defined(_Py_ADDRESS_SANITIZER)
231-
# define Py_C_RECURSION_LIMIT 8000
231+
# define Py_C_RECURSION_LIMIT 4000
232232
#else
233233
// This value is duplicated in Lib/test/support/__init__.py
234234
# define Py_C_RECURSION_LIMIT 10000

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ struct _Py_global_strings {
276276
STRUCT_FOR_ID(after_in_child)
277277
STRUCT_FOR_ID(after_in_parent)
278278
STRUCT_FOR_ID(aggregate_class)
279+
STRUCT_FOR_ID(alias)
279280
STRUCT_FOR_ID(append)
280281
STRUCT_FOR_ID(argdefs)
282+
STRUCT_FOR_ID(args)
281283
STRUCT_FOR_ID(arguments)
282284
STRUCT_FOR_ID(argv)
283285
STRUCT_FOR_ID(as_integer_ratio)
@@ -401,6 +403,8 @@ struct _Py_global_strings {
401403
STRUCT_FOR_ID(errors)
402404
STRUCT_FOR_ID(event)
403405
STRUCT_FOR_ID(eventmask)
406+
STRUCT_FOR_ID(exc_type)
407+
STRUCT_FOR_ID(exc_value)
404408
STRUCT_FOR_ID(excepthook)
405409
STRUCT_FOR_ID(exception)
406410
STRUCT_FOR_ID(existing_file_name)
@@ -654,6 +658,7 @@ struct _Py_global_strings {
654658
STRUCT_FOR_ID(seek)
655659
STRUCT_FOR_ID(seekable)
656660
STRUCT_FOR_ID(selectors)
661+
STRUCT_FOR_ID(self)
657662
STRUCT_FOR_ID(send)
658663
STRUCT_FOR_ID(sep)
659664
STRUCT_FOR_ID(sequence)
@@ -716,6 +721,7 @@ struct _Py_global_strings {
716721
STRUCT_FOR_ID(timetuple)
717722
STRUCT_FOR_ID(top)
718723
STRUCT_FOR_ID(trace_callback)
724+
STRUCT_FOR_ID(traceback)
719725
STRUCT_FOR_ID(trailers)
720726
STRUCT_FOR_ID(translate)
721727
STRUCT_FOR_ID(true)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_compile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,10 @@ def test_yet_more_evil_still_undecodable(self):
623623
@support.cpython_only
624624
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
625625
def test_compiler_recursion_limit(self):
626-
# Expected limit is Py_C_RECURSION_LIMIT * 2
627-
# Duplicating the limit here is a little ugly.
628-
# Perhaps it should be exposed somewhere...
629-
fail_depth = Py_C_RECURSION_LIMIT * 2 + 1
626+
# Expected limit is Py_C_RECURSION_LIMIT
627+
fail_depth = Py_C_RECURSION_LIMIT + 1
630628
crash_depth = Py_C_RECURSION_LIMIT * 100
631-
success_depth = int(Py_C_RECURSION_LIMIT * 1.8)
629+
success_depth = int(Py_C_RECURSION_LIMIT * 0.8)
632630

633631
def check_limit(prefix, repeated, mode="single"):
634632
expect_ok = prefix + repeated * success_depth

Lib/test/test_functools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,11 +1875,9 @@ def fib(n):
18751875
return fib(n-1) + fib(n-2)
18761876

18771877
if not support.Py_DEBUG:
1878+
depth = support.Py_C_RECURSION_LIMIT*2//7
18781879
with support.infinite_recursion():
1879-
if sys.platform == 'win32':
1880-
fib(1200)
1881-
else:
1882-
fib(2500)
1880+
fib(depth)
18831881
if self.module == c_functools:
18841882
fib.cache_clear()
18851883
with support.infinite_recursion():

Parser/asdl_c.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,15 +1388,14 @@ class PartingShots(StaticVisitor):
13881388
13891389
int starting_recursion_depth;
13901390
/* Be careful here to prevent overflow. */
1391-
int COMPILER_STACK_FRAME_SCALE = 2;
13921391
PyThreadState *tstate = _PyThreadState_GET();
13931392
if (!tstate) {
13941393
return NULL;
13951394
}
13961395
struct validator vstate;
1397-
vstate.recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1396+
vstate.recursion_limit = Py_C_RECURSION_LIMIT;
13981397
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
1399-
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
1398+
starting_recursion_depth = recursion_depth;
14001399
vstate.recursion_depth = starting_recursion_depth;
14011400
14021401
PyObject *result = ast2obj_mod(state, &vstate, t);

Python/Python-ast.c

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/ast.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,6 @@ validate_type_params(struct validator *state, asdl_type_param_seq *tps)
10371037
return 1;
10381038
}
10391039

1040-
1041-
/* See comments in symtable.c. */
1042-
#define COMPILER_STACK_FRAME_SCALE 2
1043-
10441040
int
10451041
_PyAST_Validate(mod_ty mod)
10461042
{
@@ -1057,9 +1053,9 @@ _PyAST_Validate(mod_ty mod)
10571053
}
10581054
/* Be careful here to prevent overflow. */
10591055
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
1060-
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
1056+
starting_recursion_depth = recursion_depth;
10611057
state.recursion_depth = starting_recursion_depth;
1062-
state.recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1058+
state.recursion_limit = Py_C_RECURSION_LIMIT;
10631059

10641060
switch (mod->kind) {
10651061
case Module_kind:

0 commit comments

Comments
 (0)