Commit b64bf1ba authored by Stefan Behnel's avatar Stefan Behnel

fix compiler crash on unitialised result_code and fix coercion of float/bool back to C values

parent d832f463
......@@ -958,6 +958,11 @@ class BoolNode(ConstNode):
self.pos, value=self.value,
constant_result=self.constant_result,
type=Builtin.bool_type)
if dst_type.is_int and self.type.is_pyobject:
return BoolNode(
self.pos, value=self.value,
constant_result=self.constant_result,
type=PyrexTypes.c_bint_type)
return ConstNode.coerce_to(self, dst_type, env)
......@@ -1111,12 +1116,17 @@ class FloatNode(ConstNode):
self.pos, value=self.value,
constant_result=self.constant_result,
type=Builtin.float_type)
if dst_type.is_float and self.type.is_pyobject:
return FloatNode(
self.pos, value=self.value,
constant_result=self.constant_result,
type=dst_type)
return ConstNode.coerce_to(self, dst_type, env)
def calculate_result_code(self):
return self.result_code
def as_c_constant(self):
def get_constant_c_result_code(self):
strval = self.value
assert isinstance(strval, (str, unicode))
cmpval = repr(float(strval))
......@@ -1130,11 +1140,11 @@ class FloatNode(ConstNode):
return strval
def generate_evaluation_code(self, code):
c_value = self.get_constant_c_result_code()
if self.type.is_pyobject:
self.result_code = code.get_py_float(
self.value, self.as_c_constant())
self.result_code = code.get_py_float(self.value, c_value)
else:
self.result_code = self.as_c_constant()
self.result_code = c_value
class BytesNode(ConstNode):
......
......@@ -1792,7 +1792,8 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
arg = arg.arg
if arg.is_literal:
if (node.type.is_int and isinstance(arg, ExprNodes.IntNode) or
node.type.is_float and isinstance(arg, ExprNodes.FloatNode)):
node.type.is_float and isinstance(arg, ExprNodes.FloatNode) or
node.type.is_int and isinstance(arg, ExprNodes.BoolNode)):
return arg.coerce_to(node.type, self.current_env())
elif isinstance(arg, ExprNodes.CoerceToPyTypeNode):
if arg.type is PyrexTypes.py_object_type:
......
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