Skip to content

Commit 0c26dbd

Browse files
authored
gh-133079: Remove Py_C_RECURSION_LIMIT & PyThreadState.c_recursion_remaining (GH-133080)
Both were added in 3.13, are undocumented, and don't make sense in 3.14 due to changes in the stack overflow detection machinery (gh-112282). PEP 387 exception for skipping a deprecation period: python/steering-council#288
1 parent 208d06f commit 0c26dbd

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

Doc/whatsnew/3.14.rst

+7
Original file line numberDiff line numberDiff line change
@@ -2280,3 +2280,10 @@ Removed
22802280
* Remove the private ``_Py_InitializeMain()`` function. It was a
22812281
:term:`provisional API` added to Python 3.8 by :pep:`587`.
22822282
(Contributed by Victor Stinner in :gh:`129033`.)
2283+
2284+
* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2285+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
2286+
without a deprecation period.
2287+
Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
2288+
in C code.
2289+
(Removed in :gh:`133079`, see also :gh:`130396`.)

Include/cpython/pystate.h

-4
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ struct _ts {
118118

119119
int py_recursion_remaining;
120120
int py_recursion_limit;
121-
122-
int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */
123121
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
124122

125123
/* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -210,8 +208,6 @@ struct _ts {
210208
_PyRemoteDebuggerSupport remote_debugger_support;
211209
};
212210

213-
# define Py_C_RECURSION_LIMIT 5000
214-
215211
/* other API */
216212

217213
/* Similar to PyThreadState_Get(), but don't issue a fatal error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
3+
without a deprecation period.

Python/pystate.c

-1
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,6 @@ init_threadstate(_PyThreadStateImpl *_tstate,
15591559

15601560
tstate->py_recursion_limit = interp->ceval.recursion_limit;
15611561
tstate->py_recursion_remaining = interp->ceval.recursion_limit;
1562-
tstate->c_recursion_remaining = 2;
15631562
tstate->exc_info = &tstate->exc_state;
15641563

15651564
// PyGILState_Release must not try to delete this thread state.

Python/vm-state.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ It will be more complex in the JIT.
7373

7474
Another important piece of VM state is the **thread state**, held in `tstate`.
7575
The current frame pointer, `frame`, is always equal to `tstate->current_frame`.
76-
The thread state also holds the exception state (`tstate->exc_info`) and the recursion counters (`tstate->c_recursion_remaining` and `tstate->py_recursion_remaining`).
76+
The thread state also holds the exception state (`tstate->exc_info`) and
77+
recursion tracking data (`tstate->py_recursion_remaining`, `tstate->c_stack*`).
7778

7879
The thread state is also used to access the **interpreter state** (`tstate->interp`), which is important since the "eval breaker" flags are stored there (`tstate->interp->ceval.eval_breaker`, an "atomic" variable), as well as the "PEP 523 function" (`tstate->interp->eval_frame`).
7980
The interpreter state also holds the optimizer state (`optimizer` and some counters).

0 commit comments

Comments
 (0)