From d716a0dfe2d1029111db393afaecdb04cc4093de Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 4 May 2022 13:30:23 +0200 Subject: 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() --- Parser/asdl_c.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Parser') diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 37925a5783..3bfe320fe3 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -490,11 +490,11 @@ class Obj2ModPrototypeVisitor(PickleVisitor): class Obj2ModVisitor(PickleVisitor): @contextmanager def recursive_call(self, node, level): - self.emit('if (Py_EnterRecursiveCall(" while traversing \'%s\' node")) {' % node, level, reflow=False) + self.emit('if (_Py_EnterRecursiveCall(" while traversing \'%s\' node")) {' % node, level, reflow=False) self.emit('goto failed;', level + 1) self.emit('}', level) yield - self.emit('Py_LeaveRecursiveCall();', level) + self.emit('_Py_LeaveRecursiveCall();', level) def funcHeader(self, name): ctype = get_c_type(name) @@ -1482,9 +1482,10 @@ def generate_module_def(mod, metadata, f, internal_h): print(textwrap.dedent(""" #include "Python.h" #include "pycore_ast.h" - #include "pycore_ast_state.h" // struct ast_state - #include "pycore_interp.h" // _PyInterpreterState.ast - #include "pycore_pystate.h" // _PyInterpreterState_GET() + #include "pycore_ast_state.h" // struct ast_state + #include "pycore_ceval.h" // _Py_EnterRecursiveCall + #include "pycore_interp.h" // _PyInterpreterState.ast + #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "structmember.h" #include -- cgit v1.2.1