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

Jeremy Hylton jhylton@users.sourceforge.net
Mon, 07 May 2001 21:12:36 -0700


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

Modified Files:
	compile.c 
Log Message:
Several small changes.  Mostly reformatting, adding parens.  

Check for free in class and method only if nested scopes are enabled.

Add assertion to verify that no free variables occur when nested
scopes are disabled.

XXX When should nested scopes by made non-optional on the trunk?




Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.198
retrieving revision 2.199
diff -C2 -r2.198 -r2.199
*** compile.c	2001/04/27 02:29:40	2.198
--- compile.c	2001/05/08 04:12:34	2.199
***************
*** 4079,4083 ****
  		*/
  		if (is_free(flags ^ DEF_FREE_CLASS) 
! 		    || flags == DEF_FREE_CLASS)
  			return 0;
  		v = PyInt_FromLong(si->si_nfrees++);
--- 4079,4083 ----
  		*/
  		if (is_free(flags ^ DEF_FREE_CLASS) 
! 		    || (flags == DEF_FREE_CLASS))
  			return 0;
  		v = PyInt_FromLong(si->si_nfrees++);
***************
*** 4261,4264 ****
--- 4261,4265 ----
  	if (!(flags & DEF_BOUND))
  		return 0;
+ 
  	/* The semantics of this code will change with nested scopes.
  	   It is defined in the current scope and referenced in a
***************
*** 4365,4370 ****
  		   variables or declared global.
  		*/
! 		if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
  			symtable_resolve_free(c, name, flags, &si);
  		}
  
--- 4366,4373 ----
  		   variables or declared global.
  		*/
! 		if (st->st_nested_scopes) {
! 		    if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
  			symtable_resolve_free(c, name, flags, &si);
+ 		    }
  		}
  
***************
*** 4426,4438 ****
  	}
  
- 	/*
- 	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 */
  		if (symtable_cellvar_offsets(&c->c_cellvars, c->c_argcount,
--- 4429,4437 ----
  	}
  
  	assert(PyDict_Size(c->c_freevars) == si.si_nfrees);
  
+ 	if (st->st_nested_scopes == 0)
+ 		assert(si.si_nfrees == 0);
+ 
  	if (si.si_ncells > 1) { /* one cell is always in order */
  		if (symtable_cellvar_offsets(&c->c_cellvars, c->c_argcount,
***************
*** 4539,4543 ****
  			   indirectly) in A and there are no scopes
  			   with bindings for N between B and A, then N
! 			   is global in B.
  			*/
  			if (v && (ste->ste_type != TYPE_CLASS)) {
--- 4538,4544 ----
  			   indirectly) in A and there are no scopes
  			   with bindings for N between B and A, then N
! 			   is global in B.  Unless A is a class scope,
! 			   because class scopes are not considered for
! 			   nested scopes.
  			*/
  			if (v && (ste->ste_type != TYPE_CLASS)) {