Re: [Python-checkins] python/dist/src/Objects listobject.c, 2.177, 2.178
On Fri, Feb 13, 2004 at 03:36:41AM -0800, rhettinger@users.sourceforge.net wrote:
*************** *** 518,540 **** else { /* Insert d items; recycle ihigh-ilow items */ ! NRESIZE(item, PyObject *, a->ob_size + d); ! if (item == NULL) { if (recycle != NULL) PyMem_DEL(recycle); - PyErr_NoMemory(); - return -1; } --- 517,535 ---- else { /* Insert d items; recycle ihigh-ilow items */ ! s = a->ob_size; ! if (list_resize(a, s+d) == -1) { if (recycle != NULL) PyMem_DEL(recycle); }
Missing the return -1; when list_resize() fails? In the following 2 for loops, the original code modified self->ob_size. In the new version I don't notice ob_size being updated. Given the context, I'm not sure if the behaviour is different or not between versions.
*************** *** 592,612 **** for (i = 1; i < n; i++) { /* Start counting at 1, not 0 */ for (j = 0; j < size; j++) { PyObject *o = PyList_GET_ITEM(self, j); Py_INCREF(o); ! PyList_SET_ITEM(self, self->ob_size++, o); } } --- 586,602 ---- for (i = 1; i < n; i++) { /* Start counting at 1, not 0 */ for (j = 0; j < size; j++) { PyObject *o = PyList_GET_ITEM(self, j); Py_INCREF(o); ! PyList_SET_ITEM(self, p++, o); } } *************** *** 687,707 **** /* populate the end of self with b's items */ for (i = 0; i < blen; i++) { PyObject *o = PySequence_Fast_GET_ITEM(b, i); Py_INCREF(o); ! PyList_SET_ITEM(self, self->ob_size++, o); } --- 676,689 ---- /* populate the end of self with b's items */ for (i = 0; i < blen; i++) { PyObject *o = PySequence_Fast_GET_ITEM(b, i); Py_INCREF(o); ! PyList_SET_ITEM(self, i+selflen, o); }
[Neal Norwitz]
Missing the return -1; when list_resize() fails?
Yes. Will fix.
In the following 2 for loops, the original code modified self->ob_size. In the new version I don't notice ob_size being updated. Given the context, I'm not sure if the behaviour is different or not between versions.
self->ob_size is now updated by list_resize() so the loop no longer needs to do the update. This is a nice improvement clients of list_resize() do not need to manage ob_size; rather, the just request the size they want and the data structure keeps its integrity. Raymond
participants (2)
-
Neal Norwitz -
Raymond Hettinger