[SPAM: 4.000] Re: [Pyrex] Callback with bound method
Greg Ewing
greg at cosc.canterbury.ac.nz
Mon Jul 19 05:23:23 CEST 2004
On Thu, Jul 08, 2004 at 03:52:51AM +0800, ha shao wrote:
> It seems that the recommend way of wrapping callbacks is using bound
> methods. By my attempt to do it failed:
> cdef class CBClass:
> ...
> cdef void action(self, void *userdata):
> self._callback(<object>userdata)
>
> def addhook(acb, adata):
> ...
> add_cb(cbobj.action, <void*> adata)
You're trying to create a bound method from a C method,
which won't work. There is no such thing as a bound C method,
only bound Python methods.
The function you install as the C callback must be a
top-level C function (not a method). All the context it
needs will have to be passed in via the userdata somehow.
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg at cosc.canterbury.ac.nz +--------------------------------------+
More information about the Pyrex
mailing list