Fix bug in new buffmt code
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 17 May 2009 06:01:24 +0000 (08:01 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sun, 17 May 2009 06:01:24 +0000 (08:01 +0200)
Cython/Compiler/PyrexTypes.py
tests/run/buffmt.pyx

index d93249cb1f72cc703c765506fd724dc698d3272f..f01b5174de0e6a49d2d29510942dcb5adf91f54e 100644 (file)
@@ -1329,9 +1329,13 @@ class CStructOrUnionType(CType):
         return self.is_complete()
 
     def can_be_complex(self):
-        # Does the struct consist of exactly two floats?
+        # Does the struct consist of exactly two identical floats?
         fields = self.scope.var_entries
-        return len(fields) == 2 and fields[0].type.is_float and fields[1].type.is_float
+        if len(fields) != 2: return False
+        a, b = fields
+        return (a.type.is_float and b.type.is_float and
+                a.type.declaration_code("") ==
+                b.type.declaration_code(""))
 
     def struct_nesting_depth(self):
         child_depths = [x.type.struct_nesting_depth()
index 581ce59d2fe8ed4c87fab83844c6a91d8a23fc42..982c8b946210d213654a5864b1001d5a61314ea0 100644 (file)
@@ -254,7 +254,7 @@ def int_and_long_are_same():
         longarr = MockBuffer("i", sizeof(int))
 
 cdef struct MixedComplex:
-    long double real
+    double real
     float imag
 
 @testcase
@@ -265,9 +265,10 @@ def mixed_complex_struct():
     >>> mixed_complex_struct()
     Traceback (most recent call last):
         ...
-    ValueError: Buffer dtype mismatch, expected 'long double' but got 'complex double' in 'MixedComplex.real'
+    ValueError: Buffer dtype mismatch, expected 'double' but got 'complex double' in 'MixedComplex.real'
     """
-    cdef object[MixedComplex] buf = MockBuffer("Zd", sizeof(MixedComplex))
+    cdef object[MixedComplex] buf = MockBuffer("Zd",
+        sizeof(MixedComplex))
 
 
 cdef packed struct PackedSubStruct: