mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
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:
parent
14243369b5
commit
d716a0dfe2
15 changed files with 524 additions and 521 deletions
|
@ -112,6 +112,7 @@ bytes(cdata)
|
|||
#endif
|
||||
|
||||
#include "pycore_call.h" // _PyObject_CallNoArgs()
|
||||
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
|
||||
#include "structmember.h" // PyMemberDef
|
||||
|
||||
#include <ffi.h>
|
||||
|
@ -2270,12 +2271,12 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
|
|||
return NULL;
|
||||
}
|
||||
if (as_parameter) {
|
||||
if (Py_EnterRecursiveCall("while processing _as_parameter_")) {
|
||||
if (_Py_EnterRecursiveCall("while processing _as_parameter_")) {
|
||||
Py_DECREF(as_parameter);
|
||||
return NULL;
|
||||
}
|
||||
value = PyCSimpleType_from_param(type, as_parameter);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
Py_DECREF(as_parameter);
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define NEEDS_PY_IDENTIFIER
|
||||
|
||||
#include "Python.h"
|
||||
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
|
||||
#include "structmember.h" // PyMemberDef
|
||||
#include "pycore_accu.h"
|
||||
|
||||
|
@ -1059,19 +1060,19 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
|
|||
return scanstring_unicode(pystr, idx + 1, s->strict, next_idx_ptr);
|
||||
case '{':
|
||||
/* object */
|
||||
if (Py_EnterRecursiveCall(" while decoding a JSON object "
|
||||
"from a unicode string"))
|
||||
if (_Py_EnterRecursiveCall(" while decoding a JSON object "
|
||||
"from a unicode string"))
|
||||
return NULL;
|
||||
res = _parse_object_unicode(s, pystr, idx + 1, next_idx_ptr);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
return res;
|
||||
case '[':
|
||||
/* array */
|
||||
if (Py_EnterRecursiveCall(" while decoding a JSON array "
|
||||
"from a unicode string"))
|
||||
if (_Py_EnterRecursiveCall(" while decoding a JSON array "
|
||||
"from a unicode string"))
|
||||
return NULL;
|
||||
res = _parse_array_unicode(s, pystr, idx + 1, next_idx_ptr);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
return res;
|
||||
case 'n':
|
||||
/* null */
|
||||
|
@ -1430,17 +1431,17 @@ encoder_listencode_obj(PyEncoderObject *s, _PyAccu *acc,
|
|||
return _steal_accumulate(acc, encoded);
|
||||
}
|
||||
else if (PyList_Check(obj) || PyTuple_Check(obj)) {
|
||||
if (Py_EnterRecursiveCall(" while encoding a JSON object"))
|
||||
if (_Py_EnterRecursiveCall(" while encoding a JSON object"))
|
||||
return -1;
|
||||
rv = encoder_listencode_list(s, acc, obj, indent_level);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
return rv;
|
||||
}
|
||||
else if (PyDict_Check(obj)) {
|
||||
if (Py_EnterRecursiveCall(" while encoding a JSON object"))
|
||||
if (_Py_EnterRecursiveCall(" while encoding a JSON object"))
|
||||
return -1;
|
||||
rv = encoder_listencode_dict(s, acc, obj, indent_level);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
|
@ -1468,13 +1469,13 @@ encoder_listencode_obj(PyEncoderObject *s, _PyAccu *acc,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (Py_EnterRecursiveCall(" while encoding a JSON object")) {
|
||||
if (_Py_EnterRecursiveCall(" while encoding a JSON object")) {
|
||||
Py_DECREF(newobj);
|
||||
Py_XDECREF(ident);
|
||||
return -1;
|
||||
}
|
||||
rv = encoder_listencode_obj(s, acc, newobj, indent_level);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
|
||||
Py_DECREF(newobj);
|
||||
if (rv) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue