[Python-checkins] r70117 - in python/branches/py3k/Python: compile.c symtable.c

benjamin.peterson python-checkins at python.org
Tue Mar 3 01:54:05 CET 2009


Author: benjamin.peterson
Date: Tue Mar  3 01:54:05 2009
New Revision: 70117

Log:
instead of hacking __locals__ in during bytecode generation, put it in the symtable

Modified:
   python/branches/py3k/Python/compile.c
   python/branches/py3k/Python/symtable.c

Modified: python/branches/py3k/Python/compile.c
==============================================================================
--- python/branches/py3k/Python/compile.c	(original)
+++ python/branches/py3k/Python/compile.c	Tue Mar  3 01:54:05 2009
@@ -1524,23 +1524,14 @@
 static int
 compiler_class(struct compiler *c, stmt_ty s)
 {
-	static PyObject *locals = NULL;
 	PyCodeObject *co;
 	PyObject *str;
-	PySTEntryObject *ste;
-	int err, i;
+	int i;
 	asdl_seq* decos = s->v.ClassDef.decorator_list;
 
         if (!compiler_decorators(c, decos))
                 return 0;
 
-	/* initialize statics */
-	if (locals == NULL) {
-		locals = PyUnicode_InternFromString("__locals__");
-		if (locals == NULL)
-			return 0;
-	}
-
 	/* ultimately generate code for:
 	     <name> = __build_class__(<func>, <name>, *<bases>, **<keywords>)
 	   where:
@@ -1553,16 +1544,6 @@
 	   This borrows from compiler_call.
 	*/
 
-	/* 0. Create a fake argument named __locals__ */
-	ste = PySymtable_Lookup(c->c_st, s);
-	if (ste == NULL)
-		return 0;
-	assert(PyList_Check(ste->ste_varnames));
-	err = PyList_Append(ste->ste_varnames, locals);
-	Py_DECREF(ste);
-	if (err < 0)
-		return 0;
-
 	/* 1. compile the class body into a code object */
 	if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s, s->lineno))
 		return 0;

Modified: python/branches/py3k/Python/symtable.c
==============================================================================
--- python/branches/py3k/Python/symtable.c	(original)
+++ python/branches/py3k/Python/symtable.c	Tue Mar  3 01:54:05 2009
@@ -186,7 +186,8 @@
 
 
 static identifier top = NULL, lambda = NULL, genexpr = NULL,
-    listcomp = NULL, setcomp = NULL, dictcomp = NULL, __class__ = NULL;
+	listcomp = NULL, setcomp = NULL, dictcomp = NULL,
+	__class__ = NULL, __locals__ = NULL;
 
 #define GET_IDENTIFIER(VAR) \
 	((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
@@ -1050,7 +1051,9 @@
 					  (void *)s, s->lineno))
 			return 0;
 		if (!GET_IDENTIFIER(__class__) ||
-		    !symtable_add_def(st, __class__, DEF_LOCAL)) {
+		    !symtable_add_def(st, __class__, DEF_LOCAL) ||
+		    !GET_IDENTIFIER(__locals__) ||
+		    !symtable_add_def(st, __locals__, DEF_PARAM)) {
 			symtable_exit_block(st, s);
 			return 0;
 		}


More information about the Python-checkins mailing list