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

@ -1,7 +1,7 @@
/* Descriptors -- a new, flexible way to describe attributes */
#include "Python.h"
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
@ -302,7 +302,7 @@ typedef void (*funcptr)(void);
static inline funcptr
method_enter_call(PyThreadState *tstate, PyObject *func)
{
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
return NULL;
}
return (funcptr)((PyMethodDescrObject *)func)->d_method->ml_meth;
@ -330,7 +330,7 @@ method_vectorcall_VARARGS(
PyObject *result = _PyCFunction_TrampolineCall(
meth, args[0], argstuple);
Py_DECREF(argstuple);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@ -363,7 +363,7 @@ method_vectorcall_VARARGS_KEYWORDS(
}
result = _PyCFunctionWithKeywords_TrampolineCall(
meth, args[0], argstuple, kwdict);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
exit:
Py_DECREF(argstuple);
Py_XDECREF(kwdict);
@ -386,7 +386,7 @@ method_vectorcall_FASTCALL_KEYWORDS_METHOD(
PyObject *result = meth(args[0],
((PyMethodDescrObject *)func)->d_common.d_type,
args+1, nargs-1, kwnames);
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
return result;
}
@ -405,7 +405,7 @@ method_vectorcall_FASTCALL(
return NULL;
}
PyObject *result = meth(args[0], args+1, nargs-1);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@ -424,7 +424,7 @@ method_vectorcall_FASTCALL_KEYWORDS(
return NULL;
}
PyObject *result = meth(args[0], args+1, nargs-1, kwnames);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@ -451,7 +451,7 @@ method_vectorcall_NOARGS(
return NULL;
}
PyObject *result = _PyCFunction_TrampolineCall(meth, args[0], NULL);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@ -479,7 +479,7 @@ method_vectorcall_O(
return NULL;
}
PyObject *result = _PyCFunction_TrampolineCall(meth, args[0], args[1]);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}