[Python-checkins] CVS: python/dist/src/Python ceval.c,2.223,2.224
Jeremy Hylton
jhylton@users.sourceforge.net
Mon, 29 Jan 2001 14:51:55 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv27579/Python
Modified Files:
ceval.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: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.223
retrieving revision 2.224
diff -C2 -r2.223 -r2.224
*** ceval.c 2001/01/25 20:06:58 2.223
--- ceval.c 2001/01/29 22:51:52 2.224
***************
*** 369,373 ****
register PyObject *stream = NULL; /* for PRINT opcodes */
register PyFrameObject *f; /* Current frame */
! register PyObject **fastlocals;
PyObject *retval = NULL; /* Return value */
PyThreadState *tstate = PyThreadState_GET();
--- 369,373 ----
register PyObject *stream = NULL; /* for PRINT opcodes */
register PyFrameObject *f; /* Current frame */
! register PyObject **fastlocals, **freevars;
PyObject *retval = NULL; /* Return value */
PyThreadState *tstate = PyThreadState_GET();
***************
*** 440,443 ****
--- 440,444 ----
tstate->frame = f;
fastlocals = f->f_localsplus;
+ freevars = f->f_localsplus + f->f_nlocals;
if (co->co_argcount > 0 ||
***************
*** 573,576 ****
--- 574,588 ----
}
}
+ /* Allocate storage for cell vars and copy free vars into frame */
+ if (f->f_ncells) {
+ int i;
+ for (i = 0; i < f->f_ncells; ++i)
+ freevars[i] = PyCell_New(NULL);
+ }
+ if (f->f_nfreevars) {
+ int i;
+ for (i = 0; i < f->f_nfreevars; ++i)
+ freevars[f->f_ncells + i] = PyTuple_GET_ITEM(closure, i);
+ }
if (tstate->sys_tracefunc != NULL) {
***************
*** 1624,1628 ****
case LOAD_CLOSURE:
! x = PyTuple_GET_ITEM(f->f_closure, oparg);
Py_INCREF(x);
PUSH(x);
--- 1636,1640 ----
case LOAD_CLOSURE:
! x = freevars[oparg];
Py_INCREF(x);
PUSH(x);
***************
*** 1630,1634 ****
case LOAD_DEREF:
! x = PyTuple_GET_ITEM(f->f_closure, oparg);
w = PyCell_Get(x);
Py_INCREF(w);
--- 1642,1646 ----
case LOAD_DEREF:
! x = freevars[oparg];
w = PyCell_Get(x);
Py_INCREF(w);
***************
*** 1638,1642 ****
case STORE_DEREF:
w = POP();
! x = PyTuple_GET_ITEM(f->f_closure, oparg);
PyCell_Set(x, w);
continue;
--- 1650,1654 ----
case STORE_DEREF:
w = POP();
! x = freevars[oparg];
PyCell_Set(x, w);
continue;