latest 0.9.4 changes into 0.9.5 branch
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 10 Jul 2007 09:15:10 +0000 (02:15 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 10 Jul 2007 09:15:10 +0000 (02:15 -0700)
1  2 
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py

index a105e33fd0ef14a3e40f9629d7a02e05c3dc141a,f7e17a05f7934928039e31742bc84f4fe34d1398..18eb72c7fcddda24340316ad5a58871efc84db06
@@@ -1877,17 -1854,31 +1877,38 @@@ class SequenceNode(ExprNode)
          self.generate_operation_code(code)
      
      def generate_assignment_code(self, rhs, code):
+         code.putln(
+             "if (PyTuple_CheckExact(%s) && PyTuple_GET_SIZE(%s) == %s) {" % (
+                 rhs.py_result(), 
+                 rhs.py_result(), 
+                 len(self.args)))
+         for i in range(len(self.args)):
+             item = self.unpacked_items[i]
+             code.putln(
+                 "%s = PyTuple_GET_ITEM(%s, %s);" % (
+                     item.result_code,
+                     rhs.py_result(),
+                     i))
+             code.put_incref(item.result_code, item.ctype())
+             value_node = self.coerced_unpacked_items[i]
+             value_node.generate_evaluation_code(code)
+             self.args[i].generate_assignment_code(value_node, code)
+             
++        rhs.generate_disposal_code(code)
+         code.putln("}")
+         code.putln("else {")
 +        code.putln(
 +            "%s = PyObject_GetIter(%s); if (!%s) %s" % (
 +                self.iterator.result_code,
 +                rhs.py_result(),
 +                self.iterator.result_code,
 +                code.error_goto(self.pos)))
 +        rhs.generate_disposal_code(code)
          for i in range(len(self.args)):
              item = self.unpacked_items[i]
 -            unpack_code = "__Pyx_UnpackItem(%s, %s)" % (
 -                rhs.py_result(),
 -                i)
 +            unpack_code = "__Pyx_UnpackItem(%s)" % (
 +                self.iterator.py_result())
              code.putln(
                  "%s = %s; if (!%s) %s" % (
                      item.result_code,
              value_node.generate_evaluation_code(code)
              self.args[i].generate_assignment_code(value_node, code)
          code.putln(
 -            "if (__Pyx_EndUnpack(%s, %s) < 0) %s" % (
 -                rhs.py_result(),
 -                len(self.args),
 +            "if (__Pyx_EndUnpack(%s) < 0) %s" % (
 +                self.iterator.py_result(),
                  code.error_goto(self.pos)))
 -
 -        code.putln("}")
          if debug_disposal_code:
              print "UnpackNode.generate_assignment_code:"
--            print "...generating disposal code for", rhs
 -        rhs.generate_disposal_code(code)
++            print "...generating disposal code for", iterator
 +        self.iterator.generate_disposal_code(code)
 +
++        code.putln("}")
  
  class TupleNode(SequenceNode):
      #  Tuple constructor.
Simple merge
Simple merge