[Python-Dev] Re: [Python-checkins] python/dist/src/Objects listobject.c, 2.177, 2.178

Neal Norwitz neal at metaslash.com
Fri Feb 13 21:05:36 EST 2004


On Fri, Feb 13, 2004 at 03:36:41AM -0800, rhettinger at 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);
>   	}



More information about the Python-Dev mailing list