[PyQt] Arrays in SIP

Phil Thompson phil at riverbankcomputing.com
Tue Sep 5 17:42:30 BST 2017


On 5 Sep 2017, at 5:39 pm, Shaheed Haque <srhaque at theiet.org> wrote:
> 
> 
> 
> On 5 Sep 2017 17:00, "Phil Thompson" <phil at riverbankcomputing.com> wrote:
> On 2 Sep 2017, at 3:29 am, Shaheed Haque <srhaque at theiet.org> wrote:
> >
> > Hi,
> >
> > Can I just check my understanding of simple arrays in SIP? Given the
> > following C++
> >
> > ===========
> > enum E
> > {
> >    A,
> >    B
> > };
> >
> > static const E e[] = { A, A, B, B };
> > ===========
> >
> > I think that the best SIP I can come up with is:
> >
> > ===========
> > %Module(name=foo)
> >
> > enum E
> > {
> >    A,
> >    B
> > };
> >
> > const E *e /NoSetter/;
> > ===========
> >
> > (I also tried SIP_PYBUFFER etc.) But of course, that needs %GetCode,
> > and %GetCode is not allowed outside class scope. Are *any* arrays
> > possible outside class scope?
> 
> Arrays aren't really supported by SIP at all.
> 
> I get that...
> 
> You'd have to provide hand-written code that implements the sequence protocol and proxies for the underlying array.
> 
> ...and for N-dimensional array variable members of classes, I already generate the needed %GetCode etc. Can you clarify what directives I could use to "host" the generated code in this case, where the variable is not in a class?
> 
> (Although as this case is const you could get away with creating a tuple with the same elements.)
> 
> Acknowledged. But even for SIP_PYTUPLE, I'd need the same directives wouldn't I?

You have to write pure C code - no help from SIP.

Phil


More information about the PyQt mailing list