Skip to content

Commit 89f9496

Browse files
committed
Tidy up frame creation a bit.
1 parent 6cab045 commit 89f9496

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Objects/frameobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,6 @@ frame_alloc(PyCodeObject *code, PyObject **localsarray)
846846
}
847847
f->f_localsptr = localsarray;
848848
f->f_own_locals_memory = owns;
849-
f->f_valuestack = f->f_localsptr + code->co_nlocalsplus + FRAME_SPECIALS_SIZE;
850849
return f;
851850
}
852851

@@ -883,18 +882,20 @@ _PyFrame_New_NoTrack(PyThreadState *tstate, PyFrameConstructor *con, PyObject *l
883882
assert(con->fc_builtins != NULL);
884883
assert(con->fc_code != NULL);
885884
assert(locals == NULL || PyMapping_Check(locals));
885+
PyCodeObject *code = (PyCodeObject *)con->fc_code;
886886

887-
PyFrameObject *f = frame_alloc((PyCodeObject *)con->fc_code, localsarray);
887+
PyFrameObject *f = frame_alloc(code, localsarray);
888888
if (f == NULL) {
889889
return NULL;
890890
}
891891

892+
PyObject **specials = f->f_localsptr + code->co_nlocalsplus;
893+
f->f_valuestack = specials + FRAME_SPECIALS_SIZE;
892894
f->f_back = (PyFrameObject*)Py_XNewRef(tstate->frame);
893895
f->f_code = (PyCodeObject *)Py_NewRef(con->fc_code);
894-
_PyFrame_Specials(f)[FRAME_SPECIALS_BUILTINS_OFFSET] = Py_NewRef(con->fc_builtins);
895-
_PyFrame_Specials(f)[FRAME_SPECIALS_GLOBALS_OFFSET] = Py_NewRef(con->fc_globals);
896-
_PyFrame_Specials(f)[FRAME_SPECIALS_LOCALS_OFFSET] = Py_XNewRef(locals);
897-
// f_valuestack initialized by frame_alloc()
896+
specials[FRAME_SPECIALS_BUILTINS_OFFSET] = Py_NewRef(con->fc_builtins);
897+
specials[FRAME_SPECIALS_GLOBALS_OFFSET] = Py_NewRef(con->fc_globals);
898+
specials[FRAME_SPECIALS_LOCALS_OFFSET] = Py_XNewRef(locals);
898899
f->f_trace = NULL;
899900
f->f_stackdepth = 0;
900901
f->f_trace_lines = 1;
@@ -903,7 +904,6 @@ _PyFrame_New_NoTrack(PyThreadState *tstate, PyFrameConstructor *con, PyObject *l
903904
f->f_lasti = -1;
904905
f->f_lineno = 0;
905906
f->f_state = FRAME_CREATED;
906-
// f_blockstack and f_localsplus initialized by frame_alloc()
907907
return f;
908908
}
909909

0 commit comments

Comments
 (0)