diff options
author | Victor Stinner <vstinner@python.org> | 2022-05-04 11:30:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 11:30:23 (GMT) |
commit | d716a0dfe2d1029111db393afaecdb04cc4093de (patch) | |
tree | 2644817d65b365bf1dd2872661948d1b564bff32 /Include | |
parent | 14243369b5f80613628a565c224bba7fb3fcacd8 (diff) | |
download | cpython-d716a0dfe2d1029111db393afaecdb04cc4093de.zip cpython-d716a0dfe2d1029111db393afaecdb04cc4093de.tar.gz cpython-d716a0dfe2d1029111db393afaecdb04cc4093de.tar.bz2 |
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()
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_ceval.h | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 45d26a3..8dd89c6 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -91,7 +91,7 @@ extern void _PyEval_DeactivateOpCache(void); #ifdef USE_STACKCHECK /* With USE_STACKCHECK macro defined, trigger stack checks in - _Py_CheckRecursiveCall() on every 64th call to Py_EnterRecursiveCall. */ + _Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */ static inline int _Py_MakeRecCheck(PyThreadState *tstate) { return (tstate->recursion_remaining-- <= 0 || (tstate->recursion_remaining & 63) == 0); @@ -106,29 +106,25 @@ PyAPI_FUNC(int) _Py_CheckRecursiveCall( PyThreadState *tstate, const char *where); -static inline int _Py_EnterRecursiveCall(PyThreadState *tstate, - const char *where) { +static inline int _Py_EnterRecursiveCallTstate(PyThreadState *tstate, + const char *where) { return (_Py_MakeRecCheck(tstate) && _Py_CheckRecursiveCall(tstate, where)); } -static inline int _Py_EnterRecursiveCall_inline(const char *where) { +static inline int _Py_EnterRecursiveCall(const char *where) { PyThreadState *tstate = _PyThreadState_GET(); - return _Py_EnterRecursiveCall(tstate, where); + return _Py_EnterRecursiveCallTstate(tstate, where); } -#define Py_EnterRecursiveCall(where) _Py_EnterRecursiveCall_inline(where) - -static inline void _Py_LeaveRecursiveCall(PyThreadState *tstate) { +static inline void _Py_LeaveRecursiveCallTstate(PyThreadState *tstate) { tstate->recursion_remaining++; } -static inline void _Py_LeaveRecursiveCall_inline(void) { +static inline void _Py_LeaveRecursiveCall(void) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_LeaveRecursiveCall(tstate); + _Py_LeaveRecursiveCallTstate(tstate); } -#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() - extern struct _PyInterpreterFrame* _PyEval_GetFrame(void); extern PyObject* _Py_MakeCoro(PyFunctionObject *func); |