[Python-checkins] python/dist/src/Include symtable.h,,

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Tue Oct 11 21:18:14 CEST 2005

Update of /cvsroot/python/python/dist/src/Include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20508/Include

Modified Files:
      Tag: ast-branch
Log Message:
Fix symbol table to catch several scoping syntax errors.

It's illegal to mix import * or bare exec with nested scopes, because
there is no unambiguous way to decide whether to treat variables are
free variables or globals.  The symbol table change a bit to detect
these errors.

ste_optimized was renamed ste_unoptimized, to match its use: It
contains a non-zero value with an unoptimized namespace
(e.g. LOAD_NAME) will be used.  Since the top-level uses LOAD_NAME,
added OPT_TOPLEVEL along with the other OPT_ defines.

Add an ste_free flag as a cheap way to tell if a block has free
variables, including those inherited from children.  Actually compute
ste_free_child and ste_opt_lineno.

Track rename of ste_optimized to ste_unoptimized in symbol table and

Fixes test_scope.

Index: symtable.h
RCS file: /cvsroot/python/python/dist/src/Include/symtable.h,v
retrieving revision
retrieving revision
diff -u -d -r2.9.18.12 -r2.9.18.13
--- symtable.h	9 Jan 2005 18:49:43 -0000
+++ symtable.h	11 Oct 2005 19:18:11 -0000
@@ -30,8 +30,9 @@
 	PyObject *ste_varnames;  /* list of variable names */
 	PyObject *ste_children;  /* list of child ids */
 	block_ty ste_type;       /* module, class, or function */
-	int ste_optimized : 1;   /* true if namespace can be optimized */
+	int ste_unoptimized;     /* false if namespace is optimized */
 	int ste_nested : 1;      /* true if block is nested */
+	int ste_free : 1;        /* true if block has free variables */
 	int ste_child_free : 1;  /* true if a child block has free variables,
 				    including free refs to globals */
 	int ste_generator : 1;   /* true if namespace is a generator */
@@ -86,9 +87,11 @@
 #define FREE 4
 #define CELL 5
+/* The following three names are used for the ste_unoptimized bit field */
 #define OPT_IMPORT_STAR 1
 #define OPT_EXEC 2
 #define OPT_BARE_EXEC 4
+#define OPT_TOPLEVEL 8  /* top-level names, including eval and exec */
 #define GENERATOR 1

More information about the Python-checkins mailing list