[Python-checkins] CVS: python/dist/src/Objects abstract.c,2.60.2.2,2.60.2.3
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 06 Jun 2001 10:59:43 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv9436
Modified Files:
Tag: descr-branch
abstract.c
Log Message:
Stamp out duplicate code: PySequence_List(x) should call list(x).
Index: abstract.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v
retrieving revision 2.60.2.2
retrieving revision 2.60.2.3
diff -C2 -r2.60.2.2 -r2.60.2.3
*** abstract.c 2001/05/05 11:37:29 2.60.2.2
--- abstract.c 2001/06/06 17:59:41 2.60.2.3
***************
*** 1237,1286 ****
PySequence_List(PyObject *v)
{
- PySequenceMethods *m;
-
if (v == NULL)
return null_error();
!
! if (PyList_Check(v))
! return PyList_GetSlice(v, 0, PyList_GET_SIZE(v));
!
! m = v->ob_type->tp_as_sequence;
! if (m && m->sq_item) {
! int i;
! PyObject *l;
! int n = PySequence_Size(v);
! if (n < 0)
! return NULL;
! l = PyList_New(n);
! if (l == NULL)
! return NULL;
! for (i = 0; ; i++) {
! PyObject *item = (*m->sq_item)(v, i);
! if (item == NULL) {
! if (PyErr_ExceptionMatches(PyExc_IndexError))
! PyErr_Clear();
! else {
! Py_DECREF(l);
! l = NULL;
! }
! break;
! }
! if (i < n)
! PyList_SET_ITEM(l, i, item);
! else if (PyList_Append(l, item) < 0) {
! Py_DECREF(l);
! l = NULL;
! break;
! }
! }
! if (i < n && l != NULL) {
! if (PyList_SetSlice(l, i, n, (PyObject *)NULL) != 0) {
! Py_DECREF(l);
! l = NULL;
! }
! }
! return l;
! }
! return type_error("list() argument must be a sequence");
}
--- 1237,1243 ----
PySequence_List(PyObject *v)
{
if (v == NULL)
return null_error();
! return PyObject_CallFunction((PyObject *) &PyList_Type, "(O)", v);
}