[Python-checkins] r51081 - in python/trunk: Lib/test/test_code.py Misc/NEWS Python/compile.c

neal.norwitz python-checkins at python.org
Fri Aug 4 07:09:32 CEST 2006


Author: neal.norwitz
Date: Fri Aug  4 07:09:28 2006
New Revision: 51081

Modified:
   python/trunk/Lib/test/test_code.py
   python/trunk/Misc/NEWS
   python/trunk/Python/compile.c
Log:
Bug #1333982: string/number constants were inappropriately stored
in the byte code and co_consts even if they were not used, ie
immediately popped off the stack.


Modified: python/trunk/Lib/test/test_code.py
==============================================================================
--- python/trunk/Lib/test/test_code.py	(original)
+++ python/trunk/Lib/test/test_code.py	Fri Aug  4 07:09:28 2006
@@ -61,6 +61,23 @@
 flags: 67
 consts: ('None',)
 
+>>> def optimize_away():
+...     'doc string'
+...     'not a docstring'
+...     53
+...     53L
+
+>>> dump(optimize_away.func_code)
+name: optimize_away
+argcount: 0
+names: ()
+varnames: ()
+cellvars: ()
+freevars: ()
+nlocals: 0
+flags: 67
+consts: ("'doc string'", 'None')
+
 """
 
 def consts(t):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Aug  4 07:09:28 2006
@@ -17,6 +17,10 @@
   magic number.  This means that .pyc files generated before 2.5c1
   will be regenerated.
 
+- Bug #1333982: string/number constants were inappropriately stored
+  in the byte code and co_consts even if they were not used, ie
+  immediately popped off the stack.
+
 
 Library
 -------

Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c	(original)
+++ python/trunk/Python/compile.c	Fri Aug  4 07:09:28 2006
@@ -2745,11 +2745,13 @@
 	case Global_kind:
 		break;
 	case Expr_kind:
-		VISIT(c, expr, s->v.Expr.value);
 		if (c->c_interactive && c->c_nestlevel <= 1) {
+			VISIT(c, expr, s->v.Expr.value);
 			ADDOP(c, PRINT_EXPR);
 		}
-		else {
+		else if (s->v.Expr.value->kind != Str_kind &&
+			 s->v.Expr.value->kind != Num_kind) {
+			VISIT(c, expr, s->v.Expr.value);
 			ADDOP(c, POP_TOP);
 		}
 		break;


More information about the Python-checkins mailing list