Index: Include/frameobject.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/frameobject.h,v retrieving revision 2.38 diff -w -u -r2.38 frameobject.h --- Include/frameobject.h 2 Jul 2004 06:41:04 -0000 2.38 +++ Include/frameobject.h 25 Oct 2005 06:10:56 -0000 @@ -36,10 +36,6 @@ in this scope */ int f_iblock; /* index in f_blockstack */ PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */ - int f_nlocals; /* number of locals */ - int f_ncells; - int f_nfreevars; - int f_stacksize; /* size of value stack */ PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */ } PyFrameObject; Index: Objects/frameobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v retrieving revision 2.81 diff -w -u -r2.81 frameobject.c --- Objects/frameobject.c 21 Oct 2005 14:58:06 -0000 2.81 +++ Objects/frameobject.c 25 Oct 2005 06:10:57 -0000 @@ -357,7 +357,6 @@ is on the free list, only the following members have a meaning: ob_type == &Frametype f_back next item on free list, or NULL - f_nlocals number of locals f_stacksize size of value stack ob_size size of localsplus Note that the value and block stacks are preserved -- this can save @@ -388,7 +387,7 @@ PyObject_GC_UnTrack(f); Py_TRASHCAN_SAFE_BEGIN(f) /* Kill all local variables */ - slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; + slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); fastlocals = f->f_localsplus; for (i = slots; --i >= 0; ++fastlocals) { Py_XDECREF(*fastlocals); @@ -437,7 +436,7 @@ VISIT(f->f_exc_traceback); /* locals */ - slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; + slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); fastlocals = f->f_localsplus; for (i = slots; --i >= 0; ++fastlocals) { VISIT(*fastlocals); @@ -470,7 +469,7 @@ f->f_trace = NULL; /* locals */ - slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; + slots = f->f_code->co_nlocals + PyTuple_GET_SIZE(f->f_code->co_cellvars) + PyTuple_GET_SIZE(f->f_code->co_freevars); fastlocals = f->f_localsplus; for (i = slots; --i >= 0; ++fastlocals) { if (*fastlocals != NULL) { @@ -635,12 +634,8 @@ f->f_lineno = code->co_firstlineno; f->f_restricted = (builtins != tstate->interp->builtins); f->f_iblock = 0; - f->f_nlocals = code->co_nlocals; - f->f_stacksize = code->co_stacksize; - f->f_ncells = ncells; - f->f_nfreevars = nfrees; - extras = f->f_nlocals + ncells + nfrees; + extras = f->f_code->co_nlocals + ncells + nfrees; /* Tim said it's ok to replace memset */ for (i=0; if_localsplus[i] = NULL; @@ -733,7 +728,8 @@ PyObject *locals, *map; PyObject **fast; PyObject *error_type, *error_value, *error_traceback; - int j; + PyCodeObject *co; + int j, ncells, nfreevars; if (f == NULL) return; locals = f->f_locals; @@ -744,27 +740,24 @@ return; } } - map = f->f_code->co_varnames; + co = f->f_code; + map = co->co_varnames; if (!PyTuple_Check(map)) return; PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; j = PyTuple_Size(map); - if (j > f->f_nlocals) - j = f->f_nlocals; - if (f->f_nlocals) + if (j > co->co_nlocals) + j = co->co_nlocals; + if (co->co_nlocals) map_to_dict(map, j, locals, fast, 0); - if (f->f_ncells || f->f_nfreevars) { - if (!(PyTuple_Check(f->f_code->co_cellvars) - && PyTuple_Check(f->f_code->co_freevars))) { - return; - } - map_to_dict(f->f_code->co_cellvars, - PyTuple_GET_SIZE(f->f_code->co_cellvars), - locals, fast + f->f_nlocals, 1); - map_to_dict(f->f_code->co_freevars, - PyTuple_GET_SIZE(f->f_code->co_freevars), - locals, fast + f->f_nlocals + f->f_ncells, 1); + ncells = PyTuple_GET_SIZE(co->co_cellvars); + nfreevars = PyTuple_GET_SIZE(co->co_freevars); + if (ncells || nfreevars) { + map_to_dict(co->co_cellvars, ncells, + locals, fast + co->co_nlocals, 1); + map_to_dict(co->co_freevars, nfreevars, + locals, fast + co->co_nlocals + ncells, 1); } PyErr_Restore(error_type, error_value, error_traceback); } @@ -776,11 +769,13 @@ PyObject *locals, *map; PyObject **fast; PyObject *error_type, *error_value, *error_traceback; - int j; + PyCodeObject *co; + int j, ncells, nfreevars; if (f == NULL) return; locals = f->f_locals; - map = f->f_code->co_varnames; + co = f->f_code; + map = co->co_varnames; if (locals == NULL) return; if (!PyTuple_Check(map)) @@ -788,20 +783,17 @@ PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; j = PyTuple_Size(map); - if (j > f->f_nlocals) - j = f->f_nlocals; - if (f->f_nlocals) - dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); - if (f->f_ncells || f->f_nfreevars) { - if (!(PyTuple_Check(f->f_code->co_cellvars) - && PyTuple_Check(f->f_code->co_freevars))) - return; - dict_to_map(f->f_code->co_cellvars, - PyTuple_GET_SIZE(f->f_code->co_cellvars), - locals, fast + f->f_nlocals, 1, clear); - dict_to_map(f->f_code->co_freevars, - PyTuple_GET_SIZE(f->f_code->co_freevars), - locals, fast + f->f_nlocals + f->f_ncells, 1, + if (j > co->co_nlocals) + j = co->co_nlocals; + if (co->co_nlocals) + dict_to_map(co->co_varnames, j, locals, fast, 0, clear); + ncells = PyTuple_GET_SIZE(co->co_cellvars); + nfreevars = PyTuple_GET_SIZE(co->co_freevars); + if (ncells || nfreevars) { + dict_to_map(co->co_cellvars, ncells, + locals, fast + co->co_nlocals, 1, clear); + dict_to_map(co->co_freevars, nfreevars, + locals, fast + co->co_nlocals + ncells, 1, clear); } PyErr_Restore(error_type, error_value, error_traceback); Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.429 diff -w -u -r2.429 ceval.c --- Python/ceval.c 21 Oct 2005 04:28:38 -0000 2.429 +++ Python/ceval.c 25 Oct 2005 06:10:57 -0000 @@ -654,11 +654,11 @@ #ifdef LLTRACE #define PUSH(v) { (void)(BASIC_PUSH(v), \ lltrace && prtrace(TOP(), "push")); \ - assert(STACK_LEVEL() <= f->f_stacksize); } + assert(STACK_LEVEL() <= co->co_stacksize); } #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), BASIC_POP()) #define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \ lltrace && prtrace(TOP(), "stackadj")); \ - assert(STACK_LEVEL() <= f->f_stacksize); } + assert(STACK_LEVEL() <= co->co_stacksize); } #else #define PUSH(v) BASIC_PUSH(v) #define POP() BASIC_POP() @@ -727,7 +727,7 @@ names = co->co_names; consts = co->co_consts; fastlocals = f->f_localsplus; - freevars = f->f_localsplus + f->f_nlocals; + freevars = f->f_localsplus + co->co_nlocals; first_instr = (unsigned char*) PyString_AS_STRING(co->co_code); /* An explanation is in order for the next line. @@ -778,7 +778,7 @@ READ_TIMESTAMP(loop0); #endif assert(stack_pointer >= f->f_valuestack); /* else underflow */ - assert(STACK_LEVEL() <= f->f_stacksize); /* else overflow */ + assert(STACK_LEVEL() <= co->co_stacksize); /* else overflow */ /* Do periodic things. Doing this every time through the loop would add too much overhead, so we do it @@ -1914,17 +1914,17 @@ /* Don't stomp existing exception */ if (PyErr_Occurred()) break; - if (oparg < f->f_ncells) { - v = PyTuple_GetItem(co->co_cellvars, + if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) { + v = PyTuple_GET_ITEM(co->co_cellvars, oparg); format_exc_check_arg( PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, v); } else { - v = PyTuple_GetItem( + v = PyTuple_GET_ITEM( co->co_freevars, - oparg - f->f_ncells); + oparg - PyTuple_GET_SIZE(co->co_cellvars)); format_exc_check_arg( PyExc_NameError, UNBOUNDFREE_ERROR_MSG, @@ -2536,7 +2536,7 @@ return NULL; fastlocals = f->f_localsplus; - freevars = f->f_localsplus + f->f_nlocals; + freevars = f->f_localsplus + co->co_nlocals; if (co->co_argcount > 0 || co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) { @@ -2672,7 +2672,7 @@ } /* Allocate and initialize storage for cell vars, and copy free vars into frame. This isn't too efficient right now. */ - if (f->f_ncells) { + if (PyTuple_GET_SIZE(co->co_cellvars)) { int i = 0, j = 0, nargs, found; char *cellname, *argname; PyObject *c; @@ -2690,7 +2690,7 @@ that are arguments at the beginning of the cellvars list so that we can march over it more efficiently? */ - for (i = 0; i < f->f_ncells; ++i) { + for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { cellname = PyString_AS_STRING( PyTuple_GET_ITEM(co->co_cellvars, i)); found = 0; @@ -2701,7 +2701,7 @@ c = PyCell_New(GETLOCAL(j)); if (c == NULL) goto fail; - GETLOCAL(f->f_nlocals + i) = c; + GETLOCAL(co->co_nlocals + i) = c; found = 1; break; } @@ -2710,16 +2710,16 @@ c = PyCell_New(NULL); if (c == NULL) goto fail; - SETLOCAL(f->f_nlocals + i, c); + SETLOCAL(co->co_nlocals + i, c); } } } - if (f->f_nfreevars) { + if (PyTuple_GET_SIZE(co->co_freevars)) { int i; - for (i = 0; i < f->f_nfreevars; ++i) { + for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) { PyObject *o = PyTuple_GET_ITEM(closure, i); Py_INCREF(o); - freevars[f->f_ncells + i] = o; + freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o; } } @@ -4268,7 +4268,7 @@ } case STORE_DEREF: { - PyObject **freevars = f->f_localsplus + f->f_nlocals; + PyObject **freevars = f->f_localsplus + f->f_code->co_nlocals; PyObject *c = freevars[PEEKARG()]; if (PyCell_GET(c) == v) PyCell_Set(c, NULL);