[Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
I know that Cython does an implicit conversion from char* to Python string, but do I need to somehow specify the length of the string? I ask because I have a data buffer of known size (7854000 bytes uint8) but when i pass the pointer to that buffer into python, my string length is only 4617. this

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Lisandro Dalcin
On Tue, May 19, 2009 at 9:05 PM, Chris Colbert sccolb...@gmail.com wrote: I know that Cython does an implicit conversion from char* to Python string, but do I need to somehow specify the length of the string? But then Cython assumes you string is a NULL-terminated one. In other words, you

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
Lisandro, Once again, thank you! I think I finally have a tricky question for you now however: I have the OpenCV IplImage class wrapped as so: cdef class IplImage: cdef c_cxcore.IplImage* thisptr #Convienience Functions def show(self): #

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Lisandro Dalcin
Any chance that cvQueryFrame() returns an image that you should not free?? When you do twice: img = cam.queryFrame() img = cam.queryFrame() the first img is likely garbage-collected. Perhaps your Image.__dealloc__ is not doing the right thing in this case? Could you try to do: cam =

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Chris Colbert
Any chance that cvQueryFrame() returns an image that you should not free?? that's exactly it (i feel really dumb for having missed it) the first img is likely garbage-collected. Perhaps your Image.__dealloc__ is not doing the right thing in this case? would you suggest setting a private

Re: [Cython] returning a char* as a python string

2009-05-19 Thread Lisandro Dalcin
Such a flag would work... For example, IIUC ctypes does this (I'm remembering a 'needs_free' attribute or something like that on some ctypes instances...) Just in case, I'll ask... Any chance the library you are using has some sort of reference count mechanism? If it do, you sould rely on that