[Python-checkins] python/dist/src/Objects listobject.c,2.153,2.154
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Mon, 16 Jun 2003 22:05:51 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv30555/Objects
Modified Files:
listobject.c
Log Message:
SF #754014: list.index() should accept optional start, end arguments
Also, modified UserList.index() to match and expanded the related tests.
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.153
retrieving revision 2.154
diff -C2 -d -r2.153 -r2.154
*** listobject.c 21 May 2003 05:58:46 -0000 2.153
--- listobject.c 17 Jun 2003 05:05:48 -0000 2.154
***************
*** 1828,1836 ****
static PyObject *
! listindex(PyListObject *self, PyObject *v)
{
! int i;
! for (i = 0; i < self->ob_size; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
--- 1828,1841 ----
static PyObject *
! listindex(PyListObject *self, PyObject *args)
{
! int i, start=0, stop=self->ob_size;
! PyObject *v;
! if (!PyArg_ParseTuple(args, "O|ii:index", &v, &start, &stop))
! return NULL;
! start = max(0, start);
! stop = max(0, min(self->ob_size, stop));
! for (i = start; i < stop; i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
***************
*** 2089,2093 ****
"L.remove(value) -- remove first occurrence of value");
PyDoc_STRVAR(index_doc,
! "L.index(value) -> integer -- return index of first occurrence of value");
PyDoc_STRVAR(count_doc,
"L.count(value) -> integer -- return number of occurrences of value");
--- 2094,2098 ----
"L.remove(value) -- remove first occurrence of value");
PyDoc_STRVAR(index_doc,
! "L.index(value, [start, [stop]]) -> integer -- return first index of value");
PyDoc_STRVAR(count_doc,
"L.count(value) -> integer -- return number of occurrences of value");
***************
*** 2103,2107 ****
{"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc},
{"remove", (PyCFunction)listremove, METH_O, remove_doc},
! {"index", (PyCFunction)listindex, METH_O, index_doc},
{"count", (PyCFunction)listcount, METH_O, count_doc},
{"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc},
--- 2108,2112 ----
{"pop", (PyCFunction)listpop, METH_VARARGS, pop_doc},
{"remove", (PyCFunction)listremove, METH_O, remove_doc},
! {"index", (PyCFunction)listindex, METH_VARARGS, index_doc},
{"count", (PyCFunction)listcount, METH_O, count_doc},
{"reverse", (PyCFunction)listreverse, METH_NOARGS, reverse_doc},