From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7BVq-0008B8-Od for qemu-devel@nongnu.org; Thu, 10 Dec 2015 19:24:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7BVp-0001wr-P7 for qemu-devel@nongnu.org; Thu, 10 Dec 2015 19:24:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57668) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7BVp-0001wh-Ib for qemu-devel@nongnu.org; Thu, 10 Dec 2015 19:24:41 -0500 References: <1449791621-16185-1-git-send-email-eblake@redhat.com> <1449791621-16185-8-git-send-email-eblake@redhat.com> From: Eric Blake Message-ID: <566A17C4.5010207@redhat.com> Date: Thu, 10 Dec 2015 17:24:36 -0700 MIME-Version: 1.0 In-Reply-To: <1449791621-16185-8-git-send-email-eblake@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6DMdccapBMTsJDmdnlRTlpBvr01HstGNB" Subject: Re: [Qemu-devel] [PATCH 07/11] qapi: add json output visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --6DMdccapBMTsJDmdnlRTlpBvr01HstGNB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > 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. >=20 > 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. >=20 > +static void json_output_type_number(Visitor *v, double *obj, const cha= r *name, > + Error **errp) > +{ > + JsonOutputVisitor *jov =3D 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --6DMdccapBMTsJDmdnlRTlpBvr01HstGNB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWahfEAAoJEKeha0olJ0NqKrMH/0R6AD+DxA/C9ynF1erpEXqJ YhfZL1Csa9lTEjc52Ozr4cE8CE6CSMlI9z4B0sYWMcShvLmZeNlSp6Qoi6ITrDle iRYs5tTgQpSgWfo/7T0T+jrxnjwRJHgc61t/DBLElxlS7JzArQwCg3NGOLRDlPaq /vd1ImUfdfywWp7EiAATpIHrNeNvDOAbru2wB+EItYKPEuafwLkwBB8rtluQ5G7M P3yKkbQhBZ8LoLjomYhOIST5+PK4cT+l1Jm5OhXeLpxWNQ2FU8UAgh9AmKLWR2i/ CKpm/hpM9vbAtEJTFNz31nfMUCikbKlG6cBB8BWMsse6ICDO+WIg23x8slCna4A= =iPX3 -----END PGP SIGNATURE----- --6DMdccapBMTsJDmdnlRTlpBvr01HstGNB--