f->stacktop++;
}
-#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *))
+#define FRAME_SPECIALS_SIZE ((int)((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *)))
+
+static inline int
+_PyFrame_NumSlotsForCodeObject(PyCodeObject *code)
+{
+ /* This function needs to remain in sync with the calculation of
+ * co_framesize in Tools/build/deepfreeze.py */
+ assert(code->co_framesize >= FRAME_SPECIALS_SIZE);
+ return code->co_framesize - FRAME_SPECIALS_SIZE;
+}
void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);
--- /dev/null
+Added ``_PyFrame_NumSlotsForCodeObject``, which returns the number of slots needed in a frame for a given code object.
Py_ssize_t res;
res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus);
PyCodeObject *code = f->f_frame->f_code;
- res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *);
+ res += _PyFrame_NumSlotsForCodeObject(code) * sizeof(PyObject *);
return PyLong_FromSsize_t(res);
}
Py_ssize_t res;
res = offsetof(PyGenObject, gi_iframe) + offsetof(_PyInterpreterFrame, localsplus);
PyCodeObject *code = gen->gi_code;
- res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *);
+ res += _PyFrame_NumSlotsForCodeObject(code) * sizeof(PyObject *);
return PyLong_FromSsize_t(res);
}
make_gen(PyTypeObject *type, PyFunctionObject *func)
{
PyCodeObject *code = (PyCodeObject *)func->func_code;
- int slots = code->co_nlocalsplus + code->co_stacksize;
+ int slots = _PyFrame_NumSlotsForCodeObject(code);
PyGenObject *gen = PyObject_GC_NewVar(PyGenObject, type, slots);
if (gen == NULL) {
return NULL;
self.field(code, "co_argcount")
self.field(code, "co_posonlyargcount")
self.field(code, "co_kwonlyargcount")
+ # The following should remain in sync with _PyFrame_NumSlotsForCodeObject
self.write(f".co_framesize = {code.co_stacksize + len(localsplusnames)} + FRAME_SPECIALS_SIZE,")
self.field(code, "co_stacksize")
self.field(code, "co_firstlineno")