]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 11510: Fix BUILD_SET optimizer bug.
authorRaymond Hettinger <python@rcn.com>
Tue, 15 Mar 2011 22:03:36 +0000 (15:03 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 15 Mar 2011 22:03:36 +0000 (15:03 -0700)
Lib/test/test_peepholer.py
Python/peephole.c

index a9eb23fde316df8758a9e4af6df883a04c739ba5..a40b4b7a01f5f4954d02ba213df490d120179da3 100644 (file)
@@ -294,11 +294,23 @@ class TestTranforms(unittest.TestCase):
             self.assertNotIn('BINARY_', asm, e)
             self.assertNotIn('BUILD_', asm, e)
 
+class TestBuglets(unittest.TestCase):
+
+     def test_bug_11510(self):
+         # folded constant set optimization was commingled with the tuple
+         # unpacking optimization which would fail if the set had duplicate
+         # elements so that the set length was unexpected
+         def f():
+             x, y = {1, 1}
+             return x, y
+         with self.assertRaises(ValueError):
+             f()
+
 
 def test_main(verbose=None):
     import sys
     from test import support
-    test_classes = (TestTranforms,)
+    test_classes = (TestTranforms, TestBuglets)
     support.run_unittest(*test_classes)
 
     # verify reference counting
index ab96ce9def2edf7ed7bcbf1b0b01f377deec4b10..4bc65dcc312b2dbd77137c42d86083b639ab0f0e 100644 (file)
@@ -535,7 +535,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
                 }
                 if (codestr[i+3] != UNPACK_SEQUENCE  ||
                     !ISBASICBLOCK(blocks,i,6) ||
-                    j != GETARG(codestr, i+3))
+                    j != GETARG(codestr, i+3) ||
+                    opcode == BUILD_SET)
                     continue;
                 if (j == 1) {
                     memset(codestr+i, NOP, 6);