From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2kAK-0001JD-Uj for qemu-devel@nongnu.org; Fri, 26 Jul 2013 11:42:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2kAJ-0007hH-NO for qemu-devel@nongnu.org; Fri, 26 Jul 2013 11:42:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2kAJ-0007hB-Eh for qemu-devel@nongnu.org; Fri, 26 Jul 2013 11:42:47 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6QFgkaX029171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Jul 2013 11:42:46 -0400 Message-ID: <51F298F5.2070006@redhat.com> Date: Fri, 26 Jul 2013 09:42:45 -0600 From: Eric Blake MIME-Version: 1.0 References: <1374584606-5615-1-git-send-email-kwolf@redhat.com> <1374584606-5615-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1374584606-5615-11-git-send-email-kwolf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Wd02FB41KncS2JqfxEFalaJlqkrfs81ln" Subject: Re: [Qemu-devel] [PATCH 10/18] qapi: Anonymous unions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: armbru@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Wd02FB41KncS2JqfxEFalaJlqkrfs81ln Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: >=20 > { 'file': 'my_existing_block_device_id' } > { 'file': { 'filename': '/tmp/mydisk.qcow2', 'read-only': true } } >=20 > Unions like this are specified in the schema with an empty dict as > discriminator. For this example you could take: >=20 > { 'union': 'BlockRef', > 'discriminator': {}, > 'data': { 'definition': 'BlockOptions' Missing comma. > 'reference': 'str' } } > { 'type': 'ExampleObject', > 'data: { 'file': 'BlockRef' } } >=20 > Signed-off-by: Kevin Wolf > --- > +++ b/docs/qapi-code-gen.txt > @@ -125,6 +125,31 @@ Resulting in this JSON object: > "lazy-refcounts": true } > =20 > =20 > +A special type of unions are anonymous unions. They don't form a dicti= onary in > +the wire format but allow the direct use of different types in their p= lace. 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. T= his means > +that they are restricted to using only one discriminator value per QOb= ject > +type. For example, you cannot have two different complex types in an a= nonymous > +union, or two different integer types. > + > +Anonymous unions are declared using an empty dictionary as their discr= iminator. > +The disriminator values never appear on the wire, they are only used i= n 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 *st= r, 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 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Wd02FB41KncS2JqfxEFalaJlqkrfs81ln Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJR8pj1AAoJEKeha0olJ0NqehAIAIoCg37F4Otg4doGBJm/pA74 iWEAHn/O68/Onm52ToA3ar3pJRvR5NvkDk1Hc1EVc+EqOOoPIgMiHsOCUt+kUKa1 PmMMMX9qHYrYl34YXQMBoUuwOYEhLGio5o5jjwCxZa5USXZIuDdXOr6pfl9eaPv/ Udh1eg+MKksKgy1wygLv/10++J2hKWeJNp0wvZQ9wFoRv/xGOF54P7nc8lqUZITS XrS48N3DIh1JYbf0gdKqzzGJL4+Fna/mcyifOE6sn0fp/L8NpbeWcAxfUCIjF8cd Djz3BKw5kzK3LQA27V/bKGIvrvEnfLLs3iy4cE/lrGE8T8zXyEOqoeD8DxioVA0= =mMTg -----END PGP SIGNATURE----- --Wd02FB41KncS2JqfxEFalaJlqkrfs81ln--