]> granicus.if.org Git - python/commitdiff
Several small changes. Mostly reformatting, adding parens.
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 8 May 2001 04:12:34 +0000 (04:12 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 8 May 2001 04:12:34 +0000 (04:12 +0000)
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?

Python/compile.c

index 1f1d44c9ff030dbebdbf02bd38aaa390fc74a601..9f215f2748b5762683dae508e50fca644590b139 100644 (file)
@@ -4078,7 +4078,7 @@ symtable_resolve_free(struct compiling *c, PyObject *name, int flags,
                   anything here.
                */
                if (is_free(flags ^ DEF_FREE_CLASS) 
-                   || flags == DEF_FREE_CLASS)
+                   || (flags == DEF_FREE_CLASS))
                        return 0;
                v = PyInt_FromLong(si->si_nfrees++);
                dict = c->c_freevars;
@@ -4260,6 +4260,7 @@ symtable_check_shadow(struct symtable *st, PyObject *name, int flags)
 
        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
           child scope.  Under the old rules, the child will see a
@@ -4364,8 +4365,10 @@ symtable_load_symbols(struct compiling *c)
                   2. Free variables in methods that are also class
                   variables or declared global.
                */
-               if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
+               if (st->st_nested_scopes) {
+                   if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
                        symtable_resolve_free(c, name, flags, &si);
+                   }
                }
 
                if (flags & DEF_STAR) {
@@ -4425,15 +4428,11 @@ symtable_load_symbols(struct compiling *c)
                }
        }
 
-       /*
-       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 (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,
                                             c->c_varnames, c->c_flags) < 0)
@@ -4538,7 +4537,9 @@ symtable_update_free_vars(struct symtable *st)
                           referenced in scope B contained (perhaps
                           indirectly) in A and there are no scopes
                           with bindings for N between B and A, then N
-                          is global in B.
+                          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)) {
                                int flags = PyInt_AS_LONG(v);