make 'complex' the C double complex type instead of Python's complex object type
authorStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 09:40:12 +0000 (10:40 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 4 Dec 2010 09:40:12 +0000 (10:40 +0100)
Cython/Compiler/Nodes.py
Cython/Compiler/PyrexTypes.py

index 09a9ffdfeba3299ddda31cb7e165b97f479682ea..593f9f6ad0dc011064f99316e8d83ae1d4e3a31e 100644 (file)
@@ -786,6 +786,14 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
                 error(self.pos, "can only complexify c numeric types")
             type = PyrexTypes.CComplexType(type)
             type.create_declaration_utility_code(env)
+        elif type is Builtin.complex_type:
+            # Special case: optimise builtin complex type into C's
+            # double complex.  The parser cannot do this (as for the
+            # normal scalar types) as the user may have redeclared the
+            # 'complex' type.  Testing for the exact type here works.
+            type = PyrexTypes.c_double_complex_type
+            type.create_declaration_utility_code(env)
+            self.complex = True
         if type:
             return type
         else:
index 1ff5a0213679ef13eb2848ee79008f2e3c08ca11..2c302fc5d60a09e6643903201273157667a3183a 100755 (executable)
@@ -2318,7 +2318,7 @@ modifiers_and_name_to_type = {
     (1,  0, "double"): c_double_type,
     (1,  1, "double"): c_longdouble_type,
 
-    (1,  0, "complex"):  c_float_complex_type,
+    (1,  0, "complex"):  c_double_complex_type,  # C: float, Python: double => Python wins
     (1,  0, "floatcomplex"):  c_float_complex_type,
     (1,  0, "doublecomplex"): c_double_complex_type,
     (1,  1, "doublecomplex"): c_longdouble_complex_type,