cython-devel
changeset 908:7a1defb8455d
Function pointers as arguments, better errors for unnamed arguments.
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Sat Aug 02 23:35:16 2008 -0700 (4 years ago) |
| parents | e6bad90a921e |
| children | 9235d5b9e530 |
| files | Cython/Compiler/Nodes.py tests/compile/cargdef.pyx |
line diff
1.1 --- a/Cython/Compiler/Nodes.py Sat Aug 02 22:44:42 2008 -0700
1.2 +++ b/Cython/Compiler/Nodes.py Sat Aug 02 23:35:16 2008 -0700
1.3 @@ -362,8 +362,13 @@
1.4
1.5 def analyse(self, base_type, env, nonempty = 0):
1.6 if nonempty and self.name == '':
1.7 - # Must have mistaken the name for the type.
1.8 - self.name = base_type.name
1.9 + raise RuntimeError
1.10 + # May have mistaken the name for the type.
1.11 + if base_type.is_ptr or base_type.is_array or base_type.is_buffer:
1.12 + error(self.pos, "Missing argument name.")
1.13 + elif base_type.is_void:
1.14 + error(self.pos, "Use spam() rather than spam(void) to declare a function with no arguments.")
1.15 + self.name = base_type.declaration_code("", for_display=1, pyrex=1)
1.16 base_type = py_object_type
1.17 self.type = base_type
1.18 return self, base_type
1.19 @@ -424,7 +429,7 @@
1.20 def analyse(self, return_type, env, nonempty = 0):
1.21 func_type_args = []
1.22 for arg_node in self.args:
1.23 - name_declarator, type = arg_node.analyse(env, nonempty = nonempty)
1.24 + name_declarator, type = arg_node.analyse(env)
1.25 name = name_declarator.name
1.26 if name_declarator.cname:
1.27 error(self.pos,
2.1 --- a/tests/compile/cargdef.pyx Sat Aug 02 22:44:42 2008 -0700
2.2 +++ b/tests/compile/cargdef.pyx Sat Aug 02 23:35:16 2008 -0700
2.3 @@ -1,3 +1,10 @@
2.4 def f(obj, int i, float f, char *s1, char s2[]):
2.5 pass
2.6 -
2.7 \ No newline at end of file
2.8 +
2.9 +cdef g(obj, int i, float f, char *s1, char s2[]):
2.10 + pass
2.11 +
2.12 +cdef do_g(object (*func)(object, int, float, char*, char*)):
2.13 + return func(1, 2, 3.14159, "a", "b")
2.14 +
2.15 +do_g(&g)
