diff options
author | Raymond Hettinger <python@rcn.com> | 2005-02-21 20:03:14 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-02-21 20:03:14 (GMT) |
commit | 07359a7fed6236537e45a7f381560193274956bd (patch) | |
tree | 297687ba49165aa0a7824b05e9806c7078432b28 /Python | |
parent | 467024ccfc219866ff0b90135493d7bda0f2a841 (diff) | |
download | cpython-07359a7fed6236537e45a7f381560193274956bd.zip cpython-07359a7fed6236537e45a7f381560193274956bd.tar.gz cpython-07359a7fed6236537e45a7f381560193274956bd.tar.bz2 |
Document how the pattern recognizer keeps all of its references in bounds.
Add a test in case the underlying assumptions ever change (i.e. the
compiler starts generating code blocks that are not punctuated by
RETURN_VALUE).
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c index b458f73..6e68d0f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -677,6 +677,14 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen goto exitUnchanged; codestr = memcpy(codestr, PyString_AS_STRING(code), codelen); + /* Verify that RETURN_VALUE terminates the codestring. This allows + the various transformation patterns to look ahead several + instructions without additional checks to make sure they are not + looking beyond the end of the code string. + */ + if (codestr[codelen-1] != RETURN_VALUE) + goto exitUnchanged; + /* Mapping to new jump targets after NOPs are removed */ addrmap = PyMem_Malloc(codelen * sizeof(int)); if (addrmap == NULL) |