Skip to content

Commit d845ed1

Browse files
committed
pythonGH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT
Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on #include <Python.h>.
1 parent 8ba4714 commit d845ed1

14 files changed

+32
-32
lines changed

Include/cpython/pystate.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ struct _ts {
197197
/* WASI has limited call stack. Python's recursion limit depends on code
198198
layout, optimization, and WASI runtime. Wasmtime can handle about 700
199199
recursions, sometimes less. 500 is a more conservative limit. */
200-
#ifndef C_RECURSION_LIMIT
200+
#ifndef Py_C_RECURSION_LIMIT
201201
# ifdef __wasi__
202-
# define C_RECURSION_LIMIT 500
202+
# define Py_C_RECURSION_LIMIT 500
203203
# else
204204
// This value is duplicated in Lib/test/support/__init__.py
205-
# define C_RECURSION_LIMIT 1500
205+
# define Py_C_RECURSION_LIMIT 1500
206206
# endif
207207
#endif
208208

Lib/test/list_tests.py

+2-2
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, C_RECURSION_LIMIT
9+
from test.support import ALWAYS_EQ, NEVER_EQ, Py_C_RECURSION_LIMIT
1010

1111

1212
class CommonTest(seq_tests.CommonTest):
@@ -61,7 +61,7 @@ def test_repr(self):
6161

6262
def test_repr_deep(self):
6363
a = self.type2test([])
64-
for i in range(C_RECURSION_LIMIT + 1):
64+
for i in range(Py_C_RECURSION_LIMIT + 1):
6565
a = self.type2test([a])
6666
self.assertRaises(RecursionError, repr, a)
6767

Lib/test/mapping_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import unittest
33
import collections
44
import sys
5-
from test.support import C_RECURSION_LIMIT
5+
from test.support import Py_C_RECURSION_LIMIT
66

77

88
class BasicTestMappingProtocol(unittest.TestCase):
@@ -625,7 +625,7 @@ def __repr__(self):
625625

626626
def test_repr_deep(self):
627627
d = self._empty_mapping()
628-
for i in range(C_RECURSION_LIMIT + 1):
628+
for i in range(Py_C_RECURSION_LIMIT + 1):
629629
d0 = d
630630
d = self._empty_mapping()
631631
d[1] = d0

Lib/test/support/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"run_with_tz", "PGO", "missing_compiler_executable",
6060
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
6161
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
62-
"Py_DEBUG", "EXCEEDS_RECURSION_LIMIT", "C_RECURSION_LIMIT",
62+
"Py_DEBUG", "EXCEEDS_RECURSION_LIMIT", "Py_C_RECURSION_LIMIT",
6363
"skip_on_s390x",
6464
]
6565

@@ -2464,7 +2464,7 @@ def adjust_int_max_str_digits(max_digits):
24642464
EXCEEDS_RECURSION_LIMIT = 5000
24652465

24662466
# The default C recursion limit (from Include/cpython/pystate.h).
2467-
C_RECURSION_LIMIT = 1500
2467+
Py_C_RECURSION_LIMIT = 1500
24682468

24692469
#Windows doesn't have os.uname() but it doesn't support s390x.
24702470
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',

Lib/test/test_compile.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings
1212
from test import support
1313
from test.support import (script_helper, requires_debug_ranges,
14-
requires_specialization, C_RECURSION_LIMIT)
14+
requires_specialization, Py_C_RECURSION_LIMIT)
1515
from test.support.os_helper import FakePath
1616

1717
class TestSpecifics(unittest.TestCase):
@@ -111,7 +111,7 @@ def __getitem__(self, key):
111111

112112
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
113113
def test_extended_arg(self):
114-
repeat = int(C_RECURSION_LIMIT * 0.9)
114+
repeat = int(Py_C_RECURSION_LIMIT * 0.9)
115115
longexpr = 'x = x or ' + '-x' * repeat
116116
g = {}
117117
code = textwrap.dedent('''
@@ -557,12 +557,12 @@ def test_yet_more_evil_still_undecodable(self):
557557
@support.cpython_only
558558
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
559559
def test_compiler_recursion_limit(self):
560-
# Expected limit is C_RECURSION_LIMIT * 2
560+
# Expected limit is Py_C_RECURSION_LIMIT * 2
561561
# Duplicating the limit here is a little ugly.
562562
# Perhaps it should be exposed somewhere...
563-
fail_depth = C_RECURSION_LIMIT * 2 + 1
564-
crash_depth = C_RECURSION_LIMIT * 100
565-
success_depth = int(C_RECURSION_LIMIT * 1.8)
563+
fail_depth = Py_C_RECURSION_LIMIT * 2 + 1
564+
crash_depth = Py_C_RECURSION_LIMIT * 100
565+
success_depth = int(Py_C_RECURSION_LIMIT * 1.8)
566566

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

Lib/test/test_dict.py

+2-2
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, C_RECURSION_LIMIT
11+
from test.support import import_helper, Py_C_RECURSION_LIMIT
1212

1313

1414
class DictTest(unittest.TestCase):
@@ -596,7 +596,7 @@ def __repr__(self):
596596

597597
def test_repr_deep(self):
598598
d = {}
599-
for i in range(C_RECURSION_LIMIT + 1):
599+
for i in range(Py_C_RECURSION_LIMIT + 1):
600600
d = {1: d}
601601
self.assertRaises(RecursionError, repr, d)
602602

Lib/test/test_dictviews.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pickle
44
import sys
55
import unittest
6-
from test.support import C_RECURSION_LIMIT
6+
from test.support import Py_C_RECURSION_LIMIT
77

88
class DictSetTest(unittest.TestCase):
99

@@ -280,7 +280,7 @@ def test_recursive_repr(self):
280280

281281
def test_deeply_nested_repr(self):
282282
d = {}
283-
for i in range(C_RECURSION_LIMIT//2 + 100):
283+
for i in range(Py_C_RECURSION_LIMIT//2 + 100):
284284
d = {42: d.values()}
285285
self.assertRaises(RecursionError, repr, d)
286286

Lib/test/test_exception_group.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import collections.abc
22
import types
33
import unittest
4-
from test.support import C_RECURSION_LIMIT
4+
from test.support import Py_C_RECURSION_LIMIT
55

66
class TestExceptionGroupTypeHierarchy(unittest.TestCase):
77
def test_exception_group_types(self):
@@ -460,7 +460,7 @@ def test_basics_split_by_predicate__match(self):
460460
class DeepRecursionInSplitAndSubgroup(unittest.TestCase):
461461
def make_deep_eg(self):
462462
e = TypeError(1)
463-
for i in range(C_RECURSION_LIMIT + 1):
463+
for i in range(Py_C_RECURSION_LIMIT + 1):
464464
e = ExceptionGroup('eg', [e])
465465
return e
466466

Parser/asdl_c.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,8 @@ class PartingShots(StaticVisitor):
14011401
if (!tstate) {
14021402
return 0;
14031403
}
1404-
state->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1405-
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
1404+
state->recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1405+
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
14061406
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
14071407
state->recursion_depth = starting_recursion_depth;
14081408

Python/Python-ast.c

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/ast.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,10 @@ _PyAST_Validate(mod_ty mod)
10461046
return 0;
10471047
}
10481048
/* Be careful here to prevent overflow. */
1049-
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
1049+
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
10501050
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
10511051
state.recursion_depth = starting_recursion_depth;
1052-
state.recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1052+
state.recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
10531053

10541054
switch (mod->kind) {
10551055
case Module_kind:

Python/ast_opt.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1130,10 +1130,10 @@ _PyAST_Optimize(mod_ty mod, PyArena *arena, int optimize, int ff_features)
11301130
return 0;
11311131
}
11321132
/* Be careful here to prevent overflow. */
1133-
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
1133+
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
11341134
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
11351135
state.recursion_depth = starting_recursion_depth;
1136-
state.recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
1136+
state.recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
11371137

11381138
int ret = astfold_mod(mod, arena, &state);
11391139
assert(ret || PyErr_Occurred());

Python/pystate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ init_threadstate(PyThreadState *tstate,
13021302

13031303
tstate->py_recursion_limit = interp->ceval.recursion_limit,
13041304
tstate->py_recursion_remaining = interp->ceval.recursion_limit,
1305-
tstate->c_recursion_remaining = C_RECURSION_LIMIT;
1305+
tstate->c_recursion_remaining = Py_C_RECURSION_LIMIT;
13061306

13071307
tstate->exc_info = &tstate->exc_state;
13081308

Python/symtable.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
312312
return NULL;
313313
}
314314
/* Be careful here to prevent overflow. */
315-
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
315+
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
316316
starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
317317
st->recursion_depth = starting_recursion_depth;
318-
st->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
318+
st->recursion_limit = Py_C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
319319

320320
/* Make the initial symbol information gathering pass */
321321
if (!symtable_enter_block(st, &_Py_ID(top), ModuleBlock, (void *)mod, 0, 0, 0, 0)) {

0 commit comments

Comments
 (0)