From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmlhv-00045T-9i for qemu-devel@nongnu.org; Tue, 20 May 2014 11:12:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmlhq-0006zW-8W for qemu-devel@nongnu.org; Tue, 20 May 2014 11:11:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmlhq-0006z5-1C for qemu-devel@nongnu.org; Tue, 20 May 2014 11:11:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4KFBqHE003836 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 20 May 2014 11:11:52 -0400 Message-ID: <537B70B7.1090107@redhat.com> Date: Tue, 20 May 2014 09:11:51 -0600 From: Eric Blake MIME-Version: 1.0 References: <1400576881-6954-1-git-send-email-famz@redhat.com> <1400576881-6954-2-git-send-email-famz@redhat.com> In-Reply-To: <1400576881-6954-2-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EtveXLh8ubdLeVCBGimFcI9Kv5hoGtHiA" Subject: Re: [Qemu-devel] [RFC PATCH v2 1/7] qapi: Allow decimal values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EtveXLh8ubdLeVCBGimFcI9Kv5hoGtHiA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 05/20/2014 03:07 AM, Fam Zheng wrote: > This allows giving decimal constants in the schema as expr. >=20 > Signed-off-by: Fam Zheng > --- > scripts/qapi.py | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) >=20 > diff --git a/scripts/qapi.py b/scripts/qapi.py > index 0265b40..4c945ad 100644 > --- a/scripts/qapi.py > +++ b/scripts/qapi.py > @@ -157,6 +157,21 @@ class QAPISchema: > return > else: > string +=3D ch > + elif self.tok in "-0123456789": > + val =3D self.tok > + while self.src[self.cursor] in "0123456789": > + val +=3D self.src[self.cursor] > + self.cursor +=3D 1 > + try: > + if val.startswith("0") and len(val) > 1: This fails to diagnose '-0123' as invalid. Which means your test case in 3/7 is incomplete. > + raise Exception("Leading zero for non-zero int= eger") For the string "00", this message makes no sense. You are properly diagnosing that double 0 is not a valid JSON int, but it is also not a "non-zero integer". Maybe just "Leading zero not permitted for integer".= > + self.val =3D int(val) > + if self.val > 0x7fffffffffffffffL or self.val < -0= x7fffffffffffffffL - 1: > + raise Exception("Value too big") Forces the user to use int64_t rather than allowing for uint64_t defaults (if we have an unsigned value that defaults to anything larger than INT64_MAX, it would have to be written in 2s-complement negative form) - but that's okay with me (I really doubt we'd have any default in that situation except possibly UINT64_MAX, but writing -1 for UINT64_MAX doesn't feel too bad). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --EtveXLh8ubdLeVCBGimFcI9Kv5hoGtHiA 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/ iQEcBAEBCAAGBQJTe3C3AAoJEKeha0olJ0NqPQIH/ihgtdBVsZHSc3UmaM2AWbxj Jm9i5qywD+mAz5Idpz7JlXWIRbIBVh6aeOWGfPnT1/X/+nVndiO1RcQqA1ompYHV myY5H8kedFBbGVcVr3KOZ8p+7TgNZ8iN8mbC2DjDnH/qyKEDdpKi+iWnk1R4usLF S62MJgq12dYrZ6S7NMNkNJ5nSaBpVeM5maEFYXFAy+bWBNQvHBcXvvSihGW1uIH8 WmB9S7wGn0IlB0KKKfKIeVIlio6oSi0bedNX+n5r1TyytJSC5wc8GMMzGA93sepc IosMVCc+bhyu/k/+cK6ozQmsVUd1TmRT3tnIXljrhjtKgDiJZb92vn86zn4xEZI= =rO0b -----END PGP SIGNATURE----- --EtveXLh8ubdLeVCBGimFcI9Kv5hoGtHiA--