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)


a = mytime[0]()

print a


Error converting Pyrex file to C:
------------------------------------------------------------
...
libc = CDLL('libc.so.6')
timefunc = libc.time

cdef object tptr = ctypes.addressof(timefunc)
cdef int (*mytime)()
mytime = PyLong_AsVoidPtr(tptr)
                        ^
------------------------------------------------------------

/home/brucewayne/Desktop/cytypestest.pyx:13:25: Cannot assign type
'void *' to 'int (*)(void)'



Any ideas how to get that at that pointer? I'm open to ideas that
involve the use of really big hammers ;)

Cheers!

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

Reply via email to