mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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).
This commit is contained in:
parent
467024ccfc
commit
07359a7fed
1 changed files with 8 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue