[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 10/18] qapi: Anonymous unions
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 10/18] qapi: Anonymous unions |
Date: |
Fri, 26 Jul 2013 09:42:45 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 |
On 07/23/2013 07:03 AM, Kevin Wolf wrote:
> The discriminator for anonymous unions is the data type. This allows to
> have a union type that allows both of these:
>
> { 'file': 'my_existing_block_device_id' }
> { 'file': { 'filename': '/tmp/mydisk.qcow2', 'read-only': true } }
>
> Unions like this are specified in the schema with an empty dict as
> discriminator. For this example you could take:
>
> { 'union': 'BlockRef',
> 'discriminator': {},
> 'data': { 'definition': 'BlockOptions'
Missing comma.
> 'reference': 'str' } }
> { 'type': 'ExampleObject',
> 'data: { 'file': 'BlockRef' } }
>
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> +++ b/docs/qapi-code-gen.txt
> @@ -125,6 +125,31 @@ Resulting in this JSON object:
> "lazy-refcounts": true }
>
>
> +A special type of unions are anonymous unions. They don't form a dictionary
> in
> +the wire format but allow the direct use of different types in their place.
> As
> +they aren't structured, they don't have any explicit discriminator but use
> +the (QObject) data type of their value as an implicit discriminator. This
> means
> +that they are restricted to using only one discriminator value per QObject
> +type. For example, you cannot have two different complex types in an
> anonymous
> +union, or two different integer types.
> +
> +Anonymous unions are declared using an empty dictionary as their
> discriminator.
> +The disriminator values never appear on the wire, they are only used in the
s/disriminator/discriminator/
> +generated C code. Anonymous unions cannot have a base type.
> +
> + { 'union': 'BlockRef',
> + 'discriminator': {},
> + 'data': { 'definition': 'BlockdevOptions'
Missing comma.
> +++ b/qobject/qjson.c
> @@ -260,6 +260,8 @@ static void to_json(const QObject *obj, QString *str, int
> pretty, int indent)
> /* XXX: should QError be emitted? */
> case QTYPE_NONE:
> break;
> + case QTYPE_MAX:
> + abort();
There's another recent patch proposing the use of g_assert_not_reached():
https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg04560.html
but I don't know if it is worth switching abort() over to this function
(and even if it was, there's enough other use of abort in the qapi code
that it would be better to switch it all as a separate patch).
Fix the typos, then you can add:
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
[Qemu-devel] [PATCH 09/18] qapi.py: Maintain a list of union types, Kevin Wolf, 2013/07/23
[Qemu-devel] [PATCH 08/18] qapi: Add consume argument to qmp_input_get_object(), Kevin Wolf, 2013/07/23
[Qemu-devel] [PATCH 10/18] qapi: Anonymous unions, Kevin Wolf, 2013/07/23
- Re: [Qemu-devel] [PATCH 10/18] qapi: Anonymous unions,
Eric Blake <=
[Qemu-devel] [PATCH 11/18] block: Allow "driver" option on the top level, Kevin Wolf, 2013/07/23
[Qemu-devel] [PATCH 13/18] blockdev: Rename I/O throttling options for QMP, Kevin Wolf, 2013/07/23
Re: [Qemu-devel] [PATCH 13/18] blockdev: Rename I/O throttling options for QMP, BenoƮt Canet, 2013/07/26
Re: [Qemu-devel] [PATCH 13/18] blockdev: Rename I/O throttling options for QMP, Eric Blake, 2013/07/26