]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-128563: Simplify recursion check in `_PyEval_EvalFrameDefault` (GH-129481)
authorMark Shannon <mark@hotpy.org>
Fri, 31 Jan 2025 12:12:24 +0000 (12:12 +0000)
committerGitHub <noreply@github.com>
Fri, 31 Jan 2025 12:12:24 +0000 (12:12 +0000)
Simplify recursion check in _PyEval_EvalFrameDefault

Python/ceval.c

index 10c20faf852479bbf85cad83da38b07afe7408e9..e3b87441f8088d568e9bc96042d45b0d75595c5e 100644 (file)
@@ -786,7 +786,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
 
     _PyInterpreterFrame  entry_frame;
 
-
+    if (_Py_EnterRecursiveCallTstate(tstate, "")) {
+        assert(frame->owner != FRAME_OWNED_BY_INTERPRETER);
+        _PyEval_FrameClearAndPop(tstate, frame);
+        return NULL;
+    }
 
 #if defined(Py_DEBUG) && !defined(Py_STACKREF_DEBUG)
     /* Set these to invalid but identifiable values for debugging. */
@@ -811,11 +815,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
     tstate->current_frame = frame;
 
     tstate->c_recursion_remaining -= (PY_EVAL_C_STACK_UNITS - 1);
-    if (_Py_EnterRecursiveCallTstate(tstate, "")) {
-        tstate->c_recursion_remaining--;
-        tstate->py_recursion_remaining--;
-        goto exit_unwind;
-    }
 
     /* support for generator.throw() */
     if (throwflag) {