Index: Python/peephole.c =================================================================== --- Python/peephole.c (revision 61073) +++ Python/peephole.c (working copy) @@ -313,7 +313,7 @@ goto exitUnchanged; /* Make a modifiable copy of the code string */ - codestr = (unsigned char *)PyMem_Malloc(codelen); + codestr = (unsigned char *)PyMem_Malloc(codelen + 1); if (codestr == NULL) goto exitUnchanged; codestr = (unsigned char *)memcpy(codestr, @@ -325,7 +325,7 @@ looking beyond the end of the code string. */ if (codestr[codelen-1] != RETURN_VALUE) - goto exitUnchanged; + codestr[codelen] = RETURN_VALUE; /* Mapping to new jump targets after NOPs are removed */ addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); @@ -550,17 +550,22 @@ case EXTENDED_ARG: goto exitUnchanged; - /* Replace RETURN LOAD_CONST None RETURN with just RETURN */ - /* Remove unreachable JUMPs after RETURN */ + /* Remove unreachable code completely */ +#if 0 + /* These are handled differently above */ + case CONTINUE_LOOP: + case JUMP_FORWARD: + case JUMP_ABSOLUTE: +#endif + case RAISE_VARARGS: + case BREAK_LOOP: case RETURN_VALUE: - if (i+4 >= codelen) - continue; - if (codestr[i+4] == RETURN_VALUE && - ISBASICBLOCK(blocks,i,5)) - memset(codestr+i+1, NOP, 4); - else if (UNCONDITIONAL_JUMP(codestr[i+1]) && - ISBASICBLOCK(blocks,i,4)) - memset(codestr+i+1, NOP, 3); + j = i + CODESIZE(codestr[i]); + tgt = j; + while (tgt < codelen && blocks[tgt] == blocks[i]) + tgt += CODESIZE(codestr[tgt]); + if (tgt > j) + memset(codestr+j, NOP, tgt-j); break; } }