From: Stefan Behnel Date: Sat, 20 Apr 2013 20:26:55 +0000 (+0200) Subject: always convert C integer values to 1/0 when testing them for their boolean value X-Git-Tag: 0.19.1~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=beb42251d5c5ace129f75b36af949cb6cf0d38c0;p=platform%2Fupstream%2Fpython-cython.git always convert C integer values to 1/0 when testing them for their boolean value --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 5f6edc5..7e2b105 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -744,13 +744,12 @@ class ExprNode(Node): constant_result=bool_value) type = self.type - if type.is_pyobject or type.is_ptr or type.is_float: + if type.is_enum or type.is_error: + return self + elif type.is_pyobject or type.is_int or type.is_ptr or type.is_float: return CoerceToBooleanNode(self, env) else: - if not (type.is_int or type.is_enum or type.is_error): - error(self.pos, - "Type '%s' not acceptable as a boolean" % type) - return self + error(self.pos, "Type '%s' not acceptable as a boolean" % type) def coerce_to_integer(self, env): # If not already some C integer type, coerce to longint. diff --git a/tests/run/bint_binop_T145.pyx b/tests/run/bint_binop_T145.pyx index 5f5ef65..c5325a5 100644 --- a/tests/run/bint_binop_T145.pyx +++ b/tests/run/bint_binop_T145.pyx @@ -111,3 +111,25 @@ def x_and_1_or_False(x): False """ return x and 1 or False + +def test_large_int(unsigned long x): + """ + >>> try: test_large_int(1 << 127) + ... except OverflowError: print True + True + >>> try: test_large_int(1 << 63) + ... except OverflowError: print True + True + >>> try: test_large_int(1 << 48) + ... except OverflowError: print True + True + >>> try: test_large_int(1 << 31) + ... except OverflowError: print True + True + >>> test_large_int(0) + False + """ + if True and x: + return True + else: + return False