On May 19, 2009, at 1:45 PM, Chris Colbert wrote: > how do a pass a pointer to a C datatype to my python extension type > constructor? I have the following in my code: > > > #### in a cdef extern from .h block ###### > struct _IplImage: > <filler> > ctypedef _IplImage IplImage > > > ###### extension type declaration ####### > cdef class PyIplImage: > > cdef IplImage* img > cdef readonly int width, height > > def __cinit__(self, IplImage* imgptr): > self.img = imgptr > self.width = self.img[0].width > self.height = self.img[0].height > > > ###### test functions ################# > > cdef IplImage* load(char* filename): > cdef IplImage* img = cvLoadImage(filename, 1) > > return img > > def testload(filename): > cdef IplImage* img = load(filename) > pyimg = PyIplImage(img) > return pyimg > > > Cython compilation errs with "Cannot convert IplImage* to python > object"
Unfortunately, you can't, because the parameters to __cinit__ are the same parameters to __init__ which are fixed to be Python objects. What you can do is allow it to pass in a char* (bytes) object with a length, have a cdef set method, use opaque object pointer wrappers (there was a previous thread about this). You could also make a function > def testload(filename): > cdef IplImage* img = load(filename) > cdef PyIplImage pyimg = PyIplImage > pyimg.img = img > return pyimg - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
