@@ -3931,7 +3931,7 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
39313931 /* Create the frame */
39323932 tstate = PyThreadState_GET ();
39333933 assert (tstate != NULL );
3934- f = PyFrame_New (tstate , co , globals , locals );
3934+ f = _PyFrame_New_NoTrack (tstate , co , globals , locals );
39353935 if (f == NULL ) {
39363936 return NULL ;
39373937 }
@@ -4176,9 +4176,15 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
41764176 so recursion_depth must be boosted for the duration.
41774177 */
41784178 assert (tstate != NULL );
4179- ++ tstate -> recursion_depth ;
4180- Py_DECREF (f );
4181- -- tstate -> recursion_depth ;
4179+ if (Py_REFCNT (f ) > 1 ) {
4180+ Py_DECREF (f );
4181+ _PyObject_GC_TRACK (f );
4182+ }
4183+ else {
4184+ ++ tstate -> recursion_depth ;
4185+ Py_DECREF (f );
4186+ -- tstate -> recursion_depth ;
4187+ }
41824188 return retval ;
41834189}
41844190
@@ -4904,11 +4910,11 @@ _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
49044910
49054911 assert (globals != NULL );
49064912 /* XXX Perhaps we should create a specialized
4907- PyFrame_New () that doesn't take locals, but does
4913+ _PyFrame_New_NoTrack () that doesn't take locals, but does
49084914 take builtins without sanity checking them.
49094915 */
49104916 assert (tstate != NULL );
4911- f = PyFrame_New (tstate , co , globals , NULL );
4917+ f = _PyFrame_New_NoTrack (tstate , co , globals , NULL );
49124918 if (f == NULL ) {
49134919 return NULL ;
49144920 }
@@ -4921,10 +4927,15 @@ _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
49214927 }
49224928 result = PyEval_EvalFrameEx (f ,0 );
49234929
4924- ++ tstate -> recursion_depth ;
4925- Py_DECREF (f );
4926- -- tstate -> recursion_depth ;
4927-
4930+ if (Py_REFCNT (f ) > 1 ) {
4931+ Py_DECREF (f );
4932+ _PyObject_GC_TRACK (f );
4933+ }
4934+ else {
4935+ ++ tstate -> recursion_depth ;
4936+ Py_DECREF (f );
4937+ -- tstate -> recursion_depth ;
4938+ }
49284939 return result ;
49294940}
49304941
0 commit comments