From: Craig Citro Date: Wed, 7 Jul 2010 08:11:24 +0000 (-0700) Subject: Fix an error with coercing C ints in boolean context. X-Git-Tag: 0.13.beta0~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d817949dec34f0b66ba730b8c8eb75bffdea1da3;p=cython.git Fix an error with coercing C ints in boolean context. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 852286f4..7239c635 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6268,7 +6268,12 @@ class CoerceToPyTypeNode(CoercionNode): return False def coerce_to_boolean(self, env): - return self.arg.coerce_to_boolean(env).coerce_to_temp(env) + arg_type = self.arg.type + if (arg_type == PyrexTypes.c_bint_type or + (arg_type.is_pyobject and arg_type.name == 'bool')): + return self.arg.coerce_to_temp(env) + else: + return CoerceToBooleanNode(self, env) def coerce_to_integer(self, env): # If not already some C integer type, coerce to longint. diff --git a/tests/run/boolean_context.pyx b/tests/run/boolean_context.pyx new file mode 100644 index 00000000..f6d59e1b --- /dev/null +++ b/tests/run/boolean_context.pyx @@ -0,0 +1,8 @@ + +def test(): + """ + >>> test() + True + """ + cdef int x = 5 + print bool(x)