fix ticket #643: infer the type of C function names as function pointers
authorStefan Behnel <scoder@users.berlios.de>
Thu, 13 Jan 2011 15:57:57 +0000 (16:57 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 13 Jan 2011 15:57:57 +0000 (16:57 +0100)
Cython/Compiler/ExprNodes.py
tests/run/type_inference.pyx

index 8332f443a552e0d168fb6223c4400ec3b5162a60..ec12a94d658bb7f18de410a4f58e8c0b41c05417 100755 (executable)
@@ -1296,6 +1296,9 @@ class NameNode(AtomicExprNode):
             # Unfortunately the type attribute of type objects
             # is used for the pointer to the type they represent.
             return type_type
+        elif self.entry.type.is_cfunction:
+            # special case: referring to a C function must return it's pointer
+            return PyrexTypes.CPtrType(self.entry.type)
         else:
             return self.entry.type
 
index dc4566104c11882b733c48ced373d4c26797ae71..74e1449096135cf8fd4d1e014e9aa66617b5aafb 100644 (file)
@@ -199,6 +199,17 @@ def builtin_type_operations():
     T2 = () * 2
     assert typeof(T2) == "tuple object", typeof(T2)
 
+cdef int func(int x):
+    return x+1
+
+def c_functions():
+    """
+    >>> c_functions()
+    """
+    f = func
+    assert typeof(f) == 'int (*)(int)', typeof(f)
+    assert 2 == f(1)
+
 def cascade():
     """
     >>> cascade()