diff Python/compile.c @ 34626:fcacf9d4b8f0 legacy-trunk

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).
author Raymond Hettinger <python@rcn.com>
date Mon, 21 Feb 2005 20:03:14 +0000
parents 516bb8fd75b4
children 660419bdb4ae
line wrap: on
line diff
--- a/Python/compile.c	Mon Feb 21 15:46:52 2005 +0000
+++ b/Python/compile.c	Mon Feb 21 20:03:14 2005 +0000
@@ -677,6 +677,14 @@
 		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)