summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-05-08 04:12:34 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-05-08 04:12:34 (GMT)
commit9c90105cb000dbda5dead81732322a27b62319bb (patch)
tree13ae32fe8c0cb935fbbcedd7175e0c3ae0c769d2 /Python
parent4c889011db22df761709ac8f9bc246bf4931e9c4 (diff)
downloadcpython-9c90105cb000dbda5dead81732322a27b62319bb.zip
cpython-9c90105cb000dbda5dead81732322a27b62319bb.tar.gz
cpython-9c90105cb000dbda5dead81732322a27b62319bb.tar.bz2
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?
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 1f1d44c..9f215f2 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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);