diff options
author | Guido van Rossum <guido@python.org> | 2007-02-26 21:23:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-02-26 21:23:50 (GMT) |
commit | 0240b92a6c3a17fac38d93ee80fc8e8523388786 (patch) | |
tree | 8434f85d5b00ca30cc2fad24082ba454a43a4409 /Python/peephole.c | |
parent | f74225d63b84a4d3b508fd5657cfe2596633876a (diff) | |
download | cpython-0240b92a6c3a17fac38d93ee80fc8e8523388786.zip cpython-0240b92a6c3a17fac38d93ee80fc8e8523388786.tar.gz cpython-0240b92a6c3a17fac38d93ee80fc8e8523388786.tar.bz2 |
Two more patches by Tony Lownds (SF# 1607548).
(1)
Combines the code paths for MAKE_FUNCTION and MAKE_CLOSURE.
Fixes a crash where functions with closures and either annotations or
keyword-only arguments result in MAKE_CLOSURE, but only
MAKE_FUNCTION has the code to handle annotations or keyword-only
arguments.
Includes enough tests to trigger the bug.
(2)
Change peepholer to not bail in the presence of EXTENDED_ARG +
MAKE_FUNCTION.
Enforce the natural 16-bit limit of annotations in compile.c.
Also update Misc/NEWS with the "input = raw_input" change.
Diffstat (limited to 'Python/peephole.c')
-rw-r--r-- | Python/peephole.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index 28e4c4c..f2e0c0b 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -261,10 +261,12 @@ markblocks(unsigned char *code, int len) The consts object should still be in list form to allow new constants to be appended. - To keep the optimizer simple, it bails out (does nothing) for code - containing extended arguments or that has a length over 32,700. That - allows us to avoid overflow and sign issues. Likewise, it bails when - the lineno table has complex encoding for gaps >= 255. + To keep the optimizer simple, it bails out (does nothing) for code that + has a length over 32,700, and does not calculate extended arguments. + That allows us to avoid overflow and sign issues. Likewise, it bails when + the lineno table has complex encoding for gaps >= 255. EXTENDED_ARG can + appear before MAKE_FUNCTION; in this case both opcodes are skipped. + EXTENDED_ARG preceding any other opcode causes the optimizer to bail. Optimizations are restricted to simple transformations occuring within a single basic block. All transformations keep the code size the same or @@ -535,7 +537,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, break; case EXTENDED_ARG: - goto exitUnchanged; + if (codestr[i+3] != MAKE_FUNCTION) + goto exitUnchanged; + /* don't visit MAKE_FUNCTION as GETARG will be wrong */ + i += 3; + break; /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ /* Remove unreachable JUMPs after RETURN */ |