Chris Colbert wrote:
> Given our previous conversation, it will probably be easier to use
> ctypes to get the function handles for dynamically loaded libraries
> and *somehow* get that function pointer into Cython.
>
> My attempt is like so (for a simple example) but Cython is complaining
> during compilation:
>
>
> from ctypes import *
>
> cdef extern from "Python.h":
> void* PyLong_AsVoidPtr(object)
>
> cdef int a
>
> libc = CDLL('libc.so.6')
> timefunc = libc.time
>
> cdef object tptr = ctypes.addressof(timefunc)
> cdef int (*mytime)()
> mytime = PyLong_AsVoidPtr(tptr)
>
I think this should do it:
ctypedef int (*timefuncptr)()
cdef timefuncptr mytime
mytime = <timefuncptr>ctypes.addressof(libc.time)
That is, unless ctypes.addressof returns the address of the *pointer* to
the function stored in libc.time (I'm not familiar enough with ctypes).
In that case it is instead:
mytime = (<timefuncptr*>ctypes.addressof(libc.time))[0]
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev