From 0661e91feda0757c10c8b3bf3fa047b7d3e50444 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:03:36 -0700 Subject: [PATCH 1/3] Issue 11510: Fix BUILD_SET optimizer bug. --- Lib/test/test_peepholer.py | 14 +++++++++++++- Python/peephole.c | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index a9eb23fde31..a40b4b7a01f 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -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 diff --git a/Python/peephole.c b/Python/peephole.c index ab96ce9def2..4bc65dcc312 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -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); From f932f747e6242c7de88864798e845135d9d981c9 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:06:09 -0700 Subject: [PATCH 2/3] whitespace fix --- Lib/test/test_peepholer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index a40b4b7a01f..bab4c1e5d9d 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -19,6 +19,7 @@ def disassemble(func): def dis_single(line): return disassemble(compile(line, '', 'single')) + class TestTranforms(unittest.TestCase): def test_unot(self): From 5bd75b87263bc6502753381138e15531ce4574a6 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 15 Mar 2011 15:07:38 -0700 Subject: [PATCH 3/3] whitespace fix --- Lib/test/test_peepholer.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index bab4c1e5d9d..f73565eb46f 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -297,15 +297,15 @@ class TestTranforms(unittest.TestCase): 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_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):