]> granicus.if.org Git - python/commitdiff
Issue 11510: Fix BUILD_SET optimizer bug.
authorRaymond Hettinger <python@rcn.com>
Tue, 15 Mar 2011 21:50:16 +0000 (14:50 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 15 Mar 2011 21:50:16 +0000 (14:50 -0700)
Lib/test/test_peepholer.py
Misc/NEWS
Python/peephole.c

index 531b42507752175a98435157c1183c9b7847207a..b7d446fdd07e537028bb1bc499fd3c52f1cd84fa 100644 (file)
@@ -267,11 +267,23 @@ class TestTranforms(unittest.TestCase):
         asm = disassemble(f)
         self.assertNotIn('BINARY_ADD', asm)
 
+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 8b72498f68a446bf116ba9ea7557f7d84fd5c97a..42330ff40da859ec642396b0833f0aef035b13c8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2.1?
 Core and Builtins
 -----------------
 
+- Issue #11510: Fixed optimizer bug which turned "a,b={1,1}" into "a,b=(1,1)".
+
 - Issue #11432: A bug was introduced in subprocess.Popen on posix systems with
   3.2.0 where the stdout or stderr file descriptor being the same as the stdin
   file descriptor would raise an exception. webbrowser.open would fail. fixed.
index f972e1611e662969a485654268e1ecd14ebcb163..69850439171e071afbed72c0799cdf5519ac7920 100644 (file)
@@ -475,7 +475,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);