From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaQu8-00007x-6c for qemu-devel@nongnu.org; Fri, 11 Sep 2015 12:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaQu3-0005Yo-8A for qemu-devel@nongnu.org; Fri, 11 Sep 2015 12:10:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaQu3-0005YQ-1H for qemu-devel@nongnu.org; Fri, 11 Sep 2015 12:10:19 -0400 References: <1728a2f1b0ab562957512cafe3931d3073ed68e8.1441667360.git.crosthwaite.peter@gmail.com> From: Eric Blake Message-ID: <55F2FCE9.8080705@redhat.com> Date: Fri, 11 Sep 2015 10:10:17 -0600 MIME-Version: 1.0 In-Reply-To: <1728a2f1b0ab562957512cafe3931d3073ed68e8.1441667360.git.crosthwaite.peter@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="C6ipEEeoEMJRLl6PspsDgmL0aObVKu55s" Subject: Re: [Qemu-devel] [RFC PATCH v1 06/25] error: Add error_printf_fn() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --C6ipEEeoEMJRLl6PspsDgmL0aObVKu55s Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/10/2015 11:33 PM, Peter Crosthwaite wrote: > Add an API to report an error with a custom printf function. Use > this for the implementation of error_report_err(). >=20 > Signed-off-by: Peter Crosthwaite > --- >=20 > include/qapi/error.h | 7 +++++++ > util/error.c | 22 ++++++++++++++++++++-- > 2 files changed, 27 insertions(+), 2 deletions(-) Sounds independently useful. >=20 > diff --git a/include/qapi/error.h b/include/qapi/error.h > index b25c72f..0e5c311 100644 > --- a/include/qapi/error.h > +++ b/include/qapi/error.h > @@ -94,6 +94,13 @@ const char *error_get_pretty(Error *err); > void error_report_err(Error *); > =20 > /** > + * Report an and free an error object using a custom printf implementa= tion. s/an and/and/ > + */ > + > +void error_printf_fn(Error *err, void (*printf_fn)(void *, const char = *, ...), > + void *printf_opaque); > + > +/** > * Propagate an error to an indirect pointer to an error. This functi= on will > * always transfer ownership of the error reference and handles the ca= se where > * dst_err is NULL correctly. Errors after the first are discarded. > diff --git a/util/error.c b/util/error.c > index e9c23ce..c4656af 100644 > --- a/util/error.c > +void error_printf_fn(Error *err, void (*printf_fn)(void *, const char = *, ...), > + void *printf_opaque) > +{ > + if (err->next) { > + error_printf_fn(err->next, printf_fn, printf_opaque); > + } > + printf_fn(printf_opaque, "%s\n", error_get_pretty(err)); > + error_free(err); > +} Of course, if you rebase this to come independent of multi-error, it won't need the first 'if'. But it looks like a reasonable factorization. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --C6ipEEeoEMJRLl6PspsDgmL0aObVKu55s 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/ iQEcBAEBCAAGBQJV8vzpAAoJEKeha0olJ0Nqc+EH/3bi4JEDF6p6Ip2LkPRbYadc LRpDIwO9dlPQIdkx3P0aWVIMQBLqILG+5MwKzFpGoEo4XgYKaoFo2pILtI8qBI1X SevUBpzPuG2f0/J10iLE/G5BTJKYGumTJCTpt1u78nwR7gjo7/fSm0wi1bP7weYr f+6qdKw88U22KA+sJ27P2D2BkAaraBEP/VNzYwFrI92/Su+8nImujlR2f45S5uZO kmc7zLQazPWI+mXa1WuoovRLq+Jij89YqpIzAzJFyHEbyFJ8sL0s45IxNxlRnTIz 3g5LwZeoYrdDXXPHbCSGy9fVRXuF8dhdsTioRuWWhU+B4EJ5pXPV0Gut+o/PvI4= =ENMP -----END PGP SIGNATURE----- --C6ipEEeoEMJRLl6PspsDgmL0aObVKu55s--