diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-04 05:09:28 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-04 05:09:28 (GMT) |
commit | 0cbd805a10b91f803bccbb5a54f8e54c2e40e9e8 (patch) | |
tree | 62229621195dcaf1c38378924227066697ef8643 | |
parent | 4ffedadb1032a4310e756d476310d056ad209310 (diff) | |
download | cpython-0cbd805a10b91f803bccbb5a54f8e54c2e40e9e8.zip cpython-0cbd805a10b91f803bccbb5a54f8e54c2e40e9e8.tar.gz cpython-0cbd805a10b91f803bccbb5a54f8e54c2e40e9e8.tar.bz2 |
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.
-rw-r--r-- | Lib/test/test_code.py | 17 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Python/compile.c | 6 |
3 files changed, 25 insertions, 2 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 52bc894..4e68638 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -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): @@ -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 ------- diff --git a/Python/compile.c b/Python/compile.c index 755531e..6a9e8c9 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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; |