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

@ -9,6 +9,7 @@
#endif
#include "Python.h"
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_pystate.h" // _PyThreadState_GET()
@ -3068,21 +3069,21 @@ save_list(PicklerObject *self, PyObject *obj)
if (len != 0) {
/* Materialize the list elements. */
if (PyList_CheckExact(obj) && self->proto > 0) {
if (Py_EnterRecursiveCall(" while pickling an object"))
if (_Py_EnterRecursiveCall(" while pickling an object"))
goto error;
status = batch_list_exact(self, obj);
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
} else {
PyObject *iter = PyObject_GetIter(obj);
if (iter == NULL)
goto error;
if (Py_EnterRecursiveCall(" while pickling an object")) {
if (_Py_EnterRecursiveCall(" while pickling an object")) {
Py_DECREF(iter);
goto error;
}
status = batch_list(self, iter);
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
Py_DECREF(iter);
}
}
@ -3327,10 +3328,10 @@ save_dict(PicklerObject *self, PyObject *obj)
if (PyDict_CheckExact(obj) && self->proto > 0) {
/* We can take certain shortcuts if we know this is a dict and
not a dict subclass. */
if (Py_EnterRecursiveCall(" while pickling an object"))
if (_Py_EnterRecursiveCall(" while pickling an object"))
goto error;
status = batch_dict_exact(self, obj);
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
} else {
items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items));
if (items == NULL)
@ -3339,12 +3340,12 @@ save_dict(PicklerObject *self, PyObject *obj)
Py_DECREF(items);
if (iter == NULL)
goto error;
if (Py_EnterRecursiveCall(" while pickling an object")) {
if (_Py_EnterRecursiveCall(" while pickling an object")) {
Py_DECREF(iter);
goto error;
}
status = batch_dict(self, iter);
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
Py_DECREF(iter);
}
}
@ -4300,9 +4301,9 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
return save_unicode(self, obj);
}
/* We're only calling Py_EnterRecursiveCall here so that atomic
/* We're only calling _Py_EnterRecursiveCall here so that atomic
types above are pickled faster. */
if (Py_EnterRecursiveCall(" while pickling an object")) {
if (_Py_EnterRecursiveCall(" while pickling an object")) {
return -1;
}
@ -4460,7 +4461,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
}
done:
Py_LeaveRecursiveCall();
_Py_LeaveRecursiveCall();
Py_XDECREF(reduce_func);
Py_XDECREF(reduce_value);