qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V7 04/11] qapi script: check correctness of disc


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH V7 04/11] qapi script: check correctness of discriminator values in union
Date: Thu, 20 Feb 2014 08:26:25 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 02/20/2014 07:43 AM, Markus Armbruster wrote:
> Wenchao Xia <address@hidden> writes:
> 
>> It will check whether base is set, whether discriminator is found
>> in base, whether the values specified are written correctly, and
>> whether all enum values are covered, when discriminator is a

> 
> And every member of the discriminator enum type must also occur as key
> of the union's member 'data'.  Why?
> 
> Consider:
> 
>     { 'enum': 'FooEnum', 'data': [ 'plain', 'bells', 'whistles' ] }
> 
>     { 'type': 'CommonFooOptions',
>       'data': { 'type: 'FooType', 'readonly': 'bool' } }
>     { 'union': 'FooOptions',
>       'base': 'CommonFooOptions',
>       'discriminator': 'type',
>       'data': { 'bells': 'BellsOptions',
>                 'whistles': 'WhistlesOptions' } }
> 
> Type 'plain' doesn't have options beyond CommonFooOptions.

I'd still rather make it explicit that we KNOW that this branch of the
union has no additional options:

{ 'union': 'FooOptions',
  'base': 'CommonFooOptions',
  'discriminator': 'type',
  'data': { 'plain': {},
            'bells': 'BellsOptions',
            'whistles': 'WhistlesOptions' } }

to show that we explicitly thought about all the cases.  We don't
currently have any such unions with an empty branch, but it would be
worth documenting in the qapi text and explicitly testing that it works
if we intend to support this.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]