diff -r b7b805e05978 Python/peephole.c --- a/Python/peephole.c Wed Mar 09 19:01:04 2011 -0500 +++ b/Python/peephole.c Thu Mar 10 20:07:34 2011 -0500 @@ -328,6 +328,128 @@ return 1; } +/* Fixup line numbers, remove NOPs and unused constants. */ +static Py_ssize_t +fixup_code(unsigned char *codestr, Py_ssize_t codelen, PyObject* consts, PyObject *lineno_obj) +{ + Py_ssize_t i, j, tabsiz, pos, numconst; + int nops, adj, opcode; + int new_line, cum_orig_line, last_line; + unsigned char *lineno; + int *addrmap=NULL, *constuse=NULL; + + /* Mapping to new jump targets after NOPs are removed. */ + addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); + if (addrmap == NULL) + goto exitError; + + /* Table to record use and remapping of consts. */ + numconst = PyList_GET_SIZE(consts); + constuse = (int *)PyMem_Malloc(numconst * sizeof(int)); + if (constuse == NULL) + goto exitError; + memset(constuse, 0, numconst * sizeof(int)); + /* First constant is a docstring. */ + if (numconst > 0) + constuse[0] = 1; + + /* Fixup linenotab and record const use. */ + for (i=0, nops=0; i 0 ? pos : -1; +#else + constuse[i] = pos; +#endif + pos += j; + } + + /* Remove NOPs, fixup jump targets and remap consts. */ + for (i=0, pos=0; i