From d832f4639cbe6ab2ef5fc692304962765d0b6dd0 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 24 Nov 2013 16:06:46 +0100 Subject: [PATCH] use plain constants for Python bool values instead of coerced C ints --- Cython/Compiler/ExprNodes.py | 13 ++++++++++++- tests/run/constant_folding.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index eaa85f9..438dbd0 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -947,7 +947,18 @@ class BoolNode(ConstNode): return self.value def calculate_result_code(self): - return str(int(self.value)) + if self.type.is_pyobject: + return self.value and 'Py_True' or 'Py_False' + else: + return str(int(self.value)) + + def coerce_to(self, dst_type, env): + if dst_type.is_pyobject and self.type.is_int: + return BoolNode( + self.pos, value=self.value, + constant_result=self.constant_result, + type=Builtin.bool_type) + return ConstNode.coerce_to(self, dst_type, env) class NullNode(ConstNode): diff --git a/tests/run/constant_folding.py b/tests/run/constant_folding.py index 2efbdbc..c31bf9d 100644 --- a/tests/run/constant_folding.py +++ b/tests/run/constant_folding.py @@ -27,6 +27,7 @@ def unop_floats(): @cython.test_fail_if_path_exists( "//UnaryMinusNode", "//UnaryPlusNode", + "//CoerceToPyTypeNode", ) def unop_py_floats_tuple(): """ -- 2.7.4