[PyKDE] PyBuffer_FromMemory

Phil Thompson phil at riverbankcomputing.co.uk
Sat Mar 6 00:28:01 GMT 2004


On Friday 05 March 2004 20:14, Claus, Richard wrote:
> Does PyBuffer_FromMemory make a copy of the passed in buffer?

Looking at the Python source, no.

> Does 
> PyString_FromStringAndSize?

Looking at the Python source, yes.

> sipqtnetworkQSocket.cpp (generated from the .sip) appears to malloc,
> PyString_FromStringAndSize, free and then return the result.  In my case,
> my buffer is small (32 bytes) so I tried creating it on the stack (in the
> sip code), called PyBuffer_FromMemory, returned the result and found junk
> in the result on the Python side.  The solution I've used thus far has been
> to create the scratch buffer in Python, pass it in to the C++,
> PyBuffer_FromMemory it and return the result.  Seems to work but is ugly. 
> Is there a better way?

Depends what you are trying to achieve by using buffers.

> Are sipMalloc and sipFree doing something behind 
> the scenes that's not obvious?

No.

Phil




More information about the PyQt mailing list