diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-06-13 18:16:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-13 18:16:22 (GMT) |
commit | 3498c642f4e83f3d8e2214654c0fa8e0d51cebe5 (patch) | |
tree | 07d51da51f406a38f216a877838af3902b1161f0 /Python/peephole.c | |
parent | 95492032c48fef20b9c7076a23fe7e46927a4688 (diff) | |
download | cpython-3498c642f4e83f3d8e2214654c0fa8e0d51cebe5.zip cpython-3498c642f4e83f3d8e2214654c0fa8e0d51cebe5.tar.gz cpython-3498c642f4e83f3d8e2214654c0fa8e0d51cebe5.tar.bz2 |
bpo-37213: Handle negative line deltas correctly in the peephole optimizer (GH-13969)
The peephole optimizer was not optimizing correctly bytecode after negative deltas were introduced. This is due to the fact that some special values (255) were being searched for in both instruction pointer delta and line number deltas.
Diffstat (limited to 'Python/peephole.c')
-rw-r--r-- | Python/peephole.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index 1ce3535..6f3e2ed 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -250,12 +250,16 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, lnotab = (unsigned char*)PyBytes_AS_STRING(lnotab_obj); tabsiz = PyBytes_GET_SIZE(lnotab_obj); assert(tabsiz == 0 || Py_REFCNT(lnotab_obj) == 1); - if (memchr(lnotab, 255, tabsiz) != NULL) { - /* 255 value are used for multibyte bytecode instructions */ - goto exitUnchanged; + + /* Don't optimize if lnotab contains instruction pointer delta larger + than +255 (encoded as multiple bytes), just to keep the peephole optimizer + simple. The optimizer leaves line number deltas unchanged. */ + + for (j = 0; j < tabsiz; j += 2) { + if (lnotab[j] == 255) { + goto exitUnchanged; + } } - /* Note: -128 and 127 special values for line number delta are ok, - the peephole optimizer doesn't modify line numbers. */ assert(PyBytes_Check(code)); Py_ssize_t codesize = PyBytes_GET_SIZE(code); |