Received: from eggs.gnu.org ([2001:4830:134:3::10]:50674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4qNJ-0001kk-KA for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:53:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4qNI-000802-Ai for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:53:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4qNI-0007zv-6Z for qemu-devel@nongnu.org; Tue, 16 Jun 2015 08:53:56 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id C5FF63672B7 for ; Tue, 16 Jun 2015 12:53:55 +0000 (UTC) Date: Tue, 16 Jun 2015 14:53:52 +0200 From: "Michael S. Tsirkin" Message-ID: <1434458200-23440-3-git-send-email-mst@redhat.com> References: <1434458200-23440-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1434458200-23440-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PATCH RFC 2/3] error: allow local errors to trigger abort List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com It's a common idiom: Error *local_err = NULL; .... foo(&local_err); ... if (local_err) { error_propagate(errp, local_err); return; } Unfortunately it means that call to foo(&local_err) will not abort even if errp is set to error_abort. Instead, we get an abort at error_propagate which is too late. To fix, add an API to check errp and set local_err to error_abort if errp is error_abort. Signed-off-by: Michael S. Tsirkin --- include/qapi/error.h | 5 +++++ util/error.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index f44c451..8246a62 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -88,6 +88,11 @@ const char *error_get_pretty(Error *err); void error_report_err(Error *); /** + * Init a local error. It must be propagated to errp using error_propagate. + */ +Error *error_init_local(Error **errp); + +/** * 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 ccf29ea..7489967 100644 --- a/util/error.c +++ b/util/error.c @@ -28,6 +28,11 @@ static bool error_is_abort(Error **errp) return errp && *errp && (*errp)->err_class == ERROR_CLASS_MAX; } +Error *error_init_local(Error **errp) +{ + return error_is_abort(errp) ? *errp : NULL; +} + void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) { Error *err; -- MST