[Python-checkins] CVS: python/dist/src/Objects cellobject.c,1.1,1.2 frameobject.c,2.45,2.46
Jeremy Hylton
jhylton@usw-pr-cvs1.sourceforge.net
Mon, 12 Mar 2001 17:58:23 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv30486/Objects
Modified Files:
cellobject.c frameobject.c
Log Message:
Variety of small INC/DECREF patches that fix reported memory leaks
with free variables. Thanks to Martin v. Loewis for finding two of
the problems. This fixes SF buf 405583.
There is also a C API change: PyFrame_New() is reverting to its
pre-2.1 signature. The change introduced by nested scopes was a
mistake. XXX Is this okay between beta releases?
cell_clear(), the GC helper, must decref its reference to break
cycles.
frame_dealloc() must dealloc all cell vars and free vars in addition
to locals.
eval_code2() setup code must INCREF cells it copies out of the
closure.
The STORE_DEREF opcode implementation must DECREF the object it passes
to PyCell_Set().
Index: cellobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/cellobject.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** cellobject.c 2001/01/25 20:04:14 1.1
--- cellobject.c 2001/03/13 01:58:21 1.2
***************
*** 84,87 ****
--- 84,88 ----
cell_clear(PyCellObject *op)
{
+ Py_XDECREF(op->ob_ref);
op->ob_ref = NULL;
return 0;
Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.45
retrieving revision 2.46
diff -C2 -r2.45 -r2.46
*** frameobject.c 2001/01/29 22:51:52 2.45
--- frameobject.c 2001/03/13 01:58:21 2.46
***************
*** 66,76 ****
frame_dealloc(PyFrameObject *f)
{
! int i;
PyObject **fastlocals;
Py_TRASHCAN_SAFE_BEGIN(f)
/* Kill all local variables */
fastlocals = f->f_localsplus;
! for (i = f->f_nlocals; --i >= 0; ++fastlocals) {
Py_XDECREF(*fastlocals);
}
--- 66,77 ----
frame_dealloc(PyFrameObject *f)
{
! int i, slots;
PyObject **fastlocals;
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);
}
***************
*** 109,113 ****
PyFrameObject *
PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
! PyObject *locals, PyObject *closure)
{
PyFrameObject *back = tstate->frame;
--- 110,114 ----
PyFrameObject *
PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
! PyObject *locals)
{
PyFrameObject *back = tstate->frame;