[Python-checkins] CVS: python/dist/src/Python compile.c,2.196,2.196.2.1

Thomas Wouters twouters@users.sourceforge.net
Wed, 23 May 2001 05:11:38 -0700


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

Modified Files:
      Tag: release21-maint
	compile.c 
Log Message:

Backport Jeremy's checkin 2.198:

Fix 2.1 nested scopes crash reported by Evan Simpson

The new test case demonstrates the bug.  Be more careful in
symtable_resolve_free() to add a var to cells or frees only if it
won't be added under some other rule. 

XXX Add new assertion that will catch this bug.



Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.196
retrieving revision 2.196.2.1
diff -C2 -r2.196 -r2.196.2.1
*** compile.c	2001/04/14 17:51:48	2.196
--- compile.c	2001/05/23 12:11:35	2.196.2.1
***************
*** 4070,4074 ****
  
  static int
! symtable_resolve_free(struct compiling *c, PyObject *name, 
  		      struct symbol_info *si)
  {
--- 4070,4074 ----
  
  static int
! symtable_resolve_free(struct compiling *c, PyObject *name, int flags,
  		      struct symbol_info *si)
  {
***************
*** 4080,4088 ****
  	   method and a free variable with the same name.
  	*/
- 
  	if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) {
  		v = PyInt_FromLong(si->si_ncells++);
  		dict = c->c_cellvars;
  	} else {
  		v = PyInt_FromLong(si->si_nfrees++);
  		dict = c->c_freevars;
--- 4080,4096 ----
  	   method and a free variable with the same name.
  	*/
  	if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) {
+ 		/* If it isn't declared locally, it can't be a cell. */
+ 		if (!(flags & (DEF_LOCAL | DEF_PARAM)))
+ 			return 0;
  		v = PyInt_FromLong(si->si_ncells++);
  		dict = c->c_cellvars;
  	} else {
+ 		/* If it is free anyway, then there is no need to do
+ 		   anything here.
+ 		*/
+ 		if (is_free(flags ^ DEF_FREE_CLASS) 
+ 		    || flags == DEF_FREE_CLASS)
+ 			return 0;
  		v = PyInt_FromLong(si->si_nfrees++);
  		dict = c->c_freevars;
***************
*** 4370,4377 ****
  		*/
  		if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
! 		    if ((ste->ste_type == TYPE_CLASS 
! 			 && flags != DEF_FREE_CLASS)
! 			|| (flags & (DEF_LOCAL | DEF_PARAM)))
! 			symtable_resolve_free(c, name, &si);
  		}
  
--- 4378,4382 ----
  		*/
  		if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
! 			symtable_resolve_free(c, name, flags, &si);
  		}
  
***************
*** 4432,4435 ****
--- 4437,4449 ----
  		}
  	}
+ 
+ 	/*
+ 	fprintf(stderr, 
+ 		"cells %d: %s\n"
+ 		"frees %d: %s\n",
+ 		si.si_ncells, PyObject_REPR(c->c_cellvars),
+ 		si.si_nfrees, PyObject_REPR(c->c_freevars));
+ 	*/
+ 	assert(PyDict_Size(c->c_freevars) == si.si_nfrees);
  
  	if (si.si_ncells > 1) { /* one cell is always in order */