From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb9g9-00008l-Rt for qemu-devel@nongnu.org; Thu, 26 Mar 2015 11:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yb9g6-0005Yl-Ln for qemu-devel@nongnu.org; Thu, 26 Mar 2015 11:26:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yb9g6-0005YV-FK for qemu-devel@nongnu.org; Thu, 26 Mar 2015 11:26:38 -0400 Message-ID: <5514252C.7040901@redhat.com> Date: Thu, 26 Mar 2015 09:26:36 -0600 From: Eric Blake MIME-Version: 1.0 References: <1427227433-5030-1-git-send-email-eblake@redhat.com> <1427227433-5030-11-git-send-email-eblake@redhat.com> <87d23v24uv.fsf@blackfin.pond.sub.org> In-Reply-To: <87d23v24uv.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CNckeVhSCGHEbeH8KgNsS1oXPKNknSTJv" Subject: Re: [Qemu-devel] [PATCH v5 10/28] qapi: Segregate anonymous unions into alternates in generator List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, lcapitulino@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, wenchaoqemu@gmail.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CNckeVhSCGHEbeH8KgNsS1oXPKNknSTJv Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/26/2015 08:47 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> Special-casing 'discriminator =3D=3D {}' for handling anonymous unions= >> is getting awkward; since this particular type is not always a >> dictionary on the wire, it is easier to treat it as a completely >> different class of type, "alternate", so that if a type is listed >> in the union_types array, we know it is not an anonymous union. >> >> This patch just further segregates union handling, to make sure that >> anonymous unions are not stored in union_types, and splitting up >> check_union() into separate functions. A future patch will change >> the qapi grammar, and having the segregation already in place will >> make it easier to deal with the distinct meta-type. >> >> Signed-off-by: Eric Blake >> --- >> @@ -535,7 +546,8 @@ def find_struct(name): >> >> def add_union(definition): >> global union_types >> - union_types.append(definition) >> + if definition.get('discriminator') !=3D {}: >> + union_types.append(definition) >> >> def find_union(name): >> global union_types >=20 > This is the only unobvious hunk. >=20 > union_types is used only through find_union. The hunk makes > find_union(N) return None when N names an anonymous union. >=20 > find_union() is used in two places: >=20 > * find_alternate_member_qtype() >=20 > Patched further up. It really wants only non-anonymous unions, and > this change to find_union() renders its check for anonymous unions > superfluous. Good. >=20 > * generate_visit_alternate() >=20 > Asserts that each member's type is either a built-in type, a complex > type, a union type, or an enum type. >=20 > The change relaxes the assertion not to trigger on anonymous union > types. Why is that okay? No, the change tightens the assertion so that it will now fail on an anonymous union nested as a branch of another anonymous union (where before it could silently pass the assertion), because the anonymous union is no longer found by find_union(). And this is okay because the earlier change to find_alternate_member_qtype means that we don't allow nested anonymous unions, so making the assertion fail if an anonymous union gets through anyway is correct. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --CNckeVhSCGHEbeH8KgNsS1oXPKNknSTJv 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVFCUsAAoJEKeha0olJ0NqnjAH/3vQkdH81teS8EE9NuQn5h8g FUXEISTer9TxoBGFiR0q3DFEvS0Tvbj60H/uOEWKAW9sXHSaxGUku2gG426gXaj3 ttOMMFUkrlDle9f+xwaAqEi9p6pGIwfKvqiiU57L9D6zcTEsp1AucByifMt6r09C p83SZj4RW5czzDlz3abBe9HqzBT5OxttfoPu4B0pD/RonE4y1IDUN/s8xuop1wKq 3p34vhOITt0Vb0T7E/SjFdkXhskhScB9sUbR/C+VkXpBl7R3z26gsVFg4E9repIF EPjlX9N+2auUIQgTuF1ZDgIhQCvb28RV3OsZpbjOVrcdGeBq8YEQ4ng6GwhK8ew= =ACi+ -----END PGP SIGNATURE----- --CNckeVhSCGHEbeH8KgNsS1oXPKNknSTJv--