@@ -148,17 +148,26 @@ _PyFrame_NumSlotsForCodeObject(PyCodeObject *code)
148148149149staticinlinevoid_PyFrame_Copy(_PyInterpreterFrame*src, _PyInterpreterFrame*dest)
150150{
151-*dest=*src;
151+dest->f_executable=PyStackRef_MakeHeapSafe(src->f_executable);
152+// Don't leave a dangling pointer to the old frame when creating generators
153+// and coroutines:
154+dest->previous=NULL;
155+dest->f_funcobj=PyStackRef_MakeHeapSafe(src->f_funcobj);
156+dest->f_globals=src->f_globals;
157+dest->f_builtins=src->f_builtins;
158+dest->f_locals=src->f_locals;
159+dest->frame_obj=src->frame_obj;
160+dest->instr_ptr=src->instr_ptr;
161+#ifdefPy_GIL_DISABLED
162+dest->tlbc_index=src->tlbc_index;
163+#endif
152164assert(src->stackpointer!=NULL);
153165intstacktop= (int)(src->stackpointer-src->localsplus);
154-assert(stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus);
166+assert(stacktop >= 0);
155167dest->stackpointer=dest->localsplus+stacktop;
156-for (inti=1; i<stacktop; i++) {
157-dest->localsplus[i] =src->localsplus[i];
168+for (inti=0; i<stacktop; i++) {
169+dest->localsplus[i] =PyStackRef_MakeHeapSafe(src->localsplus[i]);
158170 }
159-// Don't leave a dangling pointer to the old frame when creating generators
160-// and coroutines:
161-dest->previous=NULL;
162171}
163172164173#ifdefPy_GIL_DISABLED
@@ -393,7 +402,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
393402394403PyAPI_FUNC(_PyInterpreterFrame*)
395404_PyEvalFramePushAndInit(PyThreadState*tstate, _PyStackReffunc,
396-PyObject*locals, _PyStackRefconst*args,
405+PyObject*locals, _PyStackRefconst*args,
397406size_targcount, PyObject*kwnames,
398407_PyInterpreterFrame*previous);
399408