Skip to content

Commit 4e1690b

Browse files
committed
gh-133079: Remove Py_C_RECURSION_LIMIT & PyThreadState.c_recursion_remaining
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).
1 parent 4e04511 commit 4e1690b

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,3 +2256,10 @@ Removed
22562256
* Remove the private ``_Py_InitializeMain()`` function. It was a
22572257
:term:`provisional API` added to Python 3.8 by :pep:`587`.
22582258
(Contributed by Victor Stinner in :gh:`129033`.)
2259+
2260+
* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2261+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
2262+
without a deprecation period.
2263+
Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
2264+
in C code.
2265+
(Removed in :gh:`133079`, see also :gh:`130396`.)

Include/cpython/pystate.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ struct _ts {
120120

121121
int py_recursion_remaining;
122122
int py_recursion_limit;
123-
124-
int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */
125123
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
126124

127125
/* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -212,8 +210,6 @@ struct _ts {
212210
_PyRemoteDebuggerSupport remote_debugger_support;
213211
};
214212

215-
# define Py_C_RECURSION_LIMIT 5000
216-
217213
/* other API */
218214

219215
/* Similar to PyThreadState_Get(), but don't issue a fatal error
Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,6 @@ init_threadstate(_PyThreadStateImpl *_tstate,
15331533

15341534
tstate->py_recursion_limit = interp->ceval.recursion_limit;
15351535
tstate->py_recursion_remaining = interp->ceval.recursion_limit;
1536-
tstate->c_recursion_remaining = 2;
15371536
tstate->exc_info = &tstate->exc_state;
15381537

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

Python/vm-state.md

Lines changed: 2 additions & 1 deletion
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)