From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 07/11] qapi: add json output visitor
Date: Thu, 10 Dec 2015 17:24:36 -0700 [thread overview]
Message-ID: <566A17C4.5010207@redhat.com> (raw)
In-Reply-To: <1449791621-16185-8-git-send-email-eblake@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1997 bytes --]
On 12/10/2015 04:53 PM, Eric Blake wrote:
> We have several places that want to go from qapi to JSON; right now,
> they have to create an intermediate QObject to do the work. That
> also has the drawback that the JSON formatting of a QDict will
> rearrange keys (according to a deterministic, but unpredictable,
> hash), when humans have an easier time if dicts are produced in
> the same order as the qapi type.
>
> For these reasons, it is time to add a new JSON output visitor.
> This patch just adds the basic visitor and tests that it works;
> later patches will add pretty-printing, and convert clients to
> use the visitor.
>
> Design choices: Unlike the QMP output visitor, the JSON visitor
> refuses to visit a required string with a NULL value (abort), as
> well as a non-finite number (raises an error message). Reusing
> QString to grow the contents means that we easily share code with
> both qobject-json.c and qjson.c; although it might be nice to
> enhance things to take an optional output callback function so
> that the output can truly be streamed instead of collected in
> memory.
>
> +static void json_output_type_number(Visitor *v, double *obj, const char *name,
> + Error **errp)
> +{
> + JsonOutputVisitor *jov = to_jov(v);
> + json_output_name(jov, name);
> + qstring_append_json_number(jov->str, *obj, errp);
> +}
Hmm. The generated qapi callers always pass a non-NULL local errp, and
fail the overall iteration even if the upper-level caller passed NULL.
My intent here was to allow the choice between diagnosing NaN, or
ignoring the problem and producing output anyways; but for that to work,
I may need to add a configuration parameter 'bool strict' at the
creation of the visitor, that determines whether I pass errp or NULL on
to qstring_append_json_number() here.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-12-11 0:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-10 23:53 [Qemu-devel] [RFC PATCH 00/11] Add qapi-to-JSON output visitor Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 01/11] qapi: Rename qjson.h to qobject-json.h Eric Blake
2015-12-11 11:00 ` Paolo Bonzini
2015-12-10 23:53 ` [Qemu-devel] [PATCH 02/11] qapi: Improve use of qmp/types.h Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 03/11] qapi: Factor out JSON string escaping Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 04/11] qapi: Factor out JSON number formatting Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 05/11] qapi: Use qstring_append_chr() where appropriate Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 06/11] qapi: Add qstring_append_format() Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 07/11] qapi: add json output visitor Eric Blake
2015-12-11 0:24 ` Eric Blake [this message]
2015-12-10 23:53 ` [Qemu-devel] [PATCH 08/11] qjson: Simplify by using json-output-visitor Eric Blake
2015-12-11 11:10 ` Paolo Bonzini
2015-12-11 13:42 ` Eric Blake
2015-12-11 13:45 ` Paolo Bonzini
2015-12-18 23:06 ` Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 09/11] qapi: Add qobject_to_json_pretty_prefix() Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 10/11] qapi: Support pretty printing in JSON output visitor Eric Blake
2015-12-10 23:53 ` [Qemu-devel] [PATCH 11/11] RFC: qemu-img: Use new JSON output formatter Eric Blake
2015-12-11 1:36 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=566A17C4.5010207@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).