[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.203,2.204 ceval.c,2.242,2.243

Tim Peters tim_one@users.sourceforge.net
Fri, 04 May 2001 17:14:58 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv12706/python/dist/src/Python

Modified Files:
	bltinmodule.c ceval.c 
Log Message:
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
internals) so clients can be a lot dumber (wrt their knowledge).


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.203
retrieving revision 2.204
diff -C2 -r2.203 -r2.204
*** bltinmodule.c	2001/05/04 04:39:21	2.203
--- bltinmodule.c	2001/05/05 00:14:56	2.204
***************
*** 165,169 ****
  	PyObject *func, *seq, *result, *it;
  	int len;   /* guess for result list size */
! 	register int i, j;
  
  	if (!PyArg_ParseTuple(args, "OO:filter", &func, &seq))
--- 165,169 ----
  	PyObject *func, *seq, *result, *it;
  	int len;   /* guess for result list size */
! 	register int j;
  
  	if (!PyArg_ParseTuple(args, "OO:filter", &func, &seq))
***************
*** 205,209 ****
  
  	/* Build the result list. */
! 	for (i = j = 0; ; ++i) {
  		PyObject *item, *good;
  		int ok;
--- 205,210 ----
  
  	/* Build the result list. */
! 	j = 0;
! 	for (;;) {
  		PyObject *item, *good;
  		int ok;
***************
*** 211,224 ****
  		item = PyIter_Next(it);
  		if (item == NULL) {
! 			/* We're out of here in any case, but if this is a
! 			 * StopIteration exception it's expected, but if
! 			 * any other kind of exception it's an error.
! 			 */
! 			if (PyErr_Occurred()) {
! 				if (PyErr_ExceptionMatches(PyExc_StopIteration))
! 					PyErr_Clear();
! 				else
! 					goto Fail_result_it;
! 			}
  			break;
  		}
--- 212,217 ----
  		item = PyIter_Next(it);
  		if (item == NULL) {
! 			if (PyErr_Occurred())
! 				goto Fail_result_it;
  			break;
  		}
***************
*** 1031,1046 ****
  					++numactive;
  				else {
- 					/* StopIteration is *implied* by a
- 					 * NULL return from PyIter_Next() if
- 					 * PyErr_Occurred() is false.
- 					 */
  					if (PyErr_Occurred()) {
! 						if (PyErr_ExceptionMatches(
! 						    PyExc_StopIteration))
! 							PyErr_Clear();
! 						else {
! 							Py_XDECREF(alist);
! 							goto Fail_1;
! 						}
  					}
  					Py_INCREF(Py_None);
--- 1024,1030 ----
  					++numactive;
  				else {
  					if (PyErr_Occurred()) {
! 						Py_XDECREF(alist);
! 						goto Fail_1;
  					}
  					Py_INCREF(Py_None);
***************
*** 1048,1052 ****
  					sqp->saw_StopIteration = 1;
  				}
- 
  			}
  			if (alist)
--- 1032,1035 ----
***************
*** 1446,1450 ****
  min_max(PyObject *args, int op)
  {
- 	int i;
  	PyObject *v, *w, *x, *it;
  
--- 1429,1432 ----
***************
*** 1459,1477 ****
  
  	w = NULL;  /* the result */
! 	for (i = 0; ; i++) {
  		x = PyIter_Next(it);
  		if (x == NULL) {
- 			/* We're out of here in any case, but if this is a
- 			 * StopIteration exception it's expected, but if
- 			 * any other kind of exception it's an error.
- 			 */
  			if (PyErr_Occurred()) {
! 				if (PyErr_ExceptionMatches(PyExc_StopIteration))
! 					PyErr_Clear();
! 				else {
! 					Py_XDECREF(w);
! 					Py_DECREF(it);
! 					return NULL;
! 				}
  			}
  			break;
--- 1441,1451 ----
  
  	w = NULL;  /* the result */
! 	for (;;) {
  		x = PyIter_Next(it);
  		if (x == NULL) {
  			if (PyErr_Occurred()) {
! 				Py_XDECREF(w);
! 				Py_DECREF(it);
! 				return NULL;
  			}
  			break;
***************
*** 1881,1894 ****
  		op2 = PyIter_Next(it);
  		if (op2 == NULL) {
! 			/* StopIteration is *implied* by a NULL return from
! 			 * PyIter_Next() if PyErr_Occurred() is false.
! 			 */
! 			if (PyErr_Occurred()) {
! 				if (PyErr_ExceptionMatches(PyExc_StopIteration))
! 					PyErr_Clear();
! 				else
! 					goto Fail;
! 			}
! 			break;
  		}
  
--- 1855,1861 ----
  		op2 = PyIter_Next(it);
  		if (op2 == NULL) {
! 			if (PyErr_Occurred())
! 				goto Fail;
!  			break;
  		}
  

Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.242
retrieving revision 2.243
diff -C2 -r2.242 -r2.243
*** ceval.c	2001/04/27 02:25:33	2.242
--- ceval.c	2001/05/05 00:14:56	2.243
***************
*** 1895,1903 ****
  				continue;
  			}
! 			if (!PyErr_Occurred() ||
! 			    PyErr_ExceptionMatches(
! 				    PyExc_StopIteration))
! 			{
! 				x = v = POP();
  				Py_DECREF(v);
  				JUMPBY(oparg);
--- 1895,1901 ----
  				continue;
  			}
! 			if (!PyErr_Occurred()) {
! 				/* iterator ended normally */
!  				x = v = POP();
  				Py_DECREF(v);
  				JUMPBY(oparg);