From: Raymond Hettinger Date: Tue, 26 Oct 2004 08:59:14 +0000 (+0000) Subject: SF bug #1053819: Segfault in tuple_of_constants X-Git-Tag: v2.4b2~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=23109ef11e91c49b56b517ce454bcf87a4153c62;p=python SF bug #1053819: Segfault in tuple_of_constants Peepholer could be fooled into misidentifying a tuple_of_constants. Added code to count consecutive occurrences of LOAD_CONST. Use the count to weed out the misidentified cases. Added a unittest. --- diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index 913f805e12..934b57c1e8 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -83,6 +83,23 @@ class TestTranforms(unittest.TestCase): self.assert_(elem in asm) self.assert_('BUILD_TUPLE' not in asm) + # Bug 1053819: Tuple of constants misidentified when presented with: + # . . . opcode_with_arg 100 unary_opcode BUILD_TUPLE 1 . . . + # The following would segfault upon compilation + def crater(): + (~[ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + ],) + def test_elim_extra_return(self): # RETURN LOAD_CONST None RETURN --> RETURN def f(x): diff --git a/Python/compile.c b/Python/compile.c index dfb94d38e3..37793caaac 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -419,15 +419,16 @@ tuple_of_constants(unsigned char *codestr, int n, PyObject *consts) newconst = PyTuple_New(n); if (newconst == NULL) return 0; + len_consts = PyList_GET_SIZE(consts); for (i=0 ; i= 0 && + j == lastlc && codestr[h] == LOAD_CONST && ISBASICBLOCK(blocks, h, 3*(j+1)) && tuple_of_constants(&codestr[h], j, consts)) {