From ccc84a3f0712070884bd3d8ab847958ce350a29d Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 7 Aug 2008 22:08:21 -0700 Subject: [PATCH] Re-re-instate 908, everything should work now --- Cython/Compiler/Nodes.py | 13 ++++++++++--- Cython/Compiler/PyrexTypes.py | 7 +++++++ tests/compile/cargdef.pyx | 9 ++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 98dc1de6..a17463a9 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -362,8 +362,12 @@ class CNameDeclaratorNode(CDeclaratorNode): def analyse(self, base_type, env, nonempty = 0): if nonempty and self.name == '': - # Must have mistaken the name for the type. - self.name = base_type.name + # May have mistaken the name for the type. + if base_type.is_ptr or base_type.is_array or base_type.is_buffer: + error(self.pos, "Missing argument name") + elif base_type.is_void: + error(self.pos, "Use spam() rather than spam(void) to declare a function with no arguments.") + self.name = base_type.declaration_code("", for_display=1, pyrex=1) base_type = py_object_type self.type = base_type return self, base_type @@ -422,6 +426,8 @@ class CFuncDeclaratorNode(CDeclaratorNode): optional_arg_count = 0 def analyse(self, return_type, env, nonempty = 0): + if nonempty: + nonempty -= 1 func_type_args = [] for arg_node in self.args: name_declarator, type = arg_node.analyse(env, nonempty = nonempty) @@ -1052,7 +1058,8 @@ class CFuncDefNode(FuncDefNode): def analyse_declarations(self, env): base_type = self.base_type.analyse(env) - name_declarator, type = self.declarator.analyse(base_type, env, self.body is not None) + # The 2 here is because we need both function and argument names. + name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None)) if not type.is_cfunction: error(self.pos, "Suite attached to non-function declaration") diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index b188088e..e8a7fd10 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -287,6 +287,13 @@ class BuiltinObjectType(PyObjectType): def type_test_code(self, arg): return 'likely(Py%s_CheckExact(%s)) || (%s) == Py_None || (PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name), 0)' % (self.name[0].upper() + self.name[1:], arg, arg, self.name, arg) + def declaration_code(self, entity_code, + for_display = 0, dll_linkage = None, pyrex = 0): + if pyrex or for_display: + return self.base_declaration_code(self.name, entity_code) + else: + return "%s *%s" % (public_decl("PyObject", dll_linkage), entity_code) + class PyExtensionType(PyObjectType): # diff --git a/tests/compile/cargdef.pyx b/tests/compile/cargdef.pyx index c8064d0b..c5da39bb 100644 --- a/tests/compile/cargdef.pyx +++ b/tests/compile/cargdef.pyx @@ -1,3 +1,10 @@ def f(obj, int i, float f, char *s1, char s2[]): pass - \ No newline at end of file + +cdef g(obj, int i, float f, char *s1, char s2[]): + pass + +cdef do_g(object (*func)(object, int, float, char*, char*)): + return func(1, 2, 3.14159, "a", "b") + +do_g(&g) -- 2.26.2