From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axElH-0000AZ-91 for qemu-devel@nongnu.org; Mon, 02 May 2016 10:23:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axEl5-0000QS-DI for qemu-devel@nongnu.org; Mon, 02 May 2016 10:23:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axEl5-0000Nt-5O for qemu-devel@nongnu.org; Mon, 02 May 2016 10:23:35 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEE7685542 for ; Mon, 2 May 2016 14:23:23 +0000 (UTC) References: <1461903820-3092-1-git-send-email-eblake@redhat.com> <1461903820-3092-11-git-send-email-eblake@redhat.com> <87r3dkk2v9.fsf@dusky.pond.sub.org> From: Eric Blake Message-ID: <572762DA.4050107@redhat.com> Date: Mon, 2 May 2016 08:23:22 -0600 MIME-Version: 1.0 In-Reply-To: <87r3dkk2v9.fsf@dusky.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="sQGVwgkrK4A0tndvKi00VljwPnnPsNxlc" Subject: Re: [Qemu-devel] [PATCH v3 10/18] vmstate: Use new JSON output visitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Amit Shah , famz@redhat.com, Juan Quintela This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --sQGVwgkrK4A0tndvKi00VljwPnnPsNxlc Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/02/2016 07:26 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> Rather than using a QJSON object and converting the QString result >> to a char *, we can use the new JSON output visitor and get directly >> to a char *. >> >> The conversions are a bit tricky in place (in places, we have to >> copy an integer to an int64_t temporary to get the right pointer for >> visit_type_int(); and for several strings, we have to copy to a >> temporary variable so we can take an address (&char[] is not the >> same as &char*) and cast away const), but overall still fairly >> mechanical. >> >> Suggested-by: Paolo Bonzini >> Signed-off-by: Eric Blake >> >> -static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, Q= JSON *vmdesc) >> +static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, >> + Visitor *vmdesc) >> { >> int64_t old_offset, size; >> + const char *tmp; >> >> old_offset =3D qemu_ftell_fast(f); >> se->ops->save_state(f, se->opaque); >> size =3D qemu_ftell_fast(f) - old_offset; >> >> if (vmdesc) { >=20 > Conditionals could be avoided: use a null visitor. Not sure it's worth= > it, though. We could just teach qapi-visit-core.c to be a no-op for v=3D=3DNULL (thus= hiding the conditionals in the core code, but that then slows down the common case for more conditionals on every caller. Maybe a null visitor is reasonable, after all? >> + tmp =3D "data"; >> + visit_type_str(vmdesc, "name", (char **)&tmp, &error_abort); >=20 > The Visitor interface is the same for input and for output. Convenient= > when the code is direction-agnostic. Inconvenient when it's output: yo= u > have to pass the value by reference even though it's only read. In > particular, literals need a temporary, and types have to be adjusted vi= a > cast or temporary more frequently than for by-value. >=20 > If that bothers us, we can add by-value wrappers to the interface. >=20 > Are there other output-only visitor uses? qom-get is output-only, just as qom-set is input-only. Maybe it's worth an experiment to see how difficult it would be. > Well, it doesn't exactly make this code prettier, but having a stupid > wrapper just to hide the ugliness isn't so hot, either. And now you see why I posted two alternatives, to see which way we want to go. Having convenient wrappers for output-only visits may swing the vote. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --sQGVwgkrK4A0tndvKi00VljwPnnPsNxlc 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/ iQEcBAEBCAAGBQJXJ2LbAAoJEKeha0olJ0NqNakH/1KQgtie9gepsrkIjbdy4XBo dELALMcWNJC9EsPCghY2dUBqtwP5zAmAdxEwbx70sme2YoWxX+9Tum+WcLP1IK74 y2rmiSIwE7RVZ+gMKEG/HVl05NP2In5xwViFnHsnwx55VRGDV1g5aHpq+UBhAz2I KCYkkJy9J65BaHekRVqvTT/qoT+cXliB0IXqvYHNcofV7dF/UQ5+DHsSvJI2kLCS HQwYZxH6s0rj+R7r2adD5b69giaCDAW6PwpfEbbFlUrWPz5WJ13OpH7Pe3IzfSr5 4L7Oqa3wKaohZJyWn5Dq6Z5aaytO8oQDxvjrEFqHaCnV2AVcvXqjPmanJGv7I3k= =x3dP -----END PGP SIGNATURE----- --sQGVwgkrK4A0tndvKi00VljwPnnPsNxlc--