[Python-checkins] CVS: python/dist/src/Objects tupleobject.c,2.61,2.62
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年12月07日 12:00:08 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv2029
Modified Files:
tupleobject.c
Log Message:
_PyTuple_Resize(): this dumped core on tuple(globals()) for me. Turns
out the for loop at the end intended to zero out new items wasn't
doing anything, because sv->ob_size was already equal to newsize. The
fix slightly refactors the function, introducing a variable oldsize
and doing away with sizediff (which was used only once), and using
oldsize and newsize consistently. I also added comments explaining
what the two for loops do. (Looking at the CVS annotation of this
function, it's no miracle a bug crept in -- this has been patched by
many different folks! :-)
Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.61
retrieving revision 2.62
diff -C2 -d -r2.61 -r2.62
*** tupleobject.c 2001年10月05日 20:51:39 2.61
--- tupleobject.c 2001年12月07日 20:00:04 2.62
***************
*** 599,603 ****
register PyTupleObject *sv;
int i;
! int sizediff;
v = (PyTupleObject *) *pv;
--- 599,603 ----
register PyTupleObject *sv;
int i;
! int oldsize;
v = (PyTupleObject *) *pv;
***************
*** 609,617 ****
return -1;
}
! sizediff = newsize - v->ob_size;
! if (sizediff == 0)
return 0;
! if (v->ob_size == 0) {
/* Empty tuples are often shared, so we should never
resize them in-place even if we do own the only
--- 609,617 ----
return -1;
}
! oldsize = v->ob_size;
! if (oldsize == newsize)
return 0;
! if (oldsize == 0) {
/* Empty tuples are often shared, so we should never
resize them in-place even if we do own the only
***************
*** 628,632 ****
_PyObject_GC_UNTRACK(v);
_Py_ForgetReference((PyObject *) v);
! for (i = newsize; i < v->ob_size; i++) {
Py_XDECREF(v->ob_item[i]);
v->ob_item[i] = NULL;
--- 628,633 ----
_PyObject_GC_UNTRACK(v);
_Py_ForgetReference((PyObject *) v);
! /* DECREF items deleted by shrinkage */
! for (i = newsize; i < oldsize; i++) {
Py_XDECREF(v->ob_item[i]);
v->ob_item[i] = NULL;
***************
*** 639,643 ****
}
_Py_NewReference((PyObject *) sv);
! for (i = sv->ob_size; i < newsize; i++)
sv->ob_item[i] = NULL;
*pv = (PyObject *) sv;
--- 640,645 ----
}
_Py_NewReference((PyObject *) sv);
! /* Zero out items added by growing */
! for (i = oldsize; i < newsize; i++)
sv->ob_item[i] = NULL;
*pv = (PyObject *) sv;