Hi,
of course I can.
Imagine a binary library method called RegisterCallback which takes a
callback declared like this:
ctypedef void (*Callback)(char *somestring);
And image the same library containing a function
RegisterCallbackWithReturn accepting a callback like this:
ctypedef unsigned long (*Callback2)(char *somestring2);
Then I'll write these two callbacks in cython:
import somepythonmodule
cdef void c_Callback(char *somestring):
somepythonmodule.firework()
Adding this callback with:
...
RegisterCallback(<Callback>c_Callback)
works fine. The callback is called correctly, does it's stuff and
finished correctly, everything okay. But:
Declaring c_Callback2 as follows:
import somepythonmodule
cdef unsigned long c_Callback2(char *somestring2):
somepythonmodule.firework()
return 0
Registering this with:
RegisterCallback2(<Callback2>c_Callback2)
will still work of course, but the whole program crashes when the binary
calls the callback.
The crash occures in __pyx_PyObject_Call, as gdb states.
As I stated before, I read that the binary should use Py_Initialize()
before to access the python namespace, but as I said, the binary is a
binary, no way to change it for me.
I'm currently trying to write a c library wrapping the functionality of
being the callback function and calling the cython function with the
Py_Initialize() and Py_Finalize() thing, but i'm stuck doing that, c is
quite new to me and i'm sure that's not the thing to do to wrap an
external c lib in python... not writing a new c lib to wrap an existing
c lib, so you need to actually wrap 2 libs in cython to make them
accessible in python, lol.
If these examples aren't precise enough I will extract the real code
part from my project if you request it.
Thanks for your help, really!
Best Regards.
Toni Barth