[Python-checkins] CVS: python/dist/src/Objects frameobject.c,2.58,2.59
Jeremy Hylton
jhylton@users.sourceforge.net
Thu, 06 Dec 2001 07:48:18 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv28747/Objects
Modified Files:
frameobject.c
Log Message:
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
PyCell_Set() incremenets the reference count, so the earlier XINCREF
causes a leak.
Also make a number of small performance improvements to the code on
the assumption that most of the time variables are not rebound across
a FastToLocals() / LocalsToFast() pair.
Replace uses of PyCell_Set() and PyCell_Get() with PyCell_SET() and
PyCell_GET(), since the frame is guaranteed to contain cells.
Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.58
retrieving revision 2.59
diff -C2 -d -r2.58 -r2.59
*** frameobject.c 2001/09/20 21:45:26 2.58
--- frameobject.c 2001/12/06 15:48:16 2.59
***************
*** 346,355 ****
int j;
for (j = nmap; --j >= 0; ) {
! PyObject *key = PyTuple_GetItem(map, j);
PyObject *value = values[j];
if (deref)
value = PyCell_GET(value);
if (value == NULL) {
- PyErr_Clear();
if (PyDict_DelItem(dict, key) != 0)
PyErr_Clear();
--- 346,354 ----
int j;
for (j = nmap; --j >= 0; ) {
! PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = values[j];
if (deref)
value = PyCell_GET(value);
if (value == NULL) {
if (PyDict_DelItem(dict, key) != 0)
PyErr_Clear();
***************
*** 368,382 ****
int j;
for (j = nmap; --j >= 0; ) {
! PyObject *key = PyTuple_GetItem(map, j);
PyObject *value = PyDict_GetItem(dict, key);
- Py_XINCREF(value);
if (deref) {
if (value || clear) {
! if (PyCell_Set(values[j], value) < 0)
! PyErr_Clear();
}
} else if (value != NULL || clear) {
! Py_XDECREF(values[j]);
! values[j] = value;
}
}
--- 367,385 ----
int j;
for (j = nmap; --j >= 0; ) {
! PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = PyDict_GetItem(dict, key);
if (deref) {
if (value || clear) {
! if (PyCell_GET(values[j]) != value) {
! if (PyCell_Set(values[j], value) < 0)
! PyErr_Clear();
! }
}
} else if (value != NULL || clear) {
! if (values[j] != value) {
! Py_XINCREF(value);
! Py_XDECREF(values[j]);
! values[j] = value;
! }
}
}