[Python-checkins] python/dist/src/Objects listobject.c,2.154,2.155

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 17 Jun 2003 07:24:55 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv10479

Modified Files:
	listobject.c 
Log Message:
Fix sloppy index() implementation:
- don't use min() and max()
- interpret negative start/stop argument like negative slice indices


Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.154
retrieving revision 2.155
diff -C2 -d -r2.154 -r2.155
*** listobject.c	17 Jun 2003 05:05:48 -0000	2.154
--- listobject.c	17 Jun 2003 14:24:53 -0000	2.155
***************
*** 1835,1840 ****
  	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);
--- 1835,1850 ----
  	if (!PyArg_ParseTuple(args, "O|ii:index", &v, &start, &stop))
  		return NULL;
! 	if (start < 0) {
! 		start += self->ob_size;
! 		if (start < 0)
! 			start = 0;
! 	}
! 	if (stop < 0) {
! 		stop += self->ob_size;
! 		if (stop < 0)
! 			stop = 0;
! 	}
! 	else if (stop > self->ob_size)
! 		stop = self->ob_size;
  	for (i = start; i < stop; i++) {
  		int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);