[SciPy-Dev] Documentation to use LowLevelCallable from cython

Pauli Virtanen pav at iki.fi
Sun Feb 18 18:02:50 EST 2018


ma, 2018-02-19 kello 08:08 +1100, Andrew Nelson kirjoitti:
> Sorry if I wasn't clear. I'll look at those two places. What I was
> hoping
> to do is have a generic way of calling a LowLevelCallable in cython:
> 
> <in cython>
> 
> cpdef func_caller(LowLevelCallable func, a, b, c, ...):
> 
>     return_value = func(a, b, c)
> 
>     return return_value

That's the `test_thunk_cython` routine in `_ccallback_c.pyx`. See also
`test_call_cython` on how to get `ccallback_t` from a user-provided
callable (which may be a LowLevelCallable).

Of course, when you are not writing callbacks for some 3rd party
library, a more sensible signature for the caller routine would be
along the lines `test_thunk_cython(ccallback_t *callback, double a)`.

Note that you need to write a separate "caller" routine to do the call
for each specific type of callback function you have. There's no
generic way to do it, as that would require online code generation.

	Pauli



More information about the SciPy-Dev mailing list