]> granicus.if.org Git - python/commitdiff
Bug #1333982: string/number constants were inappropriately stored
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 4 Aug 2006 05:09:28 +0000 (05:09 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 4 Aug 2006 05:09:28 +0000 (05:09 +0000)
in the byte code and co_consts even if they were not used, ie
immediately popped off the stack.

Lib/test/test_code.py
Misc/NEWS
Python/compile.c

index 52bc8948b9872cd4f664d7a2a6015fec06e25114..4e6863856988fd88669391b0a30a8f7a835d095e 100644 (file)
@@ -61,6 +61,23 @@ nlocals: 1
 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):
index 6a315354794286edb351b7a636ede7801caea078..c4904da764090f6c494012f66e3618410f00ae68 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,10 @@ Core and builtins
   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
 -------
index 755531ed428a80fb75b6b5b43c251092ea0e481e..6a9e8c9f7e599bc3c80680659d6808f6368dfa8d 100644 (file)
@@ -2745,11 +2745,13 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
        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;