[PyQt] Partial support for scoped enums

Shaheed Haque srhaque at theiet.org
Thu Aug 10 13:59:50 BST 2017


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.

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).

Thanks, Shaheed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170810/2aba5055/attachment.html>


More information about the PyQt mailing list