[PyKDE] SIP: /Array/ and memory deallocation

Giovanni Bajo rasky at develer.com
Wed Mar 22 13:43:12 GMT 2006


Hello,

I have an API like this:

class Foo
{
public:
    Foo(char *filename);
    Foo(char *buffer, int size);
    [...]
};

To make both construction forms work, I have wrapped the second constructor
as a staticmethod factory, using /Array/ and /ArraySize/ (this is because
overload resolution can't work, as both forms would get a Python string
object).

The problem is the ownership of the buffer pointer. The C++ Foo API expects
the buffer to stay alive for the lifetime of the Foo instance. Is there an
immediate way to implement this? I was thining of storing the buffer as
Pything string object in a "secret" member of the Foo wrapped instance. Does
that sound like a good solution?

Thanks
-- 
Giovanni Bajo




More information about the PyQt mailing list