always convert C integer values to 1/0 when testing them for their boolean value
authorStefan Behnel <stefan_ml@behnel.de>
Sat, 20 Apr 2013 20:26:55 +0000 (22:26 +0200)
committerStefan Behnel <stefan_ml@behnel.de>
Sat, 20 Apr 2013 20:26:55 +0000 (22:26 +0200)
Cython/Compiler/ExprNodes.py
tests/run/bint_binop_T145.pyx

index 5f6edc5..7e2b105 100755 (executable)
@@ -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.
index 5f5ef65..c5325a5 100644 (file)
@@ -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