From patchwork Wed Feb 18 11:10:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 440908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 64D7E14014D for ; Wed, 18 Feb 2015 22:11:33 +1100 (AEDT) Received: from localhost ([::1]:49890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO2XT-0007Mh-9Z for incoming@patchwork.ozlabs.org; Wed, 18 Feb 2015 06:11:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO2Wo-0006KK-3T for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:10:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YO2Wj-0006im-Hi for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:10:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YO2Wj-0006iK-57 for qemu-devel@nongnu.org; Wed, 18 Feb 2015 06:10:45 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1IBAhRg029857 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 18 Feb 2015 06:10:44 -0500 Received: from blackfin.pond.sub.org (ovpn-116-39.ams2.redhat.com [10.36.116.39]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1IBAg4R002062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 18 Feb 2015 06:10:43 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D2C56303FB71; Wed, 18 Feb 2015 12:10:41 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 18 Feb 2015 12:10:32 +0100 Message-Id: <1424257841-18634-3-git-send-email-armbru@redhat.com> In-Reply-To: <1424257841-18634-1-git-send-email-armbru@redhat.com> References: <1424257841-18634-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 02/11] error: New convenience function error_report_err() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org I've typed error_report("%s", error_get_pretty(ERR)) too many times already, and I've fixed too many instances of qerror_report_err(ERR) to error_report("%s", error_get_pretty(ERR)) as well. Capture the pattern in a convenience function. Since it's almost invariably followed by error_free(), stuff that into the convenience function as well. The next patch will put it to use. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/error.h | 5 +++++ util/error.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index d712089..f44c451 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -83,6 +83,11 @@ Error *error_copy(const Error *err); const char *error_get_pretty(Error *err); /** + * Convenience function to error_report() and free an error object. + */ +void error_report_err(Error *); + +/** * Propagate an error to an indirect pointer to an error. This function will * always transfer ownership of the error reference and handles the case where * dst_err is NULL correctly. Errors after the first are discarded. diff --git a/util/error.c b/util/error.c index 2ace0d8..1ff6ae5 100644 --- a/util/error.c +++ b/util/error.c @@ -152,6 +152,12 @@ const char *error_get_pretty(Error *err) return err->msg; } +void error_report_err(Error *err) +{ + error_report("%s", error_get_pretty(err)); + error_free(err); +} + void error_free(Error *err) { if (err) {