Skip to content

Commit 19c3ac9

Browse files
authored
bpo-41834: Remove _Py_CheckRecursionLimit variable (GH-22359)
Remove the global _Py_CheckRecursionLimit variable: it has been replaced by ceval.recursion_limit of the PyInterpreterState structure. There is no need to keep the variable for the stable ABI, since Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() were not usable in Python 3.8 and older: these macros accessed PyThreadState members, whereas the PyThreadState structure is opaque in the limited C API.
1 parent ddc0dd0 commit 19c3ac9

File tree

7 files changed

+10
-18
lines changed

7 files changed

+10
-18
lines changed

Doc/whatsnew/3.10.rst

+4
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,7 @@ Removed
314314
* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or
315315
:c:func:`PyUnicode_AsWideCharString`
316316
(Contributed by Inada Naoki in :issue:`41103`.)
317+
318+
* Removed ``_Py_CheckRecursionLimit`` variable: it has been replaced by
319+
``ceval.recursion_limit`` of the :c:type:`PyInterpreterState` structure.
320+
(Contributed by Victor Stinner in :issue:`41834`.)

Include/internal/pycore_ceval.h

-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ extern void _PyEval_ReleaseLock(PyThreadState *tstate);
6363

6464
/* --- _Py_EnterRecursiveCall() ----------------------------------------- */
6565

66-
PyAPI_DATA(int) _Py_CheckRecursionLimit;
67-
6866
#ifdef USE_STACKCHECK
6967
/* With USE_STACKCHECK macro defined, trigger stack checks in
7068
_Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the ``_Py_CheckRecursionLimit`` variable: it has been replaced by
2+
``ceval.recursion_limit`` of the :c:type:`PyInterpreterState`
3+
structure. Patch by Victor Stinner.

PC/python3dll.c

-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ EXPORT_FUNC(PyWeakref_NewProxy)
663663
EXPORT_FUNC(PyWeakref_NewRef)
664664
EXPORT_FUNC(PyWrapper_New)
665665

666-
EXPORT_DATA(_Py_CheckRecursionLimit)
667666
EXPORT_DATA(_Py_EllipsisObject)
668667
EXPORT_DATA(_Py_FalseStruct)
669668
EXPORT_DATA(_Py_NoneStruct)

Python/ceval.c

+3-13
Original file line numberDiff line numberDiff line change
@@ -741,15 +741,12 @@ Py_MakePendingCalls(void)
741741
/* The interpreter's recursion limit */
742742

743743
#ifndef Py_DEFAULT_RECURSION_LIMIT
744-
#define Py_DEFAULT_RECURSION_LIMIT 1000
744+
# define Py_DEFAULT_RECURSION_LIMIT 1000
745745
#endif
746746

747-
int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
748-
749747
void
750748
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
751749
{
752-
_Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
753750
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
754751
_gil_initialize(&ceval->gil);
755752
#endif
@@ -797,14 +794,11 @@ Py_SetRecursionLimit(int new_limit)
797794
{
798795
PyThreadState *tstate = _PyThreadState_GET();
799796
tstate->interp->ceval.recursion_limit = new_limit;
800-
if (_Py_IsMainInterpreter(tstate)) {
801-
_Py_CheckRecursionLimit = new_limit;
802-
}
803797
}
804798

805799
/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
806-
if the recursion_depth reaches _Py_CheckRecursionLimit.
807-
If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
800+
if the recursion_depth reaches recursion_limit.
801+
If USE_STACKCHECK, the macro decrements recursion_limit
808802
to guarantee that _Py_CheckRecursiveCall() is regularly called.
809803
Without USE_STACKCHECK, there is no need for this. */
810804
int
@@ -819,10 +813,6 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
819813
_PyErr_SetString(tstate, PyExc_MemoryError, "Stack overflow");
820814
return -1;
821815
}
822-
if (_Py_IsMainInterpreter(tstate)) {
823-
/* Needed for ABI backwards-compatibility (see bpo-31857) */
824-
_Py_CheckRecursionLimit = recursion_limit;
825-
}
826816
#endif
827817
if (tstate->recursion_critical)
828818
/* Somebody asked that we don't check for recursion. */

Tools/c-analyzer/TODO

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Objects/tupleobject.c:_Py_tuple_zero_allocs Py_ssize_t _Py_
6666
Objects/typeobject.c:next_version_tag static unsigned int next_version_tag
6767
Python/Python-ast.c:init_types():initialized static int initialized
6868
Python/bootstrap_hash.c:urandom_cache static struct { int fd; dev_t st_dev; ino_t st_ino; } urandom_cache
69-
Python/ceval.c:_Py_CheckRecursionLimit int _Py_CheckRecursionLimit
7069
Python/ceval.c:lltrace static int lltrace
7170
Python/ceval.c:make_pending_calls():busy static int busy
7271
Python/dynload_shlib.c:handles static struct { dev_t dev; ino_t ino; void *handle; } handles[128]

Tools/c-analyzer/known.tsv

-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ Objects/iterobject.c - PyCallIter_Type variable PyTypeObject PyCallIter_Type
805805
Objects/capsule.c - PyCapsule_Type variable PyTypeObject PyCapsule_Type
806806
Objects/cellobject.c - PyCell_Type variable PyTypeObject PyCell_Type
807807
Objects/methodobject.c - PyCFunction_Type variable PyTypeObject PyCFunction_Type
808-
Python/ceval.c - _Py_CheckRecursionLimit variable int _Py_CheckRecursionLimit
809808
Objects/descrobject.c - PyClassMethodDescr_Type variable PyTypeObject PyClassMethodDescr_Type
810809
Objects/funcobject.c - PyClassMethod_Type variable PyTypeObject PyClassMethod_Type
811810
Objects/codeobject.c - PyCode_Type variable PyTypeObject PyCode_Type

0 commit comments

Comments
 (0)