From: Stefan Behnel Date: Tue, 25 Nov 2008 19:16:21 +0000 (+0100) Subject: use type cast to enforce INCREF() on Python objects X-Git-Tag: 0.11-beta~218 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=778c2f66e6cd589d10b837ecdda30050ff0bfe45;p=cython.git use type cast to enforce INCREF() on Python objects --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index fcf07ff4..40f7b5e8 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -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 = [