Use static inline function Py_EnterRecursiveCall() (#91988)

Currently, calling Py_EnterRecursiveCall() and
Py_LeaveRecursiveCall() may use a function call or a static inline
function call, depending if the internal pycore_ceval.h header file
is included or not. Use a different name for the static inline
function to ensure that the static inline function is always used in
Python internals for best performance. Similar approach than
PyThreadState_GET() (function call) and _PyThreadState_GET() (static
inline function).

* Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate()
* Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate()
* pycore_ceval.h: Rename Py_EnterRecursiveCall() to
  _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and
  _Py_LeaveRecursiveCall()
This commit is contained in:
Victor Stinner 2022-05-04 13:30:23 +02:00 committed by GitHub
parent 14243369b5
commit d716a0dfe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 524 additions and 521 deletions

View file

@ -880,7 +880,7 @@ Py_SetRecursionLimit(int new_limit)
}
}
/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
if the recursion_depth reaches recursion_limit. */
int
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
@ -1736,7 +1736,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
/* support for generator.throw() */
if (throwflag) {
if (_Py_EnterRecursiveCall(tstate, "")) {
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
tstate->recursion_remaining--;
goto exit_unwind;
}
@ -1776,7 +1776,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
start_frame:
if (_Py_EnterRecursiveCall(tstate, "")) {
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
tstate->recursion_remaining--;
goto exit_unwind;
}
@ -2492,7 +2492,7 @@ handle_eval_breaker:
_PyFrame_SetStackPointer(frame, stack_pointer);
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
if (!frame->is_entry) {
frame = cframe.current_frame = pop_frame(tstate, frame);
_PyFrame_StackPush(frame, retval);
@ -2704,7 +2704,7 @@ handle_eval_breaker:
_PyFrame_SetStackPointer(frame, stack_pointer);
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
/* Restore previous cframe and return. */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
@ -5066,12 +5066,12 @@ handle_eval_breaker:
PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
// This is slower but CPython promises to check all non-vectorcall
// function calls.
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
goto error;
}
PyObject *arg = TOP();
PyObject *res = cfunc(PyCFunction_GET_SELF(callable), arg);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
Py_DECREF(arg);
@ -5268,11 +5268,11 @@ handle_eval_breaker:
PyCFunction cfunc = meth->ml_meth;
// This is slower but CPython promises to check all non-vectorcall
// function calls.
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
goto error;
}
PyObject *res = cfunc(self, arg);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
Py_DECREF(self);
Py_DECREF(arg);
@ -5340,11 +5340,11 @@ handle_eval_breaker:
PyCFunction cfunc = meth->ml_meth;
// This is slower but CPython promises to check all non-vectorcall
// function calls.
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
goto error;
}
PyObject *res = cfunc(self, NULL);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
Py_DECREF(self);
STACK_SHRINK(oparg + 1);
@ -5484,7 +5484,7 @@ handle_eval_breaker:
assert(frame->frame_obj == NULL);
gen->gi_frame_state = FRAME_CREATED;
gen_frame->owner = FRAME_OWNED_BY_GENERATOR;
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
if (!frame->is_entry) {
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
@ -5850,7 +5850,7 @@ exception_unwind:
exit_unwind:
assert(_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
if (frame->is_entry) {
/* Restore previous cframe and exit */
tstate->cframe = cframe.previous;
@ -7955,12 +7955,12 @@ maybe_dtrace_line(_PyInterpreterFrame *frame,
int Py_EnterRecursiveCall(const char *where)
{
return _Py_EnterRecursiveCall_inline(where);
return _Py_EnterRecursiveCall(where);
}
#undef Py_LeaveRecursiveCall
void Py_LeaveRecursiveCall(void)
{
_Py_LeaveRecursiveCall_inline();
_Py_LeaveRecursiveCall();
}