Skip to content

Commit 4f4817f

Browse files
committed
Make frames a PyVarObject. Use new GC API.
1 parent 01b66a8 commit 4f4817f

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

Objects/frameobject.c

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static struct getsetlist frame_getsetlist[] = {
4747
f_back next item on free list, or NULL
4848
f_nlocals number of locals
4949
f_stacksize size of value stack
50-
f_size size of localsplus
50+
ob_size size of localsplus
5151
Note that the value and block stacks are preserved -- this can save
5252
another malloc() call or two (and two free() calls as well!).
5353
Also note that, unlike for integers, each frame object is a
@@ -68,7 +68,7 @@ frame_dealloc(PyFrameObject *f)
6868
PyObject **p;
6969

7070
Py_TRASHCAN_SAFE_BEGIN(f)
71-
PyObject_GC_Fini(f);
71+
_PyObject_GC_UNTRACK(f);
7272
/* Kill all local variables */
7373
slots = f->f_nlocals + f->f_ncells + f->f_nfreevars;
7474
fastlocals = f->f_localsplus;
@@ -125,7 +125,6 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg)
125125
for (p = f->f_valuestack; p < f->f_stacktop; p++)
126126
VISIT(*p);
127127
}
128-
129128
return 0;
130129
}
131130

@@ -171,8 +170,8 @@ PyTypeObject PyFrame_Type = {
171170
PyObject_HEAD_INIT(&PyType_Type)
172171
0,
173172
"frame",
174-
sizeof(PyFrameObject) + PyGC_HEAD_SIZE,
175-
0,
173+
sizeof(PyFrameObject),
174+
sizeof(PyObject *),
176175
(destructor)frame_dealloc, /* tp_dealloc */
177176
0, /* tp_print */
178177
0, /* tp_getattr */
@@ -188,7 +187,7 @@ PyTypeObject PyFrame_Type = {
188187
PyObject_GenericGetAttr, /* tp_getattro */
189188
PyObject_GenericSetAttr, /* tp_setattro */
190189
0, /* tp_as_buffer */
191-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
190+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
192191
0, /* tp_doc */
193192
(traverseproc)frame_traverse, /* tp_traverse */
194193
(inquiry)frame_clear, /* tp_clear */
@@ -241,34 +240,21 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
241240
if (builtins != NULL && !PyDict_Check(builtins))
242241
builtins = NULL;
243242
if (free_list == NULL) {
244-
/* PyObject_New is inlined */
245-
f = (PyFrameObject *)
246-
PyObject_MALLOC(sizeof(PyFrameObject) +
247-
extras*sizeof(PyObject *) +
248-
PyGC_HEAD_SIZE);
243+
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
249244
if (f == NULL)
250-
return (PyFrameObject *)PyErr_NoMemory();
251-
f = (PyFrameObject *) PyObject_FROM_GC(f);
252-
PyObject_INIT(f, &PyFrame_Type);
253-
f->f_size = extras;
245+
return NULL;
254246
}
255247
else {
256248
f = free_list;
257249
free_list = free_list->f_back;
258-
if (f->f_size < extras) {
259-
f = (PyFrameObject *) PyObject_AS_GC(f);
260-
f = (PyFrameObject *)
261-
PyObject_REALLOC(f, sizeof(PyFrameObject) +
262-
extras*sizeof(PyObject *) +
263-
PyGC_HEAD_SIZE);
250+
if (f->ob_size < extras) {
251+
f = PyObject_GC_Resize(PyFrameObject, f, extras);
264252
if (f == NULL)
265-
return (PyFrameObject *)PyErr_NoMemory();
266-
f = (PyFrameObject *) PyObject_FROM_GC(f);
267-
f->f_size = extras;
253+
return NULL;
268254
}
269255
else
270-
extras = f->f_size;
271-
PyObject_INIT(f, &PyFrame_Type);
256+
extras = f->ob_size;
257+
_Py_NewReference(f);
272258
}
273259
if (builtins == NULL) {
274260
/* No builtins! Make up a minimal one. */
@@ -323,8 +309,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
323309

324310
f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees);
325311
f->f_stacktop = f->f_valuestack;
326-
327-
PyObject_GC_Init(f);
312+
_PyObject_GC_TRACK(f);
328313
return f;
329314
}
330315

@@ -486,7 +471,6 @@ PyFrame_Fini(void)
486471
while (free_list != NULL) {
487472
PyFrameObject *f = free_list;
488473
free_list = free_list->f_back;
489-
f = (PyFrameObject *) PyObject_AS_GC(f);
490-
PyObject_DEL(f);
474+
PyObject_GC_Del(f);
491475
}
492476
}

0 commit comments

Comments
 (0)