From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: [Qemu-devel] Problem with discriminated unions with enum prefixes
Date: Tue, 16 Feb 2016 17:35:40 +0000 [thread overview]
Message-ID: <20160216173540.GG11370@redhat.com> (raw)
In my LUKS encryption series, I have a discriminated union for
storing options for different encryption formats. See qapi/crypto.json
in this file:
https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03187.html
You'll notice I have the 'prefix' line for the enum commented out. When
I uncomment this, I discovered that the discriminated union visitor does
not deal with prefixes.
To save having to wade through that big series, here is a quick
reproducer
diff --git a/qapi-schema.json b/qapi-schema.json
index 8d04897..a58648d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4083,3 +4083,22 @@
##
{ 'enum': 'ReplayMode',
'data': [ 'none', 'record', 'play' ] }
+
+
+{ 'enum': 'QDemoType',
+ 'prefix': 'QDEMO_TYPE',
+ 'data': ['foo', 'bar' ] }
+
+{ 'struct': 'QDemoBase',
+ 'data': { 'type': 'QDemoType' } }
+
+{ 'struct': 'QDemoFoo',
+ 'data': { 'eek': 'int' } }
+
+{ 'struct': 'QDemoBar',
+ 'data': { 'wizz': 'str' } }
+
+{ 'union': 'QDemo',
+ 'base': 'QDemoBase',
+ 'discriminator': 'type',
+ 'data': { 'foo': 'QDemoFoo', 'bar': 'QDemoBar' } }
Apply that and then try to build and it'll fail with:
qapi-visit.c: In function ‘visit_type_QDemo’:
qapi-visit.c:7596:10: error: ‘Q_DEMO_TYPE_FOO’ undeclared (first use in this function)
case Q_DEMO_TYPE_FOO:
^
qapi-visit.c:7596:10: note: each undeclared identifier is reported only once for each function it appears in
qapi-visit.c:7599:10: error: ‘Q_DEMO_TYPE_BAR’ undeclared (first use in this function)
case Q_DEMO_TYPE_BAR:
^
The issue is that we used the 'QDEMO_TYPE' custom prefix for generating the
enum, but we didn't use the prefix in the union visitor.
I know we had had previous discussions with Markus strongly wanting to kill
off the support for enum prefixes. So before I waste time trying to fix
this union visitor code to handle prefixes, I figure we should decide if
we actually want to fix it, or go with Markus' plan to kill custom prefixes
on enums.
Per previous discussions, I think the ability to have custom prefixes is
quite desirable, to get more natural enum constant names. At the end of
the day though, the default enum naming is far from the worst bit of
QEMU, so I'm not ultimately too bothered either way. We either make
custom enum prefixes work everything they need to, or remove them.
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next reply other threads:[~2016-02-16 17:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 17:35 Daniel P. Berrange [this message]
2016-02-16 17:45 ` [Qemu-devel] Problem with discriminated unions with enum prefixes Eric Blake
2016-02-17 10:19 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160216173540.GG11370@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).