Skip to content

Commit

Permalink
Backport copying recursion limit from C to test.support
Browse files Browse the repository at this point in the history
Partially backport Python 3.13 changes that expose the C recursion
limit as _testcapi.Py_C_RECURSION_LIMIT and use them in test.support
rather than (incompletely) duplicating the values from header.  This
should fix test failures on platforms that were not correctly covered
in the Python code (e.g. SPARC).

The code is roughly based on parts of the following upstream commits:

45e09f9 pythonGH-112215: Increase C recursion limit for non debug builds (pythonGH-113397)
7e135a4 pythongh-111520: Integrate the Tier 2 interpreter in the Tier 1 interpreter (python#111428)
b0edf3b pythonGH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT (python#108507)
  • Loading branch information
mgorny committed Nov 25, 2024
1 parent ad3daea commit fd5c81d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2375,8 +2375,17 @@ def adjust_int_max_str_digits(max_digits):
finally:
sys.set_int_max_str_digits(current)

def _get_c_recursion_limit():
try:
import _testcapi
return _testcapi.Py_C_RECURSION_LIMIT
except ImportError:
return 8000

C_RECURSION_LIMIT = _get_c_recursion_limit()

#For recursion tests, easily exceeds default recursion limit
EXCEEDS_RECURSION_LIMIT = 5000
EXCEEDS_RECURSION_LIMIT = C_RECURSION_LIMIT * 3

# The default C recursion limit (from Include/cpython/pystate.h).
if Py_DEBUG:
Expand Down
2 changes: 2 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,8 @@ PyInit__testcapi(void)
PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);

PyModule_AddIntConstant(m, "the_number_three", 3);
#define Py_C_RECURSION_LIMIT C_RECURSION_LIMIT
PyModule_AddIntMacro(m, Py_C_RECURSION_LIMIT);

if (PyModule_AddIntMacro(m, Py_single_input)) {
return NULL;
Expand Down

0 comments on commit fd5c81d

Please sign in to comment.