Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de>
Branch: py3.5
Changeset: r94691:26a7e1a30293
Date: 2018-05-27 17:27 +0200
http://bitbucket.org/pypy/pypy/changeset/26a7e1a30293/

Log:    fix issue #2838: don't swallow exceptions in BUILD_SET_UNPACK

        (the bytecode was quite badly broken in other ways too: the JIT
        would unroll the set generation completely}

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1433,21 +1433,12 @@
     @jit.unroll_safe
     def BUILD_SET_UNPACK(self, itemcount, next_instr):
         space = self.space
-        w_sum = space.newset()
+        w_set = space.newset()
         for i in range(itemcount, 0, -1):
             w_item = self.peekvalue(i-1)
-            # cannot use w_sum.update, w_item might not be a set
-            iterator = space.iter(w_item)
-            while True:
-                try:
-                    w_value = space.next(iterator)
-                except OperationError:
-                    break
-                w_sum.add(w_value)
-        while itemcount != 0:
-            self.popvalue()
-            itemcount -= 1
-        self.pushvalue(w_sum)
+            space.call_method(w_set, "update", w_item)
+        self.popvalues(itemcount)
+        self.pushvalue(w_set)
 
     @jit.unroll_safe
     def list_unpack_helper(frame, itemcount):
diff --git a/pypy/interpreter/test/test_interpreter.py 
b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -265,7 +265,7 @@
             return a, b, c, d
         """
         assert self.codetest(code, "f", [1, 2], {"d" : 4, "c" : 3}) == (1, 2, 
3, 4)
-    
+
     def test_build_set_unpack(self):
         code = """ def f():
             return {*range(4), 4, *(5, 6, 7)}
@@ -274,13 +274,28 @@
         res = self.codetest(code, "f", [])
         l_res = space.call_function(space.w_list, res)
         assert space.unwrap(l_res) == [0, 1, 2, 3, 4, 5, 6, 7]
-        
+
+    def test_build_set_unpack_exception(self):
+        code = """ if 1:
+        def g():
+            yield 1
+            yield 2
+            raise TypeError
+        def f():
+            try:
+                {*g(), 1, 2}
+            except TypeError:
+                return True
+            return False
+        """
+        assert self.codetest(code, "f", [])
+
     def test_build_tuple_unpack(self):
         code = """ def f():
             return (*range(4), 4)
         """
         assert self.codetest(code, "f", []) == (0, 1, 2, 3, 4)
-    
+
     def test_build_list_unpack(self):
         code = """ def f():
             return [*range(4), 4]
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to