mirror of
https://github.com/python/cpython.git
synced 2025-07-16 15:55:18 +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
831
Python/Python-ast.c
generated
831
Python/Python-ast.c
generated
File diff suppressed because it is too large
Load diff
|
@ -880,7 +880,7 @@ Py_SetRecursionLimit(int new_limit)
|
|||
}
|
||||
}
|
||||
|
||||
/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
|
||||
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
|
||||
if the recursion_depth reaches recursion_limit. */
|
||||
int
|
||||
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
|
||||
|
@ -1736,7 +1736,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
|
|||
|
||||
/* support for generator.throw() */
|
||||
if (throwflag) {
|
||||
if (_Py_EnterRecursiveCall(tstate, "")) {
|
||||
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
|
||||
tstate->recursion_remaining--;
|
||||
goto exit_unwind;
|
||||
}
|
||||
|
@ -1776,7 +1776,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
|
|||
|
||||
|
||||
start_frame:
|
||||
if (_Py_EnterRecursiveCall(tstate, "")) {
|
||||
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
|
||||
tstate->recursion_remaining--;
|
||||
goto exit_unwind;
|
||||
}
|
||||
|
@ -2492,7 +2492,7 @@ handle_eval_breaker:
|
|||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
TRACE_FUNCTION_EXIT();
|
||||
DTRACE_FUNCTION_EXIT();
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
if (!frame->is_entry) {
|
||||
frame = cframe.current_frame = pop_frame(tstate, frame);
|
||||
_PyFrame_StackPush(frame, retval);
|
||||
|
@ -2704,7 +2704,7 @@ handle_eval_breaker:
|
|||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
TRACE_FUNCTION_EXIT();
|
||||
DTRACE_FUNCTION_EXIT();
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
/* Restore previous cframe and return. */
|
||||
tstate->cframe = cframe.previous;
|
||||
tstate->cframe->use_tracing = cframe.use_tracing;
|
||||
|
@ -5066,12 +5066,12 @@ handle_eval_breaker:
|
|||
PyCFunction cfunc = PyCFunction_GET_FUNCTION(callable);
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
|
||||
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
|
||||
goto error;
|
||||
}
|
||||
PyObject *arg = TOP();
|
||||
PyObject *res = cfunc(PyCFunction_GET_SELF(callable), arg);
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
|
||||
Py_DECREF(arg);
|
||||
|
@ -5268,11 +5268,11 @@ handle_eval_breaker:
|
|||
PyCFunction cfunc = meth->ml_meth;
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
|
||||
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
|
||||
goto error;
|
||||
}
|
||||
PyObject *res = cfunc(self, arg);
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
Py_DECREF(self);
|
||||
Py_DECREF(arg);
|
||||
|
@ -5340,11 +5340,11 @@ handle_eval_breaker:
|
|||
PyCFunction cfunc = meth->ml_meth;
|
||||
// This is slower but CPython promises to check all non-vectorcall
|
||||
// function calls.
|
||||
if (_Py_EnterRecursiveCall(tstate, " while calling a Python object")) {
|
||||
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object")) {
|
||||
goto error;
|
||||
}
|
||||
PyObject *res = cfunc(self, NULL);
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
|
||||
Py_DECREF(self);
|
||||
STACK_SHRINK(oparg + 1);
|
||||
|
@ -5484,7 +5484,7 @@ handle_eval_breaker:
|
|||
assert(frame->frame_obj == NULL);
|
||||
gen->gi_frame_state = FRAME_CREATED;
|
||||
gen_frame->owner = FRAME_OWNED_BY_GENERATOR;
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
if (!frame->is_entry) {
|
||||
_PyInterpreterFrame *prev = frame->previous;
|
||||
_PyThreadState_PopFrame(tstate, frame);
|
||||
|
@ -5850,7 +5850,7 @@ exception_unwind:
|
|||
|
||||
exit_unwind:
|
||||
assert(_PyErr_Occurred(tstate));
|
||||
_Py_LeaveRecursiveCall(tstate);
|
||||
_Py_LeaveRecursiveCallTstate(tstate);
|
||||
if (frame->is_entry) {
|
||||
/* Restore previous cframe and exit */
|
||||
tstate->cframe = cframe.previous;
|
||||
|
@ -7955,12 +7955,12 @@ maybe_dtrace_line(_PyInterpreterFrame *frame,
|
|||
|
||||
int Py_EnterRecursiveCall(const char *where)
|
||||
{
|
||||
return _Py_EnterRecursiveCall_inline(where);
|
||||
return _Py_EnterRecursiveCall(where);
|
||||
}
|
||||
|
||||
#undef Py_LeaveRecursiveCall
|
||||
|
||||
void Py_LeaveRecursiveCall(void)
|
||||
{
|
||||
_Py_LeaveRecursiveCall_inline();
|
||||
_Py_LeaveRecursiveCall();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "Python.h"
|
||||
|
||||
#include "pycore_ast.h" // PyAST_mod2obj
|
||||
#include "pycore_ceval.h" // _Py_EnterRecursiveCall
|
||||
#include "pycore_compile.h" // _PyAST_Compile()
|
||||
#include "pycore_interp.h" // PyInterpreterState.importlib
|
||||
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
|
||||
|
@ -1268,13 +1269,13 @@ print_chained(struct exception_print_context* ctx, PyObject *value,
|
|||
{
|
||||
PyObject *f = ctx->file;
|
||||
|
||||
if (Py_EnterRecursiveCall(" in print_chained") < 0) {
|
||||
if (_Py_EnterRecursiveCall(" in print_chained") < 0) {
|
||||
return -1;
|
||||
}
|
||||
bool need_close = ctx->need_close;
|
||||
int res = print_exception_recursive(ctx, value);
|
||||
ctx->need_close = need_close;
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
if (res < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1445,11 +1446,11 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value)
|
|||
PyObject *exc = PyTuple_GET_ITEM(excs, i);
|
||||
|
||||
if (!truncated) {
|
||||
if (Py_EnterRecursiveCall(" in print_exception_group") != 0) {
|
||||
if (_Py_EnterRecursiveCall(" in print_exception_group") != 0) {
|
||||
return -1;
|
||||
}
|
||||
int res = print_exception_recursive(ctx, exc);
|
||||
Py_LeaveRecursiveCall();
|
||||
_Py_LeaveRecursiveCall();
|
||||
if (res < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue