[PyQt] Partial support for scoped enums

Phil Thompson phil at riverbankcomputing.com
Fri Aug 11 15:46:25 BST 2017


On 10 Aug 2017, at 1:59 pm, Shaheed Haque <srhaque at theiet.org> wrote:
> 
> Hi,
> 
> I think that SIP makes a partial attempt to support so-called "scoped enums" in gencode.c in that enums are emitted with a static_cast<int> like this:
> 
> static sipEnumMemberDef enummembers_KWindowSystem[] = {
>     {sipName_ClassHint, static_cast<int>( ::KWindowSystem::ClassHint), 15},
>     {sipName_NETWM, static_cast<int>( ::KWindowSystem::NETWM), 15},
>     {sipName_Unknown, static_cast<int>( ::KWindowSystem::Unknown), 16},
>     {sipName_WMHints, static_cast<int>( ::KWindowSystem::WMHints), 15},
>     {sipName_Wayland, static_cast<int>( ::KWindowSystem::Wayland), 16},
>     {sipName_X11, static_cast<int>( ::KWindowSystem::X11), 16},
>     {sipName_XApp, static_cast<int>( ::KWindowSystem::XApp), 15},
> };
> 
> However, there are a couple of parts missing. One missing part is that the emitted code has two calls to "sipConvertFromEnum()", and I think that each call needs a similar static_cast<int> applied to the first argument.

That will be fixed in tonight's snapshot.

> I'm not so sure about the fix for the second missing part. Looking at the above set of enums. It turns out that ::KWindowSystem::{Unknown,Wayland,X11} actually should be emitted as ::KWindowSystem::Platform::{Unknown,Wayland,X11} as that is a scoped enum in the C++ code:
> 
>     enum class Platform {
>         Unknown,
>         X11,
>         Wayland
>     };
> 
> The relevant logic is near line sipgen.c:3270 (in 4.19.4.dev1708081632) and the correct prefix is available in the data:
> 
> (gdb) p *emd->ed.cname
> $49 = {nameflags = 1, text = 0x5555582be010 "KWindowSystem::Platform", len = 23, offset = 634, next = 0x5555582bc880}
> 
> However, the code presently ends up calling 'prcode(fp, "%S::", classFQCName(ecd))' for the result as above. I am unclear as to the correct change to the logic around here though.
> 
> It would be great to get these two fixed (I have a trivial patch for the first part if needed).

It's a bit more complicated than that. I'll talk about it in a separate posting.

Phil


More information about the PyQt mailing list