Commit 778c2f66 authored by Stefan Behnel's avatar Stefan Behnel

use type cast to enforce INCREF() on Python objects

parent 1e0ab7ca
...@@ -115,16 +115,19 @@ class DictIterTransform(Visitor.VisitorTransform): ...@@ -115,16 +115,19 @@ class DictIterTransform(Visitor.VisitorTransform):
class FakeEnv(object): class FakeEnv(object):
nogil = False nogil = False
if dest_type.is_pyobject: if dest_type.is_pyobject:
coercion = None
if dest_type.is_extension_type or dest_type.is_builtin_type: if dest_type.is_extension_type or dest_type.is_builtin_type:
return (obj_node, ExprNodes.PyTypeTestNode(obj_node, dest_type, FakeEnv())) coercion = ExprNodes.PyTypeTestNode(obj_node, dest_type, FakeEnv())
else: result = ExprNodes.TypecastNode(
return (obj_node, None) obj_node.pos,
operand = obj_node,
type = dest_type)
return (result, coercion)
else: else:
temp = UtilNodes.TempHandle(dest_type) temp = UtilNodes.TempHandle(dest_type)
temps.append(temp) temps.append(temp)
temp_result = temp.ref(obj_node.pos) temp_result = temp.ref(obj_node.pos)
class CoercedTempNode(ExprNodes.CoerceFromPyTypeNode): class CoercedTempNode(ExprNodes.CoerceFromPyTypeNode):
# FIXME: remove this after result-code refactoring
def result(self): def result(self):
return temp_result.result() return temp_result.result()
def generate_execution_code(self, code): def generate_execution_code(self, code):
...@@ -168,8 +171,8 @@ class DictIterTransform(Visitor.VisitorTransform): ...@@ -168,8 +171,8 @@ class DictIterTransform(Visitor.VisitorTransform):
assign_stats.append( assign_stats.append(
Nodes.SingleAssignmentNode( Nodes.SingleAssignmentNode(
pos = key_temp.pos, pos = key_temp.pos,
rhs = temp_result, lhs = key_target,
lhs = key_target)) rhs = temp_result))
if values: if values:
temp_result, coercion = coerce_object_to( temp_result, coercion = coerce_object_to(
value_temp, value_target.type) value_temp, value_target.type)
...@@ -178,8 +181,8 @@ class DictIterTransform(Visitor.VisitorTransform): ...@@ -178,8 +181,8 @@ class DictIterTransform(Visitor.VisitorTransform):
assign_stats.append( assign_stats.append(
Nodes.SingleAssignmentNode( Nodes.SingleAssignmentNode(
pos = value_temp.pos, pos = value_temp.pos,
rhs = temp_result, lhs = value_target,
lhs = value_target)) rhs = temp_result))
body.stats[0:0] = coercion_stats + assign_stats body.stats[0:0] = coercion_stats + assign_stats
result_code = [ result_code = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment