From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zfwf3-0001Hf-Fz for qemu-devel@nongnu.org; Sat, 26 Sep 2015 17:05:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zfwf0-00056L-Ah for qemu-devel@nongnu.org; Sat, 26 Sep 2015 17:05:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zfwf0-00055g-1d for qemu-devel@nongnu.org; Sat, 26 Sep 2015 17:05:34 -0400 References: <1442872682-6523-1-git-send-email-eblake@redhat.com> <1442872682-6523-8-git-send-email-eblake@redhat.com> <87r3lneuet.fsf@blackfin.pond.sub.org> <5604216D.2010509@redhat.com> From: Eric Blake Message-ID: <56070895.1@redhat.com> Date: Sat, 26 Sep 2015 15:05:25 -0600 MIME-Version: 1.0 In-Reply-To: <5604216D.2010509@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0l4OJW4jMaCDD0DHfBAO1kV6cepFlaBhB" Subject: Re: [Qemu-devel] [PATCH v5 07/46] qapi: Don't pass pre-existing error to later call List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Michael Roth , marcandre.lureau@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com, DirtY.iCE.hu@gmail.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --0l4OJW4jMaCDD0DHfBAO1kV6cepFlaBhB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/24/2015 10:14 AM, Eric Blake wrote: >>> >>> visit_start_implicit_struct(m, (void **)obj, sizeof(FOO), &err); >>> if (!err) { >>> visit_type_FOO_fields(m, obj, &err); >>> visit_end_implicit_struct(m, err ? NULL : &err); >>> } >>> error_propagate(errp, err); >> >> Hmmmmm... not sure we do this anywhere else, yet. The ternary isn't >> exactly pretty, but the intent to ignore additional error is clear >> enough, I think. >> >> If we elect to adopt this new error handling pattern, we should perhap= s >> document it in error.h. >> >> Third option: drop visit_end_implicit_struct()'s errp parameter. If w= e >> find a compelling use for it, we'll put it back and solve the problem.= >> >=20 > Ooh, interesting idea. It changes the contract - but since the contrac= t > isn't (yet) documented, and happens to work with existing uses without = a > contract, it could indeed be nicer. It would have knock-on effects to > 24/46 where I first try documenting the contract. Oh well. We do have a compelling use: qmp-input-visitor.c can set errp during visit_end_struct() when in strict mode (basically, the mode which warns if the input QDict has leftover key:value pairs that were not consumed by visit_type_FOO() between the start/end call). I don't know if visit_end_list() or visit_end_implicit_struct() care; but then we have the argument that it is worth keeping them consistent with visit_end_struct() which can indeed raise an error. One other potential alternative: What if we split visit_end_struct() into two visitor functions, one that checks for success, and the other that is called unconditionally to clean up resources. That is, go from: visit_start_struct(m, (void **)obj, "foo", name, sizeof(FOO), &err); if (!err) { if (*obj) { visit_type_FOO_fields(m, obj, errp); } visit_end_struct(m, &err); } error_propagate(errp, err); to a form where the check for leftover key/value pairs is only done on success with a new visit_check_struct(): visit_start_struct(m, (void **)obj, "foo", name, sizeof(FOO), &err); if (!err) { if (*obj) { visit_type_FOO_fields(m, obj, &err); } if (!err) { visit_check_struct(m, &err); } visit_end_struct(m); } error_propagate(errp, err); --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --0l4OJW4jMaCDD0DHfBAO1kV6cepFlaBhB 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/ iQEcBAEBCAAGBQJWBwiWAAoJEKeha0olJ0NqNwQH/1D0Yw/bYN78uzHWkD2qJaeg SKNdCOSnlLltxpPbi2Uy6o8N6xHScYKMQ1GIkT2RAoBkUZAe2LnK3jdv18YSNFQz oyf6QWg+DQwPYRt1Sq7wEJeZV65I18SGyhptVeV2na3ljlBif3iifLlxhlBDa8wh CUh5jIRF6DGMsWgD9MoVTufjs0qKjQVjTAwfDrJlm2JiUYe4rs/KrxExewOJGHAG 3H6zf15oGzaELMM6RcAwJ9leadVBGybBizmk9zChQyS3+ubNo208RtuXV+iS6/s+ 5fNZ+Znv+OjmXm6w0htDQmeBykaokfsESFXdzwTf7maW4L/yAc4rYgoYgt0z8eQ= =xhSo -----END PGP SIGNATURE----- --0l4OJW4jMaCDD0DHfBAO1kV6cepFlaBhB--