fix sequence assignments for value coercion to non-Python types
authorStefan Behnel <scoder@users.berlios.de>
Fri, 21 Nov 2008 11:07:26 +0000 (12:07 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 21 Nov 2008 11:07:26 +0000 (12:07 +0100)
- coercion code cannot currently be taken out of the conditional as the temp release of the coercion code happens straight away

Cython/Compiler/ExprNodes.py
tests/run/tupleassign.pyx

index 2f4560e96588d0f84527e2a238e216c855cbd22f..9612dd86daed1832f5fd220d62d27517b5eb85db 100644 (file)
@@ -2793,7 +2793,10 @@ class SequenceNode(ExprNode):
                     item.result(),
                     i))
             code.put_incref(item.result(), item.ctype())
+            value_node = self.coerced_unpacked_items[i]
+            value_node.generate_evaluation_code(code)
         rhs.generate_disposal_code(code)
+
         code.putln("} else {")
 
         code.putln(
@@ -2811,6 +2814,8 @@ class SequenceNode(ExprNode):
                     item.result(),
                     typecast(item.ctype(), py_object_type, unpack_code),
                     code.error_goto_if_null(item.result(), self.pos)))
+            value_node = self.coerced_unpacked_items[i]
+            value_node.generate_evaluation_code(code)
         code.put_error_if_neg(self.pos, 
             "__Pyx_EndUnpack(%s)" % (
                 self.iterator.py_result()))
@@ -2821,9 +2826,8 @@ class SequenceNode(ExprNode):
 
         code.putln("}")
         for i in range(len(self.args)):
-            value_node = self.coerced_unpacked_items[i]
-            value_node.generate_evaluation_code(code)
-            self.args[i].generate_assignment_code(value_node, code)
+            self.args[i].generate_assignment_code(
+                self.coerced_unpacked_items[i], code)
         
     def annotate(self, code):
         for arg in self.args:
index 3149f2b909ff0cedc62d80af730db3eb78158c77..4339da1239d0f79fa1beacdb1ce84473f470a380 100644 (file)
@@ -3,19 +3,41 @@ __doc__ = u"""
 (1, 2, 3)
 >>> assign3(t)
 (1, 2, 3)
->>> 
+>>> assign3_int(l)
+(1, 2, 3)
+>>> assign3_mixed1(l)
+(1, 2, 3)
+>>> assign3_mixed2(l)
+(1, 2, 3)
+>>> assign3_mixed3(l)
+(1, 2, 3)
 
->>> a,b = 99,99
+>>> a,b = 99,98
 >>> a,b = t
 Traceback (most recent call last):
 ValueError: too many values to unpack
 >>> a,b
-(99, 99)
+(99, 98)
 
 >>> test_overwrite(l)
-(99, 99)
+(99, 98)
 >>> test_overwrite(t)
-(99, 99)
+(99, 98)
+
+>>> test_overwrite_int(l)
+(99, 98)
+>>> test_overwrite_int(t)
+(99, 98)
+
+>>> test_overwrite_mixed(l)
+(99, 98)
+>>> test_overwrite_mixed(t)
+(99, 98)
+
+>>> test_overwrite_mixed2(l)
+(99, 98)
+>>> test_overwrite_mixed2(t)
+(99, 98)
 """
 
 t = (1,2,3)
@@ -25,8 +47,60 @@ def assign3(t):
     a,b,c = t
     return (a,b,c)
 
+def assign3_int(t):
+    cdef int a,b,c
+    a,b,c = t
+    return (a,b,c)
+
+def assign3_mixed1(t):
+    cdef int a
+    a,b,c = t
+    return (a,b,c)
+
+def assign3_mixed2(t):
+    cdef int b
+    a,b,c = t
+    return (a,b,c)
+
+def assign3_mixed3(t):
+    cdef int c
+    a,b,c = t
+    return (a,b,c)
+
+def assign3_mixed4(t):
+    cdef int b,c
+    a,b,c = t
+    return (a,b,c)
+
 def test_overwrite(t):
-    a,b = 99,99
+    a,b = 99,98
+    try:
+        a,b = t
+    except ValueError:
+        pass
+    return (a,b)
+
+def test_overwrite_int(t):
+    cdef int a,b
+    a,b = 99,98
+    try:
+        a,b = t
+    except ValueError:
+        pass
+    return (a,b)
+
+def test_overwrite_mixed(t):
+    cdef int b
+    a,b = 99,98
+    try:
+        a,b = t
+    except ValueError:
+        pass
+    return (a,b)
+
+def test_overwrite_mixed2(t):
+    cdef int a
+    a,b = 99,98
     try:
         a,b = t
     except ValueError: