[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 17/28] qapi: Factor out JSON number formattin

From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v4 17/28] qapi: Factor out JSON number formatting
Date: Thu, 2 Jun 2016 09:06:30 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 06/02/2016 09:02 AM, Markus Armbruster wrote:
> Eric Blake <address@hidden> writes:
>> Pull out a new qstring_append_json_number() helper, so that all
>> JSON output producers can use a consistent style for printing
>> floating point without duplicating code (since we are doing more
>> data massaging than a simple printf format can handle).  (For
>> now, there is only one client, but later patches will use it.)
>> Adding a return value will let callers that care diagnose the
>> situation where an attempt was made to output invalid JSON (which
>> does not specify Infinity or NaN). None of the current callers
>> care, but a future patch wants to make it possible to turn this
>> situation into an error.

> Suggest:
>  * Return 0 if the number is finite, as required by RFC 7159, else -1.
> The return value makes some sense only for symmetry with
> qstring_append_json_string().  Without that, I'd ask you to keep this
> function simple.  Callers could just as easily test isfinite()
> themselves.

I'm actually thinking of modifying this, given the recent thread
pointing out that libvirt chokes hard on JSON extensions:


That is, for symmetry with qstring_append_json_string(), I'm thinking of
changing NaN to 0 and Inf to DBL_MAX, and always outputting a finite
value, in addition to returning -1 to inform the caller that a
substitution was made, so that the output is always strict JSON.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]