[Python-checkins] CVS: python/dist/src/Objects listobject.c,2.69.2.1,2.69.2.2
Fred L. Drake
python-dev@python.org
Thu, 10 Aug 2000 07:49:42 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv14170
Modified Files:
Tag: cnri-16-start
listobject.c
Log Message:
Migrate Fredrik Lundh's patch to add support for arbitrary sequences to
[].extend() to the 1.6 branch; this is needed to pass the regression test
for the SRE code.
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.69.2.1
retrieving revision 2.69.2.2
diff -C2 -r2.69.2.1 -r2.69.2.2
*** listobject.c 2000/08/03 16:48:51 2.69.2.1
--- listobject.c 2000/08/10 14:49:39 2.69.2.2
***************
*** 593,606 ****
return NULL;
! if (!PyList_Check(b)) {
! PyErr_SetString(PyExc_TypeError,
! "list.extend() argument must be a list");
return NULL;
! }
! if (PyList_GET_SIZE(b) == 0) {
/* short circuit when b is empty */
! Py_INCREF(Py_None);
! return Py_None;
! }
if (self == (PyListObject*)b) {
/* as in list_ass_slice() we must special case the
--- 593,604 ----
return NULL;
! b = PySequence_Fast(b, "list.extend() argument must be a sequence");
! if (!b)
return NULL;
!
! if (PyObject_Length(b) == 0)
/* short circuit when b is empty */
! goto ok;
!
if (self == (PyListObject*)b) {
/* as in list_ass_slice() we must special case the
***************
*** 610,613 ****
--- 608,612 ----
* list_slice() the way list_ass_slice() does.
*/
+ Py_DECREF(b);
b = PyList_New(selflen);
if (!b)
***************
*** 619,649 ****
}
}
! else
! /* we want b to have the same refcount semantics for the
! * Py_XDECREF() in the finally clause regardless of which
! * branch in the above conditional we took.
! */
! Py_INCREF(b);
- blen = PyList_GET_SIZE(b);
/* resize a using idiom */
items = self->ob_item;
NRESIZE(items, PyObject*, selflen + blen);
! if (items == NULL ) {
PyErr_NoMemory();
! goto finally;
}
self->ob_item = items;
! /* populate the end self with b's items */
for (i = 0; i < blen; i++) {
! PyObject *o = PyList_GET_ITEM(b, i);
Py_INCREF(o);
PyList_SET_ITEM(self, self->ob_size++, o);
}
res = Py_None;
Py_INCREF(res);
! finally:
! Py_XDECREF(b);
return res;
}
--- 618,644 ----
}
}
!
! blen = PyObject_Length(b);
/* resize a using idiom */
items = self->ob_item;
NRESIZE(items, PyObject*, selflen + blen);
! if (items == NULL) {
PyErr_NoMemory();
! goto failed;
}
self->ob_item = items;
! /* 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);
}
+ ok:
res = Py_None;
Py_INCREF(res);
! failed:
! Py_DECREF(b);
return res;
}