use type cast to enforce INCREF() on Python objects
authorStefan Behnel <scoder@users.berlios.de>
Tue, 25 Nov 2008 19:16:21 +0000 (20:16 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 25 Nov 2008 19:16:21 +0000 (20:16 +0100)
Cython/Compiler/Optimize.py

index fcf07ff4ffb5c78d8bcb2c9a6f761fcf1b8cb5be..40f7b5e87925e8c0f65c8efc96d70847cd6792c9 100644 (file)
@@ -115,16 +115,19 @@ class DictIterTransform(Visitor.VisitorTransform):
             class FakeEnv(object):
                 nogil = False
             if dest_type.is_pyobject:
+                coercion = None
                 if dest_type.is_extension_type or dest_type.is_builtin_type:
-                    return (obj_node, ExprNodes.PyTypeTestNode(obj_node, dest_type, FakeEnv()))
-                else:
-                    return (obj_node, None)
+                    coercion = ExprNodes.PyTypeTestNode(obj_node, dest_type, FakeEnv())
+                result = ExprNodes.TypecastNode(
+                    obj_node.pos,
+                    operand = obj_node,
+                    type = dest_type)
+                return (result, coercion)
             else:
                 temp = UtilNodes.TempHandle(dest_type)
                 temps.append(temp)
                 temp_result = temp.ref(obj_node.pos)
                 class CoercedTempNode(ExprNodes.CoerceFromPyTypeNode):
-                    # FIXME: remove this after result-code refactoring
                     def result(self):
                         return temp_result.result()
                     def generate_execution_code(self, code):
@@ -168,8 +171,8 @@ class DictIterTransform(Visitor.VisitorTransform):
                 assign_stats.append(
                     Nodes.SingleAssignmentNode(
                         pos = key_temp.pos,
-                        rhs = temp_result,
-                        lhs = key_target))
+                        lhs = key_target,
+                        rhs = temp_result))
             if values:
                 temp_result, coercion = coerce_object_to(
                     value_temp, value_target.type)
@@ -178,8 +181,8 @@ class DictIterTransform(Visitor.VisitorTransform):
                 assign_stats.append(
                     Nodes.SingleAssignmentNode(
                         pos = value_temp.pos,
-                        rhs = temp_result,
-                        lhs = value_target))
+                        lhs = value_target,
+                        rhs = temp_result))
             body.stats[0:0] = coercion_stats + assign_stats
 
         result_code = [