[PyKDE] Re: SIP: difference between TransferBack and Factory

Phil Thompson phil at riverbankcomputing.co.uk
Wed Oct 26 10:11:16 BST 2005


On Wednesday 26 October 2005 12:30 am, Giovanni Bajo wrote:
> Hello,
>
> Having read the SIP documentation, it is not clear to me what is the
> difference between using TransferBack and using Factory as annotation for a
> function. It *looks* like Factory should be used for new objects, and
> TransferBack for objects that existed "before" (for some meaning of
> before). My doubt is: why does SIP care whether the function just created
> the object, or got it from somewhere else, as long as the semantic is that
> Python will own the object after the call? Why should it care whether it
> already seen it as a Python object or not?
>
> Can anybody elaborate a little?

In C/C++ you have have multiple instances at the same address (eg. if a 
structure is the first member of another structure). Therefore it is possible 
that when mapping a C++ address to the corresponding Python object, SIP gets 
the wrong one. There is little that can be done about it, but it is very 
unlikely to happen. (It did happen in a much earlier version but was resolved 
in that particular case by taking the expected types into account - this 
makes it even less likely but still possible.)

By using Factory you are saying it is a new instance, even if SIP already 
knows of an existing instance of a compatible type at the same address.

Phil




More information about the PyQt mailing list