mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-40513: Per-interpreter recursion_limit (GH-19929)
Move recursion_limit member from _PyRuntimeState.ceval to PyInterpreterState.ceval. * Py_SetRecursionLimit() now only sets _Py_CheckRecursionLimit of ceval.c if the current Python thread is part of the main interpreter. * Inline _Py_MakeEndRecCheck() into _Py_LeaveRecursiveCall(). * Convert _Py_RecursionLimitLowerWaterMark() macro into a static inline function.
This commit is contained in:
parent
627f701235
commit
4e30ed3af0
4 changed files with 28 additions and 22 deletions
|
@ -699,7 +699,6 @@ int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
|
|||
void
|
||||
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
|
||||
{
|
||||
ceval->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
|
||||
_Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
|
||||
_gil_initialize(&ceval->gil);
|
||||
}
|
||||
|
@ -707,6 +706,8 @@ _PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
|
|||
int
|
||||
_PyEval_InitState(struct _ceval_state *ceval)
|
||||
{
|
||||
ceval->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
|
||||
|
||||
struct _pending_calls *pending = &ceval->pending;
|
||||
assert(pending->lock == NULL);
|
||||
|
||||
|
@ -730,16 +731,18 @@ _PyEval_FiniState(struct _ceval_state *ceval)
|
|||
int
|
||||
Py_GetRecursionLimit(void)
|
||||
{
|
||||
struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
|
||||
return ceval->recursion_limit;
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
return tstate->interp->ceval.recursion_limit;
|
||||
}
|
||||
|
||||
void
|
||||
Py_SetRecursionLimit(int new_limit)
|
||||
{
|
||||
struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
|
||||
ceval->recursion_limit = new_limit;
|
||||
_Py_CheckRecursionLimit = new_limit;
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
tstate->interp->ceval.recursion_limit = new_limit;
|
||||
if (_Py_IsMainInterpreter(tstate)) {
|
||||
_Py_CheckRecursionLimit = new_limit;
|
||||
}
|
||||
}
|
||||
|
||||
/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
|
||||
|
@ -750,8 +753,7 @@ Py_SetRecursionLimit(int new_limit)
|
|||
int
|
||||
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
|
||||
{
|
||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||
int recursion_limit = runtime->ceval.recursion_limit;
|
||||
int recursion_limit = tstate->interp->ceval.recursion_limit;
|
||||
|
||||
#ifdef USE_STACKCHECK
|
||||
tstate->stackcheck_counter = 0;
|
||||
|
@ -760,8 +762,10 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
|
|||
_PyErr_SetString(tstate, PyExc_MemoryError, "Stack overflow");
|
||||
return -1;
|
||||
}
|
||||
/* Needed for ABI backwards-compatibility (see bpo-31857) */
|
||||
_Py_CheckRecursionLimit = recursion_limit;
|
||||
if (_Py_IsMainInterpreter(tstate)) {
|
||||
/* Needed for ABI backwards-compatibility (see bpo-31857) */
|
||||
_Py_CheckRecursionLimit = recursion_limit;
|
||||
}
|
||||
#endif
|
||||
if (tstate->recursion_critical)
|
||||
/* Somebody asked that we don't check for recursion. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue