[Python-checkins] CVS: python/dist/src/Python compile.c,2.187,2.188

Jeremy Hylton jhylton@users.sourceforge.net
Mon, 19 Mar 2001 16:25:46 -0800


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

Modified Files:
	compile.c 
Log Message:
Fixup handling of free variables in methods when the class scope also
has a binding for the name.  The fix is in two places:

  - in symtable_update_free_vars, ignore a global stmt in a class scope
  - in symtable_load_symbols, add extra handling for names that are
    defined at class scope and free in a method

Closes SF bug 407800
    


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.187
retrieving revision 2.188
diff -C2 -r2.187 -r2.188
*** compile.c	2001/03/19 20:38:06	2.187
--- compile.c	2001/03/20 00:25:43	2.188
***************
*** 3809,3812 ****
--- 3809,3813 ----
  		i = PyInt_AS_LONG(v);
  		Py_INCREF(k);
+ 		assert((i - offset) < size);
  		PyTuple_SET_ITEM(tuple, i - offset, k);
  	}
***************
*** 4317,4323 ****
  			flags &= ~(DEF_FREE | DEF_FREE_CLASS);
  
! 		if ((flags & (DEF_FREE | DEF_FREE_CLASS))
! 		    && (flags & (DEF_LOCAL | DEF_PARAM)))
  			symtable_resolve_free(c, name, &si);
  
  		if (flags & DEF_STAR) {
--- 4318,4332 ----
  			flags &= ~(DEF_FREE | DEF_FREE_CLASS);
  
! 		/* Deal with names that need two actions:
! 		   1. Cell variables, which are also locals.
! 		   2. Free variables in methods that are also class
! 		   variables or declared global.
! 		*/
! 		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);
+ 		}
  
  		if (flags & DEF_STAR) {
***************
*** 4479,4483 ****
  			   is global in B.
  			*/
! 			if (v) {
  				int flags = PyInt_AS_LONG(v); 
  				if (flags & DEF_GLOBAL) {
--- 4488,4492 ----
  			   is global in B.
  			*/
! 			if (v && (ste->ste_type != TYPE_CLASS)) {
  				int flags = PyInt_AS_LONG(v); 
  				if (flags & DEF_GLOBAL) {