]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133079: Remove Py_C_RECURSION_LIMIT & PyThreadState.c_recursion_remaining (GH...
authorPetr Viktorin <encukou@gmail.com>
Tue, 29 Apr 2025 10:56:20 +0000 (12:56 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Apr 2025 10:56:20 +0000 (12:56 +0200)
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: https://github.com/python/steering-council/issues/288

Doc/whatsnew/3.14.rst
Include/cpython/pystate.h
Misc/NEWS.d/next/C_API/2025-04-28-13-27-48.gh-issue-133079.DJL2sK.rst [new file with mode: 0644]
Python/pystate.c
Python/vm-state.md

index 9b28d7b6247309cb137d47573d58551521d0522c..646a0b4007fc05a1e2470c5a33a2d77a0b724169 100644 (file)
@@ -2280,3 +2280,10 @@ Removed
 * Remove the private ``_Py_InitializeMain()`` function. It was a
   :term:`provisional API` added to Python 3.8 by :pep:`587`.
   (Contributed by Victor Stinner in :gh:`129033`.)
+
+* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
+  :c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
+  without a deprecation period.
+  Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
+  in C code.
+  (Removed in :gh:`133079`, see also :gh:`130396`.)
index 97f11fff244a8ba1ba52aa9cd6c972592ee60e3b..97c097aa01c5084f3aeb9f375c21ff50c0e7d0d5 100644 (file)
@@ -118,8 +118,6 @@ struct _ts {
 
     int py_recursion_remaining;
     int py_recursion_limit;
-
-    int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */
     int recursion_headroom; /* Allow 50 more calls to handle any errors. */
 
     /* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -210,8 +208,6 @@ struct _ts {
     _PyRemoteDebuggerSupport remote_debugger_support;
 };
 
-# define Py_C_RECURSION_LIMIT 5000
-
 /* other API */
 
 /* Similar to PyThreadState_Get(), but don't issue a fatal error
diff --git a/Misc/NEWS.d/next/C_API/2025-04-28-13-27-48.gh-issue-133079.DJL2sK.rst b/Misc/NEWS.d/next/C_API/2025-04-28-13-27-48.gh-issue-133079.DJL2sK.rst
new file mode 100644 (file)
index 0000000..4363245
--- /dev/null
@@ -0,0 +1,3 @@
+The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
+:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
+without a deprecation period.
index ec19e3ae6a415a450e7782bcaa0203a91a1abc96..8c0bab3f2b48f8bce5f912afb92ac4d595ac6a26 100644 (file)
@@ -1559,7 +1559,6 @@ init_threadstate(_PyThreadStateImpl *_tstate,
 
     tstate->py_recursion_limit = interp->ceval.recursion_limit;
     tstate->py_recursion_remaining = interp->ceval.recursion_limit;
-    tstate->c_recursion_remaining = 2;
     tstate->exc_info = &tstate->exc_state;
 
     // PyGILState_Release must not try to delete this thread state.
index b3246557dbeea3dfcf787e89381d6721fcbe5368..83b6a577f29e955c9df415ccb8d43907e30550b2 100644 (file)
@@ -73,7 +73,8 @@ It will be more complex in the JIT.
 
 Another important piece of VM state is the **thread state**, held in `tstate`.
 The current frame pointer, `frame`, is always equal to `tstate->current_frame`.
-The thread state also holds the exception state (`tstate->exc_info`) and the recursion counters (`tstate->c_recursion_remaining` and `tstate->py_recursion_remaining`).
+The thread state also holds the exception state (`tstate->exc_info`) and
+recursion tracking data (`tstate->py_recursion_remaining`, `tstate->c_stack*`).
 
 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`).
 The interpreter state also holds the optimizer state (`optimizer` and some counters).