[pypy-dev] Cython-CEP: Native dispatch through Python callables

Stefan Behnel stefan_ml at behnel.de
Fri Apr 13 20:18:11 CEST 2012


wlavrijsen at lbl.gov, 13.04.2012 19:03:
>> Note that a wrapper function may offer more than one native signature, e.g.
>> when wrapping overloaded C++ functions or when using Cython fused functions.
> 
> the big problem I'm finding for unpacking C++ functions (other than that
> there's no platform-independent way to do so when it comes to methods, AFAIK
> anyway), is handling of C++ exceptions.

At least for Cython code that's not a problem - its functions raise Python
exceptions. Some C++ exceptions are mapped automatically and others can be
mapped explicitly.

Other wrapper generators could also generate an intermediate wrapper
function that does the error mapping and passes on Python exceptions.
Unpacking a wrapped function doesn't necessarily mean that you get a bare C
or C++ function. The main intention is to reduce the call overhead, which
is mainly introduced by packing and unpacking arguments. That's why we want
to expose the signature.


> Integrating unpacked functions pointers with PyPy works rather elegantly
> through the functionality made available in rlib/libffi.py. The form of the
> specification matters little at that point, as long as it is complete.

Hmm, but that's RPython, isn't it? I thought that was compiled statically?
How would it adapt to a signature that it finds at runtime then?

I think this is closer to ctypes, except that you don't have to specify the
signature of the thing you call because PyPy will see it at call time.


> For cppyy, the current plan is to wrap python functions in generated C++
> functions for callbacks.

Yes, that would be the other direction.

Stefan



More information about the pypy-dev mailing list