From: Stefan Behnel Date: Thu, 13 Jan 2011 15:57:57 +0000 (+0100) Subject: fix ticket #643: infer the type of C function names as function pointers X-Git-Tag: 0.14.1rc0~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=48177ec6f603d7ae88ee6302bfe5c4c299cd350a;p=cython.git fix ticket #643: infer the type of C function names as function pointers --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 8332f443..ec12a94d 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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 diff --git a/tests/run/type_inference.pyx b/tests/run/type_inference.pyx index dc456610..74e14490 100644 --- a/tests/run/type_inference.pyx +++ b/tests/run/type_inference.pyx @@ -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()