Hi Stefan,
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.
ah, that's what I referred to as "a problem" as it still leaves a layer,
and hence a slowdown. :) Yes, in the "slow" path it works like that. I'm
just hoping for something more elegant.
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?
It is RPython, but compiled statically does not mean that it can not have
behaviors at runtime: you specify at runtime the kind of low-level objects
to expect, then map those objects at the time of the call. Like you say,
just as with ctypes (which in PyPy has libffi underneath).
The relevant classes are libffi.Func which receives the annotations from
a selection of libffi.types, and libffi.ArgChain which receives the values
just before the call. The return type is handed to Func.call, and then
only needs boxing to be send back to python.
In C++, there's for member functions a little bit of gymnastics going on as
a naked function pointer can only be obtained after binding it to an object
which again is slow (relatively, anyway). However, if the type is known, a
single lookup suffices, and then the JIT can guard on that type. The 'this'
pointer then becomes the first arg in the libffi.ArgChain and all is good.
For gcc anyway, which has this behavior documented as an extension, so it
can presumably be relied upon. :)
For cppyy, the current plan is to wrap python functions in generated C++
functions for callbacks.
Yes, that would be the other direction.
I'm more seeing it as only half the work, rather than a different direction.
At least, as I understand Cython, the generated low level code is an actual
identifiable function? That is not the case for JIT traces, and so where in
Cython a function pointer can be given back to the C++ code performing the
callback, I'm not aware of anything similar being available from the JIT.
Of course, Python -> Cython -> C-pointer -> JIT should work nicely.
Best regards,
Wim
--
wlavrij...@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev