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

@ -3,7 +3,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_context.h" // _PyContextTokenMissing_Type
#include "pycore_dict.h" // _PyObject_MakeDictFromInstanceAttributes()
#include "pycore_floatobject.h" // _PyFloat_DebugMallocStats()
@ -427,12 +427,12 @@ PyObject_Repr(PyObject *v)
/* It is possible for a type to have a tp_repr representation that loops
infinitely. */
if (_Py_EnterRecursiveCall(tstate,
" while getting the repr of an object")) {
if (_Py_EnterRecursiveCallTstate(tstate,
" while getting the repr of an object")) {
return NULL;
}
res = (*Py_TYPE(v)->tp_repr)(v);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
if (res == NULL) {
return NULL;
@ -487,11 +487,11 @@ PyObject_Str(PyObject *v)
/* It is possible for a type to have a tp_str representation that loops
infinitely. */
if (_Py_EnterRecursiveCall(tstate, " while getting the str of an object")) {
if (_Py_EnterRecursiveCallTstate(tstate, " while getting the str of an object")) {
return NULL;
}
res = (*Py_TYPE(v)->tp_str)(v);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
if (res == NULL) {
return NULL;
@ -724,11 +724,11 @@ PyObject_RichCompare(PyObject *v, PyObject *w, int op)
}
return NULL;
}
if (_Py_EnterRecursiveCall(tstate, " in comparison")) {
if (_Py_EnterRecursiveCallTstate(tstate, " in comparison")) {
return NULL;
}
PyObject *res = do_richcompare(tstate, v, w, op);
_Py_LeaveRecursiveCall(tstate);
_Py_LeaveRecursiveCallTstate(tstate);
return res;
}