Index: Objects/frameobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v retrieving revision 2.76 diff -c -r2.76 frameobject.c *** Objects/frameobject.c 21 Oct 2003 18:14:20 -0000 2.76 --- Objects/frameobject.c 14 Jan 2004 17:34:33 -0000 *************** *** 357,365 **** 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 another malloc() call or two (and two free() calls as well!). Also note that, unlike for integers, each frame object is a --- 357,366 ---- is on the free list, only the following members have a meaning: ob_type == &Frametype f_back next item on free list, or NULL ob_size size of localsplus + f_localsplus zeroed + f_trace NULL + f_exc_* NULL 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 *************** *** 378,414 **** static int numfree = 0; /* number of frames currently in free_list */ #define MAXFREELIST 200 /* max value for numfree */ static void frame_dealloc(PyFrameObject *f) { ! int i, slots; ! PyObject **fastlocals; PyObject **p; PyObject_GC_UnTrack(f); Py_TRASHCAN_SAFE_BEGIN(f) ! /* Kill all local variables */ ! slots = f->f_nlocals + f->f_ncells + f->f_nfreevars; ! fastlocals = f->f_localsplus; ! for (i = slots; --i >= 0; ++fastlocals) { ! Py_XDECREF(*fastlocals); } ! /* Free stack */ ! if (f->f_stacktop != NULL) { ! for (p = f->f_valuestack; p < f->f_stacktop; p++) ! Py_XDECREF(*p); } Py_XDECREF(f->f_back); Py_DECREF(f->f_code); Py_DECREF(f->f_builtins); Py_DECREF(f->f_globals); ! Py_XDECREF(f->f_locals); ! Py_XDECREF(f->f_trace); ! Py_XDECREF(f->f_exc_type); ! Py_XDECREF(f->f_exc_value); ! Py_XDECREF(f->f_exc_traceback); if (numfree < MAXFREELIST) { ++numfree; f->f_back = free_list; --- 379,421 ---- static int numfree = 0; /* number of frames currently in free_list */ #define MAXFREELIST 200 /* max value for numfree */ + #define ZAP(x) { \ + PyObject *tmp = (PyObject *)(x); \ + if (tmp != NULL) { \ + (x) = NULL; \ + Py_DECREF(tmp); \ + } \ + } + static void frame_dealloc(PyFrameObject *f) { ! PyObject **stacktop; PyObject **p; PyObject_GC_UnTrack(f); Py_TRASHCAN_SAFE_BEGIN(f) ! /* Kill all local variables and stack values */ ! stacktop = f->f_stacktop != NULL ? f->f_stacktop : f->f_valuestack; ! for (p = f->f_localsplus; p < stacktop; ++p) { ! ZAP(*p); } ! /* Zero the rest of the stack memory */ ! stacktop = f->f_valuestack + f->f_stacksize; ! for (; p < stacktop; ++p) { ! *p = NULL; } Py_XDECREF(f->f_back); Py_DECREF(f->f_code); Py_DECREF(f->f_builtins); Py_DECREF(f->f_globals); ! ZAP(f->f_locals); ! ZAP(f->f_trace); ! ZAP(f->f_exc_type); ! ZAP(f->f_exc_value); ! ZAP(f->f_exc_traceback); if (numfree < MAXFREELIST) { ++numfree; f->f_back = free_list; *************** *** 540,546 **** PyFrameObject *back = tstate->frame; PyFrameObject *f; PyObject *builtins; ! int extras, ncells, nfrees; #ifdef Py_DEBUG if (code == NULL || globals == NULL || !PyDict_Check(globals) || --- 547,553 ---- PyFrameObject *back = tstate->frame; PyFrameObject *f; PyObject *builtins; ! int extras, ncells, nfrees, valuestackofs; #ifdef Py_DEBUG if (code == NULL || globals == NULL || !PyDict_Check(globals) || *************** *** 551,557 **** #endif 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); if (builtins) { --- 558,565 ---- #endif ncells = PyTuple_GET_SIZE(code->co_cellvars); nfrees = PyTuple_GET_SIZE(code->co_freevars); ! valuestackofs = code->co_nlocals + ncells + nfrees; ! extras = code->co_stacksize + valuestackofs; if (back == NULL || back->f_globals != globals) { builtins = PyDict_GetItem(globals, builtin_object); if (builtins) { *************** *** 586,591 **** --- 594,603 ---- f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras); if (f == NULL) return NULL; + f->f_trace = NULL; + f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; + memset(f->f_localsplus, 0, + valuestackofs * sizeof(f->f_localsplus[0])); } else { assert(numfree > 0); *************** *** 596,601 **** --- 608,615 ---- f = PyObject_GC_Resize(PyFrameObject, f, extras); if (f == NULL) return NULL; + memset(f->f_localsplus, 0, + valuestackofs * sizeof(f->f_localsplus[0])); } _Py_NewReference((PyObject *)f); } *************** *** 623,630 **** Py_INCREF(locals); } f->f_locals = locals; - f->f_trace = NULL; - f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL; f->f_tstate = tstate; f->f_lasti = -1; --- 637,642 ---- *************** *** 636,645 **** f->f_ncells = ncells; f->f_nfreevars = nfrees; ! extras = f->f_nlocals + ncells + nfrees; ! memset(f->f_localsplus, 0, extras * sizeof(f->f_localsplus[0])); ! ! f->f_valuestack = f->f_localsplus + extras; f->f_stacktop = f->f_valuestack; _PyObject_GC_TRACK(f); return f; --- 648,654 ---- f->f_ncells = ncells; f->f_nfreevars = nfrees; ! f->f_valuestack = f->f_localsplus + valuestackofs; f->f_stacktop = f->f_valuestack; _PyObject_GC_TRACK(f); return f;