Likely (never used ctypes) you will need to call "ctypes.addressof", and a call to PyLong_AsVoidPtr(). See yourself:
http://svn.python.org/view/python/trunk/Modules/_ctypes/callproc.c?view=markup http://docs.python.org/c-api/long.html#PyLong_AsVoidPtr cdef extern from "Python.h" void *PyLong_AsVoidPtr(object) cdef object iptr = ctypes.addressoff(pyimg) # assuming pyimg was a ctypes instance cdef IplImage *dst = <IplImage *>PyLong_AsVoidPtr(iptr) with nogil: dst = clone(dst) Disclaimer: NEVER used ctypes myself... But the above code should be near... In general, you will have to be very careful if you want to mix ctypes and Cython. They are different beast ... Once you get used to code Cython, and assuming you have some C/C++ background, I bet you will stop using ctypes ;-) .. well, except perhaps for the purposes of supporting your own legacy code ... On Mon, May 18, 2009 at 10:40 PM, Chris Colbert <[email protected]> wrote: > yet again: > > for various reasons, I would like to use both the ctypes wrapper and cython > in same program. Specifically I have a ctypes instance of an OpenCV image. I > pass the pointer of this image to a cython function which returns a pointer > to a new image. I need to get this pointer back into python as a new image. > The following cython code complains that it cant convert the pointer to a > python object. but thats exactly the purpose of the POINTER() call from > ctypes (from what I gather). > > Here is the code: > > from ctypes import * > > cdef extern from "cxtypes.h": > ctypedef struct IplImage: > pass > > cdef extern from "cxcore.h": > cdef IplImage* cvCloneImage(IplImage* img) nogil > > > cdef IplImage* clone(IplImage* img) nogil: > cdef IplImage* out = cvCloneImage(img) > return out > > > def myclone(pyimg): > cdef IplImage* dst > with nogil: > dst = clone(byref(pyimg)) > > pydst = POINTER(dst) > return pydst > > > any ideas? > > Chris > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
