Fix z.conjugate() for typedef-ed z; disallow external typedef complex
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 20 Oct 2009 08:06:09 +0000 (10:06 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 20 Oct 2009 08:06:09 +0000 (10:06 +0200)
Cython/Compiler/Nodes.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py
tests/run/complex_numbers_T305.pyx

index 4e1e409ae0bc5d16dbf1db42c8fc50161cbc8641..40e4056742c5d5268369d4e12bae0de9eaeaad81 100644 (file)
@@ -16,7 +16,7 @@ from Errors import error, warning, InternalError
 import Naming
 import PyrexTypes
 import TypeSlots
-from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType
+from PyrexTypes import py_object_type, error_type, CFuncType
 from Symtab import ModuleScope, LocalScope, GeneratorLocalScope, \
     StructOrUnionScope, PyClassScope, CClassScope
 from Cython.Utils import open_new_file, replace_suffix
index 471821327c7e6b3ea3a8669d29da0cb6cdda6a71..0a9ecbedbbe283c5e572a58ecc5b3d572051816f 100644 (file)
@@ -150,6 +150,15 @@ class PyrexType(BaseType):
         # type information of the struct.
         return 1
 
+
+def create_typedef_type(cname, base_type, is_external=0):
+    if base_type.is_complex:
+        if is_external:
+            raise ValueError("Complex external typedefs not supported")
+        return base_type
+    else:
+        return CTypedefType(cname, base_type, is_external)
+
 class CTypedefType(BaseType):
     #
     #  Pseudo-type defined with a ctypedef statement in a
@@ -170,6 +179,7 @@ class CTypedefType(BaseType):
     
     
     def __init__(self, cname, base_type, is_external=0):
+        assert not base_type.is_complex
         self.typedef_cname = cname
         self.typedef_base_type = base_type
         self.typedef_is_external = is_external
@@ -876,8 +886,6 @@ class CComplexType(CNumericType):
                     None,
                     visibility="extern")
             scope.parent_type = self
-
-            
             scope.declare_var("real", self.real_type, None, "real", is_cdef=True)
             scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
             entry = scope.declare_cfunction(
index 892e985d8a3a3a39c96f88240a6b7773f4012505..bb96dd45a844ff5e209d98aaecf4140202ae80fe 100644 (file)
@@ -342,7 +342,11 @@ class Scope(object):
                 cname = name
             else:
                 cname = self.mangle(Naming.type_prefix, name)
-        type = PyrexTypes.CTypedefType(cname, base_type, (visibility == 'extern'))
+        try:
+            type = PyrexTypes.create_typedef_type(cname, base_type, (visibility == 'extern'))
+        except ValueError, e:
+            error(pos, e.message)
+            type = PyrexTypes.error_type
         entry = self.declare_type(name, type, pos, cname, visibility)
         type.qualified_name = entry.qualified_name
         return entry
index 71846397882f216985df42e33ee2b80e0a0683f7..e25a4b3570c1cac1de7aced546787431dcac36ec 100644 (file)
@@ -116,3 +116,8 @@ def test_conjugate(float complex z):
 
 def test_conjugate_double(double complex z):
     return z.conjugate()
+
+ctypedef double complex cdouble
+def test_conjugate_typedef(cdouble z):
+    return z.conjugate()
+