[Python-checkins] CVS: python/dist/src/Python compile.c,2.150,2.151

Jeremy Hylton jhylton@users.sourceforge.net
Thu, 25 Jan 2001 09:01:51 -0800


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

Modified Files:
	compile.c 
Log Message:
Fix bug reported by Ka-Ping Yee: The compiler botched parsing function
parameters that contained both anonymous tuples and *arg or **arg. Ex:
def f(a, (b, c), *d): pass

Fix the symtable_params() to generate names in the right order for
co_varnames slot of code object.  Consider *arg and **arg before the
"complex" names introduced by anonymous tuples.


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.150
retrieving revision 2.151
diff -C2 -r2.150 -r2.151
*** compile.c	2001/01/23 01:26:20	2.150
--- compile.c	2001/01/25 17:01:49	2.151
***************
*** 4285,4289 ****
  symtable_params(struct symtable *st, node *n)
  {
! 	int i, complex = 0, ext = 0;
  	node *c = NULL;
  
--- 4285,4289 ----
  symtable_params(struct symtable *st, node *n)
  {
! 	int i, complex = -1, ext = 0;
  	node *c = NULL;
  
***************
*** 4309,4323 ****
  			sprintf(nbuf, ".%d", i);
  			symtable_add_def(st, nbuf, DEF_PARAM);
! 			complex = 1;
  		}
  	}
- 	if (complex) {
- 		int j;
- 		for (j = 0; j < i; j += 2) {
- 			c = CHILD(n, j);
- 			if (TYPE(CHILD(c, 0)) == LPAR)
- 				symtable_params_fplist(st, CHILD(c, 1));
- 		} 
- 	}
  	if (ext) {
  		c = CHILD(n, i);
--- 4309,4315 ----
  			sprintf(nbuf, ".%d", i);
  			symtable_add_def(st, nbuf, DEF_PARAM);
! 			complex = i;
  		}
  	}
  	if (ext) {
  		c = CHILD(n, i);
***************
*** 4328,4339 ****
  			i += 2;
  			if (i >= NCH(n))
! 				return;
  			c = CHILD(n, i);
  		}
! 		if (TYPE(c) == DOUBLESTAR) {
  			i++;
  			symtable_add_def(st, STR(CHILD(n, i)), 
  					 DEF_PARAM | DEF_DOUBLESTAR);
  		}
  	}
  }
--- 4320,4342 ----
  			i += 2;
  			if (i >= NCH(n))
! 				c = NULL;
! 			else
  			c = CHILD(n, i);
  		}
! 		if (c && TYPE(c) == DOUBLESTAR) {
  			i++;
  			symtable_add_def(st, STR(CHILD(n, i)), 
  					 DEF_PARAM | DEF_DOUBLESTAR);
  		}
+ 	}
+ 	if (complex >= 0) {
+ 		int j;
+ 		for (j = 0; j <= complex; j++) {
+ 			c = CHILD(n, j);
+ 			if (TYPE(c) == COMMA)
+ 			    c = CHILD(n, ++j);
+ 			if (TYPE(CHILD(c, 0)) == LPAR)
+ 				symtable_params_fplist(st, CHILD(c, 1));
+ 		} 
  	}
  }