[Pyrex] using c-methods for callbacks?
Lenard Lindstrom
len-l at telus.net
Sat May 30 06:00:22 CEST 2009
horace wrote:
> hi,
>
> it would be great if i could use c-methods for callbacks but i always
> get a crash if i access self. am i doing something wrong or doesn't
> self get assigned correctly if the method gets called from a c-library?
>
> cdef class Engine:
> ...
> cdef void on_space(self): # i pass this to the c-library to be used
> as the callback
> print "test!" # this works
> print self # this crashes
> ------------------------------------------------------------------------
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
ctypes creates C closures through libffi. That binds the self argument
with a value. Cython won't do that. It requires assembly code, so is not
portable. You either have to get your function's arguments through
global variables or hope the callback mechanism includes an argument
passing mechanism. If that later, I don't know exactly how to convert a
Python object to a void pointer and back in Cython. If the callbacks are
passed a keyboard key argument by the caller then that could be used as
a key into a dictionary of Python functions.
Lenard Lindstrom
<len-l at telus.net>
PS. Could you disable automated out-of-office replies for postings to
this mailing list? The replies don't go to the list, but rather to the
person making the post.
L.
More information about the Pyrex
mailing list