From: Dag Sverre Seljebotn Date: Sun, 17 May 2009 06:01:24 +0000 (+0200) Subject: Fix bug in new buffmt code X-Git-Tag: 0.11.2.rc1~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6e8378849935c3f54581d9a64c930aff90b1309f;p=cython.git Fix bug in new buffmt code --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index d93249cb..f01b5174 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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() diff --git a/tests/run/buffmt.pyx b/tests/run/buffmt.pyx index 581ce59d..982c8b94 100644 --- a/tests/run/buffmt.pyx +++ b/tests/run/buffmt.pyx @@ -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: