mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-38644: Pass tstate to Py_EnterRecursiveCall() (GH-16997)
* Add _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() which require a tstate argument. * Pass tstate to _Py_MakeRecCheck() and _Py_CheckRecursiveCall(). * Convert Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() macros to static inline functions. _PyThreadState_GET() is the most efficient way to get the tstate, and so using it with _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() should be a little bit more efficient than using Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() which use the "slower" PyThreadState_GET().
This commit is contained in:
parent
f4b1e3d7c6
commit
be434dc038
7 changed files with 201 additions and 136 deletions
|
@ -659,16 +659,15 @@ Py_SetRecursionLimit(int new_limit)
|
|||
_Py_CheckRecursionLimit = ceval->recursion_limit;
|
||||
}
|
||||
|
||||
/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
|
||||
/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
|
||||
if the recursion_depth reaches _Py_CheckRecursionLimit.
|
||||
If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
|
||||
to guarantee that _Py_CheckRecursiveCall() is regularly called.
|
||||
Without USE_STACKCHECK, there is no need for this. */
|
||||
int
|
||||
_Py_CheckRecursiveCall(const char *where)
|
||||
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
|
||||
{
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
||||
int recursion_limit = runtime->ceval.recursion_limit;
|
||||
|
||||
#ifdef USE_STACKCHECK
|
||||
|
@ -1073,8 +1072,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
|||
/* Start of code */
|
||||
|
||||
/* push frame */
|
||||
if (Py_EnterRecursiveCall(""))
|
||||
if (_Py_EnterRecursiveCall(tstate, "")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tstate->frame = f;
|
||||
|
||||
|
@ -3810,7 +3810,7 @@ exit_yielding:
|
|||
exit_eval_frame:
|
||||
if (PyDTrace_FUNCTION_RETURN_ENABLED())
|
||||
dtrace_function_return(f);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
f->f_executing = 0;
|
||||
tstate->frame = f->f_back;
|
||||
|
||||
|
@ -5641,12 +5641,12 @@ maybe_dtrace_line(PyFrameObject *frame,
|
|||
|
||||
int Py_EnterRecursiveCall(const char *where)
|
||||
{
|
||||
return _Py_EnterRecursiveCall_macro(where);
|
||||
return _Py_EnterRecursiveCall_inline(where);
|
||||
}
|
||||
|
||||
#undef Py_LeaveRecursiveCall
|
||||
|
||||
void Py_LeaveRecursiveCall(void)
|
||||
{
|
||||
_Py_LeaveRecursiveCall_macro();
|
||||
_Py_LeaveRecursiveCall_inline();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue