From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vdge1-0003i7-Hf for qemu-devel@nongnu.org; Tue, 05 Nov 2013 08:26:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vdgdu-0006Ur-Jh for qemu-devel@nongnu.org; Tue, 05 Nov 2013 08:26:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vdgdu-0006UR-Ay for qemu-devel@nongnu.org; Tue, 05 Nov 2013 08:26:02 -0500 Message-ID: <5278F1E5.1070402@redhat.com> Date: Tue, 05 Nov 2013 06:25:57 -0700 From: Eric Blake MIME-Version: 1.0 References: <1383611860-9053-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1383611860-9053-4-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1383611860-9053-4-git-send-email-xiawenc@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="dKwQvNu1xEHMOEHcA7nAsc6PbiQ6LTbi5" Subject: Re: [Qemu-devel] [PATCH RFC 03/10] qapi script: check correctness of discriminator values in union List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia , qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, armbru@redhat.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --dKwQvNu1xEHMOEHcA7nAsc6PbiQ6LTbi5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 11/04/2013 05:37 PM, Wenchao Xia wrote: > It will check whether the values specfied are wrotten correctly when s/specfied/specified/ s/wrotten/written/ > discriminator is a pre-defined enum type, which help check whether the > schema is in good form. >=20 > It is allowed that, not every value in enum is used, so do not check s/that,/that/ > that case. Why do you allow partial coverage? That feels like an accident waiting to happen. Does the user get a sane error message if they request an enum value that wasn't mapped to a union branch? I think it would be wiser to mandate that if the discriminator is an enum, then the union must cover all values of the enum. > + > +# Return the descriminator enum define, if discriminator is specified = in s/descriminator/discriminator/ > +# @expr and it is a pre-defined enum type > +def descriminator_find_enum_define(expr): s/descriminator/discriminator/ - and fix all callers > + discriminator =3D expr.get('discriminator') > + base =3D expr.get('base') > + > + # Only support discriminator when base present > + if not (discriminator and base): > + return None > + > + base_fields =3D find_base_fields(base) > + > + if not base_fields: > + sys.stderr.write("Base '%s' is not a valid type\n" > + % base) > + sys.exit(1) > + > + descriminator_type =3D base_fields.get(discriminator) s/descriminator/discriminator/ --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --dKwQvNu1xEHMOEHcA7nAsc6PbiQ6LTbi5 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.15 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSePHlAAoJEKeha0olJ0NqGrcH/Rx7g35/u8HvBBL20EgMjLSN Sa0LpnAcv/w9bmb1nlzHDLzd9apSWzsnBwv2TPPA6b4EOMcYJ1cfzMnU51Y80FDp Va1RLHGHL8iHHC8p6bQyQDvT/QLxgbYjGsas3Ex1kxf6x1N5hI4I8OTq1DN1vucG PdF/QlAnOk0XhOmaFXAOzbNrduXdClaqXJZ/FRiEDT57kzJav10odWYM6hbbeZJu 9Ta5kQQ/ycmTZUOpJ3dhyKNObXN1cCZGipvQk0cbEPRlUpX/BTNHfd3DsqMM3qlD Ix+g/R8u+PKAhy4w38yVKSnI3wUZONnxLyinIIsT+TC2+kMJsOm8PtCzqg9yn4I= =1HyJ -----END PGP SIGNATURE----- --dKwQvNu1xEHMOEHcA7nAsc6PbiQ6LTbi5--