All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com,
	lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH 3/8] qapi script: check correctness of discriminator values in union
Date: Wed, 13 Nov 2013 10:30:30 +0800	[thread overview]
Message-ID: <5282E446.3040002@linux.vnet.ibm.com> (raw)
In-Reply-To: <52826F76.7030904@redhat.com>

于 2013/11/13 2:12, Eric Blake 写道:
> On 11/06/2013 12:33 PM, Wenchao Xia wrote:
>> It will check whether the values specified are written correctly when
>> discriminator is a pre-defined enum type, which help check whether the
>> schema is in good form.
>>
>> It is allowed, that not every value in enum is used, so does not check
>> that case.
>
> Again, I think you should require that every value in the enum is used.
>
>>
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>>   scripts/qapi-visit.py |   11 +++++++++++
>>   scripts/qapi.py       |   33 +++++++++++++++++++++++++++++++++
>>   2 files changed, 44 insertions(+), 0 deletions(-)
>>
>> diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
>> index b3d3af8..612dc4d 100644
>> --- a/scripts/qapi-visit.py
>> +++ b/scripts/qapi-visit.py
>> @@ -251,6 +251,17 @@ def generate_visit_union(expr):
>>           assert not base
>>           return generate_visit_anon_union(name, members)
>>
>> +    # If discriminator is specified and it is a pre-defined enum in schema,
>> +    # check its correctness
>> +    enum_define = discriminator_find_enum_define(expr)
>> +    if enum_define:
>> +        for key in members:
>> +            if not key in enum_define["enum_values"]:
>> +                sys.stderr.write("Discriminator value '%s' not found in "
>> +                                 "enum '%s'\n" %
>> +                                 (key, enum_define["enum_name"]))
>> +                sys.exit(1)
>
> This checks for union branches not covered by the enum, but does not
> check for duplicate union branches, nor does it check for enum values
> not covered by a union branch.
>
   I agree that, allowing enum values not covered by union branch,
require more carefully error handling for caller, such as visitors,
will add the check for safty reason.

  reply	other threads:[~2013-11-13  2:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06 19:33 [Qemu-devel] [PATCH 0/8] qapi script: support enum as discriminator and better enum name Wenchao Xia
2013-11-06 19:33 ` [Qemu-devel] [PATCH 1/8] qapi script: remember enum values Wenchao Xia
2013-11-06 19:33 ` [Qemu-devel] [PATCH 2/8] qapi script: report error for default case in union visit Wenchao Xia
2013-11-12 16:51   ` Eric Blake
2013-11-06 19:33 ` [Qemu-devel] [PATCH 3/8] qapi script: check correctness of discriminator values in union Wenchao Xia
2013-11-12 18:12   ` Eric Blake
2013-11-13  2:30     ` Wenchao Xia [this message]
2013-11-06 19:33 ` [Qemu-devel] [PATCH 4/8] qapi script: code move for generate_enum_name() Wenchao Xia
2013-11-12 18:13   ` Eric Blake
2013-11-06 19:33 ` [Qemu-devel] [PATCH 5/8] qapi script: use same function to generate enum string Wenchao Xia
2013-11-06 19:33 ` [Qemu-devel] [PATCH 6/8] qapi script: not generate hidden enum type for pre-defined enum discriminator Wenchao Xia
2013-11-06 19:33 ` [Qemu-devel] [PATCH 7/8] qapi script: do not add "_" for every capitalized char in enum Wenchao Xia
2013-11-06 19:33 ` [Qemu-devel] [PATCH 8/8] tests: add cases for inherited struct and union with discriminator Wenchao Xia

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=5282E446.3040002@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.