]> granicus.if.org Git - python/commitdiff
Use _PyEval_SliceIndex to handle list.index() calls with
authorWalter Dörwald <walter@livinglogic.de>
Tue, 17 Jun 2003 19:27:39 +0000 (19:27 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Tue, 17 Jun 2003 19:27:39 +0000 (19:27 +0000)
huge start and stop arguments. Add tests.

Lib/test/test_types.py
Objects/listobject.c

index 61f660b6ff9f6566401059f6b59f1d9e7a3e08a9..f39c51a4d03a28acde1df9c3ff9cf16adcc9aa59 100644 (file)
@@ -374,6 +374,15 @@ if a.index(0,3) != 3: raise TestFailed, 'list index, start argument'
 if a.index(0,-3) != 3: raise TestFailed, 'list index, -start argument'
 if a.index(0,3,4) != 3: raise TestFailed, 'list index, stop argument'
 if a.index(0,-3,-2) != 3: raise TestFailed, 'list index, -stop argument'
+if a.index(0,-4*sys.maxint,4*sys.maxint) != 2:
+    raise TestFailed, 'list index, -maxint, maxint argument'
+try:
+    a.index(0, 4*sys.maxint,-4*sys.maxint)
+except ValueError:
+    pass
+else:
+    raise TestFailed, 'list index, maxint,-maxint argument'
+
 try:
     a.index(2,0,-10)
 except ValueError:
index a70ac5ffa9a0f04b6a1283cb3b431ff107d668e0..b059420f4a6d7b3ae2374a4810870946ede18aef 100644 (file)
@@ -1832,7 +1832,9 @@ 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))
+       if (!PyArg_ParseTuple(args, "O|O&O&:index", &v,
+                                   _PyEval_SliceIndex, &start,
+                                   _PyEval_SliceIndex, &stop))
                return NULL;
        if (start < 0) {
                start += self->ob_size;