cython/cython

C API returns PyCapsule with incorrect function signature

ashwinvis opened this issue · 1 comments

What does not work

# add_int.pyx
cdef api add(int x, int y):
    cdef int r;
    r = x + y;
    return r

check:

>>> import add_int
>>> add_int.__pyx_capi__['add']
<capsule object "PyObject *(int, int)" at 0x7f731cfdd540>

What works

However if I use cythonize an external C code which does the same thing, it gives me a PyCapsule with proper signature. (see link below for the code)

>>> import cy_add_int
>>> cy_add_int.__pyx_capi__['cy_add']
<capsule object "int (int, int)" at 0x7f7169dfba50>

I have uploaded the source files for the above cases with Makefiles if anybody wants to check. Just run make build.

https://github.com/ashwinvis/cython_capi/tree/master/cython_issue

This is also related to serge-sans-paille/pythran/issues/743 where Pythran is adding the possibility to pass Cython functions as arguments through PyCapsules. cc:@serge-sans-paille

The signature is correct. The return type is object in the first case. See, for example:
http://docs.cython.org/en/latest/src/reference/language_basics.html#parameters