diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-08-29 23:52:17 (GMT) |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2001-08-29 23:52:17 (GMT) |
commit | 4f4817fee86eb4b659a4629cb5c361f82f16d220 (patch) | |
tree | 5aa2a89e5de2e64d821860bf1c883b2595126a8a /Objects/frameobject.c | |
parent | 01b66a80c4c27eb8b0fb682f6ea35b4654b2cc16 (diff) | |
download | cpython-4f4817fee86eb4b659a4629cb5c361f82f16d220.zip cpython-4f4817fee86eb4b659a4629cb5c361f82f16d220.tar.gz cpython-4f4817fee86eb4b659a4629cb5c361f82f16d220.tar.bz2 |
Make frames a PyVarObject. Use new GC API.
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r-- | Objects/frameobject.c | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index d327616..5ad8afd 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -47,7 +47,7 @@ static struct getsetlist frame_getsetlist[] = { f_back next item on free list, or NULL f_nlocals number of locals f_stacksize size of value stack - f_size size of localsplus + ob_size size of localsplus Note that the value and block stacks are preserved -- this can save another malloc() call or two (and two free() calls as well!). Also note that, unlike for integers, each frame object is a @@ -68,7 +68,7 @@ frame_dealloc(PyFrameObject *f) PyObject **p; Py_TRASHCAN_SAFE_BEGIN(f) - PyObject_GC_Fini(f); + _PyObject_GC_UNTRACK(f); /* Kill all local variables */ slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; fastlocals = f->f_localsplus; @@ -125,7 +125,6 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) for (p = f->f_valuestack; p < f->f_stacktop; p++) VISIT(*p); } - return 0; } @@ -171,8 +170,8 @@ PyTypeObject PyFrame_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, "frame", - sizeof(PyFrameObject) + PyGC_HEAD_SIZE, - 0, + sizeof(PyFrameObject), + sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ @@ -188,7 +187,7 @@ PyTypeObject PyFrame_Type = { PyObject_GenericGetAttr, /* tp_getattro */ PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ 0, /* tp_doc */ (traverseproc)frame_traverse, /* tp_traverse */ (inquiry)frame_clear, /* tp_clear */ @@ -241,34 +240,21 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, if (builtins != NULL && !PyDict_Check(builtins)) builtins = NULL; if (free_list == NULL) { - /* PyObject_New is inlined */ - f = (PyFrameObject *) - PyObject_MALLOC(sizeof(PyFrameObject) + - extras*sizeof(PyObject *) + - PyGC_HEAD_SIZE); + f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); if (f == NULL) - return (PyFrameObject *)PyErr_NoMemory(); - f = (PyFrameObject *) PyObject_FROM_GC(f); - PyObject_INIT(f, &PyFrame_Type); - f->f_size = extras; + return NULL; } else { f = free_list; free_list = free_list->f_back; - if (f->f_size < extras) { - f = (PyFrameObject *) PyObject_AS_GC(f); - f = (PyFrameObject *) - PyObject_REALLOC(f, sizeof(PyFrameObject) + - extras*sizeof(PyObject *) + - PyGC_HEAD_SIZE); + if (f->ob_size < extras) { + f = PyObject_GC_Resize(PyFrameObject, f, extras); if (f == NULL) - return (PyFrameObject *)PyErr_NoMemory(); - f = (PyFrameObject *) PyObject_FROM_GC(f); - f->f_size = extras; + return NULL; } else - extras = f->f_size; - PyObject_INIT(f, &PyFrame_Type); + extras = f->ob_size; + _Py_NewReference(f); } if (builtins == NULL) { /* No builtins! Make up a minimal one. */ @@ -323,8 +309,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees); f->f_stacktop = f->f_valuestack; - - PyObject_GC_Init(f); + _PyObject_GC_TRACK(f); return f; } @@ -486,7 +471,6 @@ PyFrame_Fini(void) while (free_list != NULL) { PyFrameObject *f = free_list; free_list = free_list->f_back; - f = (PyFrameObject *) PyObject_AS_GC(f); - PyObject_DEL(f); + PyObject_GC_Del(f); } } |