summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-11-04 23:51:22 (GMT)
committerGitHub <noreply@github.com>2019-11-04 23:51:22 (GMT)
commitbe434dc0380d9f5c7c800de9943cc46d55fd9491 (patch)
treebbf95dcf9ccc433e071cb4ce09984b5c5128f67e /Python/ceval.c
parentf4b1e3d7c64985f5d5b00f6cc9a1c146bbbfd613 (diff)
downloadcpython-be434dc0380d9f5c7c800de9943cc46d55fd9491.zip
cpython-be434dc0380d9f5c7c800de9943cc46d55fd9491.tar.gz
cpython-be434dc0380d9f5c7c800de9943cc46d55fd9491.tar.bz2
bpo-38644: Pass tstate to Py_EnterRecursiveCall() (GH-16997)
* Add _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() which require a tstate argument. * Pass tstate to _Py_MakeRecCheck() and _Py_CheckRecursiveCall(). * Convert Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() macros to static inline functions. _PyThreadState_GET() is the most efficient way to get the tstate, and so using it with _Py_EnterRecursiveCall() and _Py_LeaveRecursiveCall() should be a little bit more efficient than using Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() which use the "slower" PyThreadState_GET().
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 881a7dd..a01fa35 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -659,16 +659,15 @@ Py_SetRecursionLimit(int new_limit)
_Py_CheckRecursionLimit = ceval->recursion_limit;
}
-/* the macro Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
+/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
if the recursion_depth reaches _Py_CheckRecursionLimit.
If USE_STACKCHECK, the macro decrements _Py_CheckRecursionLimit
to guarantee that _Py_CheckRecursiveCall() is regularly called.
Without USE_STACKCHECK, there is no need for this. */
int
-_Py_CheckRecursiveCall(const char *where)
+_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
{
_PyRuntimeState *runtime = &_PyRuntime;
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
int recursion_limit = runtime->ceval.recursion_limit;
#ifdef USE_STACKCHECK
@@ -1073,8 +1072,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
/* Start of code */
/* push frame */
- if (Py_EnterRecursiveCall(""))
+ if (_Py_EnterRecursiveCall(tstate, "")) {
return NULL;
+ }
tstate->frame = f;
@@ -3810,7 +3810,7 @@ exit_yielding:
exit_eval_frame:
if (PyDTrace_FUNCTION_RETURN_ENABLED())
dtrace_function_return(f);
- Py_LeaveRecursiveCall();
+ _Py_LeaveRecursiveCall(tstate);
f->f_executing = 0;
tstate->frame = f->f_back;
@@ -5641,12 +5641,12 @@ maybe_dtrace_line(PyFrameObject *frame,
int Py_EnterRecursiveCall(const char *where)
{
- return _Py_EnterRecursiveCall_macro(where);
+ return _Py_EnterRecursiveCall_inline(where);
}
#undef Py_LeaveRecursiveCall
void Py_LeaveRecursiveCall(void)
{
- _Py_LeaveRecursiveCall_macro();
+ _Py_LeaveRecursiveCall_inline();
}