[PyQt] KeepReference in constructors for wrapped instances

Phil Thompson phil at riverbankcomputing.co.uk
Mon Feb 21 18:52:07 GMT 2011


On Tue, 15 Feb 2011 14:13:42 +0100, Giovanni Bajo <rasky at develer.com>
wrote:
> Hi Phil,
> 
> given the following (pseudo) sip file:
> 
> ===================================================
> class Manager
> { ... };
> 
> class User
> {
> public:
>      User(Manager * /KeepReference=0/);
>      void changeManager(Manager * /KeepReference=0/);
> }
> ===================================================
> 
> it looks like the internal sip_api_keep_reference is not called when
> passing through the constructor. Not only the generated .cpp file does
> not have an explicit call to sipKeepReference() in the constructor
> (whilst it calls it for the changeManager method), but even stepping
> through code in the argument-parsing function I couldn't see any calls
> to sip_api_keep_reference.
> 
> I also checked PyQt, but it looks like /KeepReference/ in constructors
> is only used for classes like QLatin1String, for a "const char*"
> argument, which is special-cased in the argument-parsing code with
> letter 'A'. I could not find any usage of KeepReference for wrapped
> instances in PyQt constructors, probably because the Qt ownership system
> is a superset of its functionality.
> 
> The documentation does not mention anything specific about KeepReference
> in constructors.
> 
> Is it a bug in SIP?
> 
> BTW I'm using SIP 4.10, though I checked the changelog and the Mercurial
> history and I could only find minimal changes in the keep reference
> code.
> 
> Thanks!

Hmm - I'm surprised that hasn't been reported before now.

Fixed in hg.

Thanks,
Phil


More information about the PyQt mailing list