mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
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.
This commit is contained in:
parent
4ffedadb10
commit
0cbd805a10
3 changed files with 25 additions and 2 deletions
|
@ -61,6 +61,23 @@ nlocals: 1
|
||||||
flags: 67
|
flags: 67
|
||||||
consts: ('None',)
|
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):
|
def consts(t):
|
||||||
|
|
|
@ -17,6 +17,10 @@ Core and builtins
|
||||||
magic number. This means that .pyc files generated before 2.5c1
|
magic number. This means that .pyc files generated before 2.5c1
|
||||||
will be regenerated.
|
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
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -2745,11 +2745,13 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
|
||||||
case Global_kind:
|
case Global_kind:
|
||||||
break;
|
break;
|
||||||
case Expr_kind:
|
case Expr_kind:
|
||||||
VISIT(c, expr, s->v.Expr.value);
|
|
||||||
if (c->c_interactive && c->c_nestlevel <= 1) {
|
if (c->c_interactive && c->c_nestlevel <= 1) {
|
||||||
|
VISIT(c, expr, s->v.Expr.value);
|
||||||
ADDOP(c, PRINT_EXPR);
|
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);
|
ADDOP(c, POP_TOP);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue