From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b33D5-0005JI-2I for qemu-devel@nongnu.org; Wed, 18 May 2016 11:16:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b33D1-0006hA-O4 for qemu-devel@nongnu.org; Wed, 18 May 2016 11:16:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b33D1-0006h6-EN for qemu-devel@nongnu.org; Wed, 18 May 2016 11:16:27 -0400 References: <1461903820-3092-1-git-send-email-eblake@redhat.com> <1461903820-3092-8-git-send-email-eblake@redhat.com> <87lh3som6o.fsf@dusky.pond.sub.org> From: Eric Blake Message-ID: <573C8748.5040509@redhat.com> Date: Wed, 18 May 2016 09:16:24 -0600 MIME-Version: 1.0 In-Reply-To: <87lh3som6o.fsf@dusky.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PaOBFq2ub0J9N1LWMfrmNN8XS22uGGgNh" Subject: Re: [Qemu-devel] [PATCH v3 07/18] qapi: Add json output visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, famz@redhat.com, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --PaOBFq2ub0J9N1LWMfrmNN8XS22uGGgNh Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/02/2016 03:15 AM, Markus Armbruster wrote: > Title: s/json/JSON/ >=20 > Eric Blake writes: >=20 >> 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 > There's a drawback, though: more code. >=20 > Could the JSON output visitor replace the QMP output visitor? Yes, it turned out quite nicely to write qobject_to_json() on top of a JSON output visitor. And in fact, doing so makes it trivial to write a QObject deep-cloner - pass the QObject to the qmp-output-visitor instead of the json-output-visitor! >> +static void json_output_type_any(Visitor *v, const char *name, QObjec= t **obj, >> + Error **errp) >> +{ >> + JsonOutputVisitor *jov =3D to_jov(v); >> + QString *str =3D qobject_to_json(*obj); >> + assert(str); >=20 > Can't happen. Can too. From tests/check-qobject-json.c: obj =3D QOBJECT(qstring_from_str(utf8_in)); str =3D qobject_to_json(obj); if (json_out) { g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, json_out); } else { g_assert(!str); } where the failures occur when it is impossible to output proper UTF-8 due to invalid encoding in a string. Arguably, that case would be nicer if it could set an Error* (and would make my argument for setting an error on Inf/NaN for numbers also a bit more tenable), but that is additional work that I haven't tackled yet. I'm trying to get the series posted for another round of review, where I've done some major reshuffling (such as doing the clone visitor first, not second, in the series), so hopefully later today. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --PaOBFq2ub0J9N1LWMfrmNN8XS22uGGgNh 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/ iQEcBAEBCAAGBQJXPIdJAAoJEKeha0olJ0NqqKAH/2vQBl0lAldL9z0a8fIac2Gv 61ZEf0+bebyGv1an+exQ5m/SmpY8s0szSkv/9uNbpqdF4LoQkR7XkivXYJypQLq1 34luOXcozlHaijEiQokU+BQ7kOJ0KvU5ZyqyDyJHLl1RQnYdM191N5diiOnHTyez W+UJ0PqLtJsBYkq5FGflrBIQSL6SqEYjjOYl6Y87vNA+QI0FGaVfI7PaU1AJTra2 AI7Dqz9gP5FUXb5wiA2XiXldkYrPBwuvf7xujzvgW+9h1CZCUOSEkm5l+TZIgyss xIfdNxzHkVx8a83/cgkBurVKEAO2gi5UkDkBx8HeNLjmqWUQ4mRKYkHWIqfbp4g= =lPOb -----END PGP SIGNATURE----- --PaOBFq2ub0J9N1LWMfrmNN8XS22uGGgNh--