[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.198,2.199

Tim Peters tim_one@users.sourceforge.net
Sat, 28 Apr 2001 01:20:24 -0700


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

Modified Files:
	bltinmodule.c 
Log Message:
Fix buglet reported on c.l.py:  map(fnc, file.xreadlines()) blows up.
Also a 2.1 bugfix candidate (am I supposed to do something with those?).
Took away map()'s insistence that sequences support __len__, and cleaned
up the convoluted code that made it *look* like it really cared about
__len__ (in fact the old ->len field was only *used* as a flag bit, as
the main loop only looked at its sign bit, setting the field to -1 when
IndexError got raised; renamed the field to ->saw_IndexError instead).


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.198
retrieving revision 2.199
diff -C2 -r2.198 -r2.199
*** bltinmodule.c	2001/04/20 19:13:02	2.198
--- bltinmodule.c	2001/04/28 08:20:22	2.199
***************
*** 817,824 ****
  		PyCompilerFlags cf;
  		cf.cf_nested_scopes = 1;
! 		res = PyRun_FileExFlags(fp, filename, Py_file_input, globals, 
  				   locals, 1, &cf);
! 	} else 
! 		res = PyRun_FileEx(fp, filename, Py_file_input, globals, 
  				   locals, 1);
  	return res;
--- 817,824 ----
  		PyCompilerFlags cf;
  		cf.cf_nested_scopes = 1;
! 		res = PyRun_FileExFlags(fp, filename, Py_file_input, globals,
  				   locals, 1, &cf);
! 	} else
! 		res = PyRun_FileEx(fp, filename, Py_file_input, globals,
  				   locals, 1);
  	return res;
***************
*** 925,929 ****
  		PyObject *seq;
  		PySequenceMethods *sqf;
! 		int len;
  	} sequence;
  
--- 925,929 ----
  		PyObject *seq;
  		PySequenceMethods *sqf;
! 		int saw_IndexError;
  	} sequence;
  
***************
*** 953,956 ****
--- 953,960 ----
  	}
  
+ 	/* Do a first pass to (a) verify the args are sequences; (b) set
+ 	 * len to the largest of their lengths; (c) initialize the seqs
+ 	 * descriptor vector.
+ 	 */
  	for (len = 0, i = 0, sqp = seqs; i < n; ++i, ++sqp) {
  		int curlen;
***************
*** 960,966 ****
  			goto Fail_2;
  
  		sqp->sqf = sqf = sqp->seq->ob_type->tp_as_sequence;
  		if (sqf == NULL ||
- 		    sqf->sq_length == NULL ||
  		    sqf->sq_item == NULL)
  		{
--- 964,971 ----
  			goto Fail_2;
  
+ 		sqp->saw_IndexError = 0;
+ 
  		sqp->sqf = sqf = sqp->seq->ob_type->tp_as_sequence;
  		if (sqf == NULL ||
  		    sqf->sq_item == NULL)
  		{
***************
*** 974,980 ****
  		}
  
! 		if ((curlen = sqp->len = (*sqp->sqf->sq_length)(sqp->seq)) < 0)
  			goto Fail_2;
- 
  		if (curlen > len)
  			len = curlen;
--- 979,989 ----
  		}
  
! 		if (sqf->sq_length == NULL)
! 			/* doesn't matter -- make something up */
! 			curlen = 8;
! 		else
! 			curlen = (*sqf->sq_length)(sqp->seq);
! 		if (curlen < 0)
  			goto Fail_2;
  		if (curlen > len)
  			len = curlen;
***************
*** 984,987 ****
--- 993,997 ----
  		goto Fail_2;
  
+ 	/* Iterate over the sequences until all have raised IndexError. */
  	for (i = 0; ; ++i) {
  		PyObject *alist, *item=NULL, *value;
***************
*** 996,1000 ****
  
  		for (j = 0, sqp = seqs; j < n; ++j, ++sqp) {
! 			if (sqp->len < 0) {
  				Py_INCREF(Py_None);
  				item = Py_None;
--- 1006,1010 ----
  
  		for (j = 0, sqp = seqs; j < n; ++j, ++sqp) {
! 			if (sqp->saw_IndexError) {
  				Py_INCREF(Py_None);
  				item = Py_None;
***************
*** 1009,1013 ****
  						Py_INCREF(Py_None);
  						item = Py_None;
! 						sqp->len = -1;
  					}
  					else {
--- 1019,1023 ----
  						Py_INCREF(Py_None);
  						item = Py_None;
! 						sqp->saw_IndexError = 1;
  					}
  					else {