[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 1/2] qapi: Allow decimal values
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v2 1/2] qapi: Allow decimal values |
Date: |
Tue, 29 Apr 2014 06:42:40 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 04/29/2014 03:44 AM, Fam Zheng wrote:
> This allows giving decimal constants in the schema as expr.
>
> Signed-off-by: Fam Zheng <address@hidden>
> ---
> scripts/qapi.py | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index b474c39..6022de5 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -108,6 +108,14 @@ class QAPISchema:
> return
> else:
> string += ch
> + elif self.tok in "123456789":
> + self.val = int(self.tok)
> + while True:
> + ch = self.src[self.cursor]
> + if ch not in "1234567890":
> + return
> + self.val = self.val * 10 + int(ch)
> + self.cursor += 1
What does this do on integer overflow? Should you validate that the
result fits in [u]int64_t? Should you allow for a leading '-' sign for
a default of a negative number? You have forbidden '0' as a valid
number (although you correctly forbid '00' and any non-zero number with
a leading 0, which matches JSON restrictions).
> - if not self.tok in [ '{', '[', "'" ]:
> - raise QAPISchemaError(self, 'Expected "{", "[", "]" or string')
> + if not self.tok in "{['123456789":
> + raise QAPISchemaError(self, 'Expected "{", "[", "]", string or
> number')
Again, this forbids the use of '0' as a default.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature