More cmp tests, refix C assignable types.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 06:39:02 +0000 (23:39 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 22 Oct 2009 06:39:02 +0000 (23:39 -0700)
Cython/Compiler/ExprNodes.py
tests/run/cmp.pyx

index 5c3670b8a31d9e667fa47cf00239232982701237..9871eda3731bd1f5034105d3f25718fec8ad73ac 100644 (file)
@@ -5151,6 +5151,10 @@ class CmpNode(object):
                     # one Python type and one non-Python type, not assignable
                     self.invalid_types_error(operand1, op, operand2)
                     new_common_type = error_type
+            elif type1.assignable_from(type2):
+                new_common_type = type1
+            elif type2.assignable_from(type1):
+                new_common_type = type2
             else:
                 # C types that we couldn't handle up to here are an error
                 self.invalid_types_error(operand1, op, operand2)
index ecc30d249b388a61a1cde24123711902dc5b43a3..6b5fd14cea47098c6ce65e74c860b7300f8bba89 100644 (file)
@@ -46,3 +46,30 @@ def typed_cmp(list L):
     print Ellipsis is L
     print 1 == L
     print L == 1.5
+
+def pointer_cmp():
+    """
+    >>> pointer_cmp()
+    True
+    False
+    True
+    """
+    cdef int* a = NULL
+    cdef double* b = NULL
+    cdef double** c = NULL
+    print a is NULL
+    print b is not NULL
+    print c == NULL
+
+def c_cmp(double a, int b, long c):
+    """
+    >>> c_cmp(1, 2, 3)
+    True
+    >>> c_cmp(1.5, 2, 2)
+    True
+    >>> c_cmp(1.5, 2, 0)
+    False
+    >>> c_cmp(1, 1, 3)
+    False
+    """
+    return a < b <= c