[PyQt] Possible bug in SIP
Phil Thompson
phil at riverbankcomputing.com
Tue Jul 12 16:40:35 BST 2011
On Tue, 12 Jul 2011 15:52:05 +0100, "Tony Lynch" <tlynch at xype.com> wrote:
>> >
>> > I'm using SIP to wrap a large C++ library
>>
>> I wonder which one that is... :)
>
> You guessed it :-). I have to say that SIP is helping greatly in the
> wrapping process and I'm genuinely impressed at how much functionality
it's
> bringing.
>
>
>> So it's not a bug, it's a
>> conscious decision to do it that way. "Fixing" it would be a change of
>> behaviour which I'm not willing to do for SIP4 - happy to change it for
>> SIP5 though.
>>
>> Phil
>
> I don't know where you are with SIP5 - is there a nightly build I can
> download?
No, and not for a while.
> This issue has a real impact on the code I am working with
> (actually, it crashes because of it). I've made a simple test project to
> demonstrate the issue because I think for us it means that using SIP's
> 'virtual' mechanism and SIP's inheritance mechanism become mutually
> incompatible. I'm sending you direct a tar file of the code, in a
nutshell
> it is:
>
> 3 classes, C inherits B inherits A.
>
> int A::getTypeId() {
> return 1;
> };
>
> int B::getTypeId() {
> return 2;
> };
>
> int C::getTypeId() {
> return 3;
> };
>
>
> In the sip files getTypeId() is only listed for A, and B and C pick it
up
> via SIP's inheritance mechanism. If getTypeId() is not declared as
virtual
> in the sip file then the following python code passes:
>
> from ABC import C
> assert(C().getTypeId() == 3)
>
>
> However, if I declare the method as virtual in the sip file then the
> python test fails (1 is returned).
>
> I can work around the issue here by either (1) redeclaring in sip all
base
> class 'virtual' methods in all the derived classes
That's not a work around - that's what you are supposed to do, ie. tell
SIP about all the implementations.
> or (2) munge the
> generated wrapper cpp code to call e.g. this->getTypeId() instead of
> A::getTypeId().
That will go recursive.
With this particular example you might choose not to wrap getTypeId() at
all and instead use it to implement %ConvertToSubClassCode.
Phil
More information about the PyQt
mailing list