From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Fam Zheng <famz@redhat.com>,
qemu-devel@nongnu.org, wenchaoqemu@gmail.com,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 06/19] qapi: Better error messages for bad enums
Date: Tue, 23 Sep 2014 09:59:26 -0600 [thread overview]
Message-ID: <542198DE.4030504@redhat.com> (raw)
In-Reply-To: <874mvyiffi.fsf@blackfin.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 4819 bytes --]
On 09/23/2014 08:23 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
>
>> The previous commit demonstrated that the generator had several
>> flaws with less-than-perfect enums:
>> - an enum that listed the same string twice (or two variant
>> strings that map to the same C enum) ended up generating an
>> invalid C enum
>> - because the generator adds a _MAX terminator to each enum,
>> the use of an enum member 'max' can also cause this clash
>> - if an enum omits 'data', the generator left a python stack
>> trace rather than a graceful message
>> - an enum used a non-array 'data' was silently accepted by
>> the parser
>> - an enum that used non-string members in the 'data' member
>> was silently accepted by the parser
>>
>> Add check_enum to cover these situations, and update testcases
>> to match. While valid .json files won't trigger any of these
>> cases, we might as well be nicer to developers that make a typo
>> while trying to add new QAPI code.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---
>> --- a/tests/qapi-schema/enum-clash-member.err
>> +++ b/tests/qapi-schema/enum-clash-member.err
>> @@ -0,0 +1 @@
>> +tests/qapi-schema/enum-clash-member.json:2: enum 'MyEnum' member 'ONE' clashes with 'one'
>> diff --git a/tests/qapi-schema/enum-clash-member.exit b/tests/qapi-schema/enum-clash-member.exit
>> index 573541a..d00491f 100644
>> --- a/tests/qapi-schema/enum-clash-member.exit
>> +++ b/tests/qapi-schema/enum-clash-member.exit
>> @@ -1 +1 @@
>> -0
>> +1
>> diff --git a/tests/qapi-schema/enum-clash-member.json b/tests/qapi-schema/enum-clash-member.json
>> index cb4b428..c668ff5 100644
>> --- a/tests/qapi-schema/enum-clash-member.json
>> +++ b/tests/qapi-schema/enum-clash-member.json
>> @@ -1,2 +1,2 @@
>> -# FIXME: we should reject enums where members will clash in C switch
>> +# we reject enums where members will clash in C switch
>> { 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] }
>
> Actually in PATCH 05 already: "clash in C switch". I guess you mean we
> generate an enum with clashing enumeration constants. In the test case,
> we'd generate MY_ENUM_ONE (I think) both for 'one' and 'ONE'. Correct?
Correct; the generated C code would include an invalid switch statement
with two repetitions of the same spelling of a case label. In patch 5,
the test case demonstrates that the parser was silently accepting code
that resulted in a clash in the generated C code; this patch updates
both qapi.py to make it a hard error, and the testsuite to change from
(accidental) pass to (intentional) error detection, so that we no longer
have to worry about the issue in the generated C code.
The same principle applies throughout my series - I first introduced new
tests in isolation for existing pre-patch behavior, with FIXME comments
where the tests expose bogus behavior, then in later patches fix the
parser to reject bogus behavior and update the test to match that it now
covers the new error message.
>> +++ b/tests/qapi-schema/enum-dict-member.err
>> @@ -0,0 +1 @@
>> +tests/qapi-schema/enum-dict-member.json:2: enum 'MyEnum' member 'OrderedDict([('value', 'str')])' is not a string
>
> Error message is in terms of implementation instead of source. Since
> this is merely a development tool, it'll do. Same elsewhere, and I'm
> not going to flag it. Precedents in master quite possible.
Yeah, I couldn't figure a way to get back at the original text typed by
the user. I'm open to suggestions, but I'm (obviously) okay with
leaving it as is.
>> +++ b/tests/qapi-schema/enum-max-member.json
>> @@ -1,3 +1,3 @@
>> -# FIXME: we should either reject user-supplied 'max', or munge the implicit
>> -# max value we generate at the end of an array
>> +# we reject user-supplied 'max' for clashing with implicit enum end
>> +# FIXME: should we instead munge the the implicit value to avoid the clash?
>
> Or pick an identifier for the max member so that it cannot clash with
> the ones we generate for the user's members.
>
> The generator picks identifiers pretty much thoughtlessly in general.
> If something clashes, the C compiler spits it out, and you get to fiddle
> with the .json.
Well, hopefully by hoisting the error message away from C compilation
time (late) to qapi.py runtime (early), we have made it easier for
anyone actually needing the name 'max' to identify what still needs
fixing. At any rate, I'm always a fan of erroring out as early as
possible, rather than waiting for an obscure crash later on in the C
compilation :)
>
> [...]
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
Thanks.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
next prev parent reply other threads:[~2014-09-23 15:59 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 22:24 [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 01/19] qapi: Consistent whitespace in tests/Makefile Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 02/19] qapi: Ignore files created during make check Eric Blake
2014-09-23 8:07 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 03/19] qapi: Update docs given recent event, spacing fixes Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 04/19] qapi: Document type-safety considerations Eric Blake
2014-09-22 12:37 ` Markus Armbruster
2014-09-22 16:53 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 05/19] qapi: Add some enum tests Eric Blake
2014-09-22 12:43 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 06/19] qapi: Better error messages for bad enums Eric Blake
2014-09-23 14:23 ` Markus Armbruster
2014-09-23 15:59 ` Eric Blake [this message]
2014-09-24 7:46 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 07/19] qapi: Add some expr tests Eric Blake
2014-09-23 14:26 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions Eric Blake
2014-09-23 14:56 ` Markus Armbruster
2014-09-23 16:11 ` Eric Blake
2014-09-24 7:34 ` Markus Armbruster
2014-09-24 9:25 ` Kevin Wolf
2014-09-24 11:14 ` Markus Armbruster
2014-09-26 9:15 ` Markus Armbruster
2014-09-26 9:25 ` Kevin Wolf
2014-09-26 11:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 09/19] qapi: Add tests of redefined expressions Eric Blake
2014-09-24 11:24 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 10/19] qapi: Better error messages for duplicated expressions Eric Blake
2014-09-24 11:58 ` Markus Armbruster
2014-09-24 14:10 ` Eric Blake
2014-09-24 15:29 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 11/19] qapi: Add tests of type bypass Eric Blake
2014-09-24 16:10 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 7:34 ` Markus Armbruster
2014-09-25 8:06 ` Markus Armbruster
2014-09-25 14:00 ` Eric Blake
2014-09-25 16:19 ` Markus Armbruster
2015-03-23 15:33 ` [Qemu-devel] RFC: 'alternate' qapi top-level expression [was: [PATCH v4 12/19] qapi: Add some type check tests] Eric Blake
2015-03-23 19:28 ` Markus Armbruster
2014-09-25 13:54 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 16:12 ` Markus Armbruster
2014-09-25 16:32 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 13/19] qapi: More rigourous checking of types Eric Blake
2014-09-26 9:26 ` Markus Armbruster
2014-09-29 8:27 ` Markus Armbruster
2014-09-29 14:26 ` Eric Blake
2014-09-29 14:35 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass Eric Blake
2014-09-29 8:38 ` Markus Armbruster
2014-09-29 14:33 ` Eric Blake
2014-09-29 16:35 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 15/19] qapi: Merge UserDefTwo and UserDefNested in tests Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 16/19] qapi: Drop tests for inline subtypes Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 17/19] qapi: Drop inline subtype in query-version Eric Blake
2014-09-30 17:40 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 18/19] qapi: Drop inline subtype in query-pci Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 19/19] qapi: Drop support for inline subtypes Eric Blake
2014-09-30 17:47 ` Markus Armbruster
2014-09-26 15:42 ` [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
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=542198DE.4030504@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wenchaoqemu@gmail.com \
/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).