[Python-checkins] CVS: python/dist/src/Objects frameobject.c,2.44,2.45
Jeremy Hylton
jhylton@users.sourceforge.net
Mon, 29 Jan 2001 14:51:54 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv27579/Objects
Modified Files:
frameobject.c
Log Message:
Remove f_closure slot of frameobject and use f_localsplus instead.
This change eliminates an extra malloc/free when a frame with free
variables is created. Any cell vars or free vars are stored in
f_localsplus after the locals and before the stack.
eval_code2() fills in the appropriate values after handling
initialization of locals.
To track the size the frame has an f_size member that tracks the total
size of f_localsplus. It used to be implicitly f_nlocals + f_stacksize.
Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.44
retrieving revision 2.45
diff -C2 -r2.44 -r2.45
*** frameobject.c 2001/01/25 20:06:59 2.44
--- frameobject.c 2001/01/29 22:51:52 2.45
***************
*** 50,53 ****
--- 50,54 ----
f_nlocals number of locals
f_stacksize size of value stack
+ f_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!).
***************
*** 80,84 ****
Py_XDECREF(f->f_globals);
Py_XDECREF(f->f_locals);
- Py_XDECREF(f->f_closure);
Py_XDECREF(f->f_trace);
Py_XDECREF(f->f_exc_type);
--- 81,84 ----
***************
*** 115,119 ****
PyFrameObject *f;
PyObject *builtins;
! int extras, ncells;
if (builtin_object == NULL) {
--- 115,119 ----
PyFrameObject *f;
PyObject *builtins;
! int extras, ncells, nfrees;
if (builtin_object == NULL) {
***************
*** 129,134 ****
return NULL;
}
- extras = code->co_stacksize + code->co_nlocals;
ncells = PyTuple_GET_SIZE(code->co_cellvars);
if (back == NULL || back->f_globals != globals) {
builtins = PyDict_GetItem(globals, builtin_object);
--- 129,135 ----
return NULL;
}
ncells = PyTuple_GET_SIZE(code->co_cellvars);
+ nfrees = PyTuple_GET_SIZE(code->co_freevars);
+ extras = code->co_stacksize + code->co_nlocals + ncells + nfrees;
if (back == NULL || back->f_globals != globals) {
builtins = PyDict_GetItem(globals, builtin_object);
***************
*** 151,159 ****
return (PyFrameObject *)PyErr_NoMemory();
PyObject_INIT(f, &PyFrame_Type);
}
else {
f = free_list;
free_list = free_list->f_back;
! if (f->f_nlocals + f->f_stacksize < extras) {
f = (PyFrameObject *)
PyObject_REALLOC(f, sizeof(PyFrameObject) +
--- 152,161 ----
return (PyFrameObject *)PyErr_NoMemory();
PyObject_INIT(f, &PyFrame_Type);
+ f->f_size = extras;
}
else {
f = free_list;
free_list = free_list->f_back;
! if (f->f_size < extras) {
f = (PyFrameObject *)
PyObject_REALLOC(f, sizeof(PyFrameObject) +
***************
*** 161,167 ****
if (f == NULL)
return (PyFrameObject *)PyErr_NoMemory();
}
else
! extras = f->f_nlocals + f->f_stacksize;
PyObject_INIT(f, &PyFrame_Type);
}
--- 163,170 ----
if (f == NULL)
return (PyFrameObject *)PyErr_NoMemory();
+ f->f_size = extras;
}
else
! extras = f->f_size;
PyObject_INIT(f, &PyFrame_Type);
}
***************
*** 200,219 ****
Py_INCREF(locals);
}
- if (closure || ncells) {
- int i, size;
- size = ncells;
- if (closure)
- size += PyTuple_GET_SIZE(closure);
- f->f_closure = PyTuple_New(size);
- for (i = 0; i < ncells; ++i)
- PyTuple_SET_ITEM(f->f_closure, i, PyCell_New(NULL));
- for (i = ncells; i < size; ++i) {
- PyObject *o = PyTuple_GET_ITEM(closure, i - ncells);
- Py_INCREF(o);
- PyTuple_SET_ITEM(f->f_closure, i, o);
- }
- }
- else
- f->f_closure = NULL;
f->f_locals = locals;
f->f_trace = NULL;
--- 203,206 ----
***************
*** 226,235 ****
f->f_iblock = 0;
f->f_nlocals = code->co_nlocals;
! f->f_stacksize = extras - code->co_nlocals;
while (--extras >= 0)
f->f_localsplus[extras] = NULL;
! f->f_valuestack = f->f_localsplus + f->f_nlocals;
return f;
--- 213,224 ----
f->f_iblock = 0;
f->f_nlocals = code->co_nlocals;
! f->f_stacksize = code->co_stacksize;
! f->f_ncells = ncells;
! f->f_nfreevars = nfrees;
while (--extras >= 0)
f->f_localsplus[extras] = NULL;
! f->f_valuestack = f->f_localsplus + (f->f_nlocals + ncells + nfrees);
return f;
***************
*** 261,264 ****
--- 250,255 ----
/* Convert between "fast" version of locals and dictionary version */
+
+ /* XXX should also copy free variables and cell variables */
void