From 48177ec6f603d7ae88ee6302bfe5c4c299cd350a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 13 Jan 2011 16:57:57 +0100 Subject: [PATCH] fix ticket #643: infer the type of C function names as function pointers --- Cython/Compiler/ExprNodes.py | 3 +++ tests/run/type_inference.pyx | 11 +++++++++++ 2 files changed, 14 insertions(+) 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() -- 2.26.2