]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Document how the pattern recognizer keeps all of its references in bounds.
authorRaymond Hettinger <python@rcn.com>
Mon, 21 Feb 2005 20:03:14 +0000 (20:03 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 21 Feb 2005 20:03:14 +0000 (20:03 +0000)
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).

Python/compile.c

index b458f7319a60aca7064b2cc480d92fe66dfee6d9..6e68d0fd5da6cee5ab4134c7acc9bc0d293a19aa 100644 (file)
@@ -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)