On Tue, Feb 24, 2009 at 2:24 PM, Greg Ewing
<[email protected]> > [1] It could be done if you're willing
to dynamically
> generate machine code for a new function each time you
> want a new instance of the callback, but that would
> hardly be portable.

Well, it's somewhat portable, if you rely on somebody else to write the code :)

The libffi library has routines to write the required machine language
stub that work on a lot of different machines (but probably less
places than Python works).  The Python ctypes library (a standard part
of Python since Python 2.5) depends on (and includes) libffi to let
you create C function pointers that call an arbitrary Python callable,
so this should work for Cython functions.  (I've never tested any of
this, only read the documentation.)

This isn't a good idea for general programming; if it's at all
possible to change the callback interface, that would be better.
Using ctypes this way will definitely reduce the portability of your
code (to Python 2.5+, and to machines that have libffi callback
support).

Carl
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to