[Python-checkins] python/dist/src/Modules itertoolsmodule.c,1.10,1.11

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Fri, 02 May 2003 12:04:39 -0700


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

Modified Files:
	itertoolsmodule.c 
Log Message:
SF bug #730685:  itertools.islice stop argument is not optional

* itertools.islice() stop argument did not perform as documented.
* beefed-up test suite



Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** itertoolsmodule.c	14 Apr 2003 15:31:27 -0000	1.10
--- itertoolsmodule.c	2 May 2003 19:04:37 -0000	1.11
***************
*** 472,496 ****
  {
  	PyObject *seq;
! 	long a1=0, a2=0, a3=0, start=0, stop=0, step=1;
! 	PyObject *it;
  	int numargs;
  	isliceobject *lz;
  
  	numargs = PyTuple_Size(args);
! 	if (!PyArg_ParseTuple(args, "Ol|ll:islice", &seq, &a1, &a2, &a3))
  		return NULL;
  
  	if (numargs == 2) {
! 		stop = a1;
! 	} else if (numargs == 3) {
! 		start = a1;
! 		stop = a2;
! 	} else {
! 		start = a1;
! 		stop = a2;
! 		step = a3;
  	}
  
! 	if (start<0 || stop<0) {
  		PyErr_SetString(PyExc_ValueError,
  		   "Indices for islice() must be positive.");
--- 472,516 ----
  {
  	PyObject *seq;
! 	long start=0, stop=-1, step=1;
! 	PyObject *it, *a1=NULL, *a2=NULL;
  	int numargs;
  	isliceobject *lz;
  
  	numargs = PyTuple_Size(args);
! 	if (!PyArg_ParseTuple(args, "O|OOl:islice", &seq, &a1, &a2, &step))
  		return NULL;
  
  	if (numargs == 2) {
! 		if (a1 != Py_None) {
! 			stop = PyInt_AsLong(a1);
! 			if (stop == -1) {
! 				if (PyErr_Occurred())
! 					PyErr_Clear();
! 				PyErr_SetString(PyExc_ValueError,
! 				   "Stop argument must be an integer or None.");
! 				return NULL;
! 			}
! 		}
! 	} else if (numargs == 3 || numargs == 4) {
! 		start = PyInt_AsLong(a1);
! 		if (start == -1 && PyErr_Occurred()) {
! 			PyErr_Clear();
! 			PyErr_SetString(PyExc_ValueError,
! 			   "Start argument must be an integer.");
! 			return NULL;
! 		}
! 		if (a2 != Py_None) {
! 			stop = PyInt_AsLong(a2);
! 			if (stop == -1) {
! 				if (PyErr_Occurred())
! 					PyErr_Clear();
! 				PyErr_SetString(PyExc_ValueError,
! 				   "Stop argument must be an integer or None.");
! 				return NULL;
! 			}
! 		}
  	}
  
! 	if (start<0 || stop<-1) {
  		PyErr_SetString(PyExc_ValueError,
  		   "Indices for islice() must be positive.");
***************
*** 555,559 ****
  		lz->cnt++;
  	}
! 	if (lz->cnt >= lz->stop)
  		return NULL;
  	assert(PyIter_Check(it));
--- 575,579 ----
  		lz->cnt++;
  	}
! 	if (lz->stop != -1 && lz->cnt >= lz->stop)
  		return NULL;
  	assert(PyIter_Check(it));