[PyQt] How to avoid duplication in SIP?
Shaheed Haque
srhaque at theiet.org
Sun Apr 16 12:41:02 BST 2017
FWIW, I worked around this with a bunch of hand-written rules to fixup
the dupes.
I observe there is an "impedance mismatch" between C++ and SIP where
(roughly speaking) the former accepts duplicate identical definitions
as equivalent and SIP does not. Another example is that it is not
allowed to mark the same class /External/ more than once (I thought
had asked about that before, but I cannot find the reference right
now). Ditto for duplicate typedefs. This does make things difficult
for generated code especially as the set of C++ headers which tend to
be collected in a XXXmod.sip file will often be created with similar
forward declarations, and so on.
My conversion code has a layer which handles this in most cases for
the scope of XXXmod.sip, but not (as in this case) across XXXmod.sip
and YYYmod.sip.
On 10 April 2017 at 00:51, Shaheed Haque <srhaque at theiet.org> wrote:
> I believe that would need a sip parser to work that out, at least in the
> case A was not created by me.
>
> Mind you i guess the Feature guard idea would fail in the same case.
>
> Is there perhaps a way to mark a mapped type as local to the defining
> module?
>
> On 9 Apr 2017 10:24 pm, "Phil Thompson" <phil at riverbankcomputing.com> wrote:
>>
>> On 9 Apr 2017, at 4:05 pm, Shaheed Haque <srhaque at theiet.org> wrote:
>> >
>> > A recurring problem with my SIP generator efforts is the need to deal
>> > with duplicate SIP code. So far, I've been able to use the SIP concept
>> > of a "feature" to deal with various manifestations of this, but I have
>> > now hit one that has me stumped:
>> >
>> > - Module A has a mapped type MTA (e.g. QPair<init, int>)
>> > - Module B imports A, but also needs a mapped type for QPair<int, int>.
>> >
>> > when the generator runs for module B, it is not aware of MTA, so it
>> > ends up emitting MTB for its QPair<init, int>. Of course, when I run
>> > SIP on B, MTA and MTB collide.
>> >
>> > Is there something already in SIP I could use to say "this duplicate
>> > is fine"? If not, would it be possible to add support for the SIP
>> > equivalent of a define guard, along the lines "#define
>> > feature"/"#ifdef feature"?
>> >
>> > I realise that by generating the SIP code, I'm in a minority of SIP
>> > users, but such a feature would also significantly simplify certain
>> > other scenarios that affect me too.
>>
>> Why not fix your generator so that B knows the mapped type is defined
>> elswhere?
>>
>> Phil
More information about the PyQt
mailing list