Ticket #751 (closed enhancement: wontfix)
Allow lambda with C functions
| Reported by: | nikratio | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | wishlist |
| Component: | Cython Language Feature | Keywords: | |
| Cc: | nikratio |
Description
Currently, it is not possible to use lambda with a C function:
$ cython -Wextra mylib2.pyx
Error compiling Cython file:
------------------------------------------------------------
...
def test():
cdef void *ptr
ptr = malloc(sizeof(int))
return lambda : init(ptr)
^
------------------------------------------------------------
mylib2.pyx:10:24: Cannot convert 'void' to Python object
$ cat mylib2.pyx
from libc.stdlib cimport malloc
cdef extern from "*":
void init(void* ptr)
def test():
cdef void *ptr
ptr = malloc(sizeof(int))
return lambda : init(ptr)
This is of course a legitimate error, it's not clear what the lambda expression is supposed to return.
However, that means that creation of a Python wrapper for a C function always requires explicit definition of the function. It would be very nice to have a way around that.
My suggestion is therefore to treat any call to C function of type void as returning None, so that the following expression becomes valid:
(lambda : <void> c_function())() is None
Change History
Note: See
TracTickets for help on using
tickets.
