From patchwork Mon Aug 13 19:48:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 177124 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 12F922C0089 for ; Tue, 14 Aug 2012 07:11:22 +1000 (EST) Received: from localhost ([::1]:60142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10dZ-0001Ic-Rs for incoming@patchwork.ozlabs.org; Mon, 13 Aug 2012 15:49:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10d5-0000AF-9Z for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T10d4-0003lJ-9Z for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47568) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10d4-0003lB-12 for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:46 -0400 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 q7DJmjiZ023190 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 Aug 2012 15:48:45 -0400 Received: from localhost (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7DJmi0O004968; Mon, 13 Aug 2012 15:48:44 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 13 Aug 2012 16:48:31 -0300 Message-Id: <1344887349-13041-11-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1344887349-13041-1-git-send-email-lcapitulino@redhat.com> References: <1344887349-13041-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 10/48] error: don't delay error message construction 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 Today, the error message is only constructed when it's used. This commit changes that to construct the error message when the error object is built (ie. when the error is reported). This simplifies the Error object. Signed-off-by: Luiz Capitulino Reviewed-by: Markus Armbruster --- error.c | 8 +------- qerror.c | 4 +--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/error.c b/error.c index 3a62592..2ade99b 100644 --- a/error.c +++ b/error.c @@ -20,7 +20,6 @@ struct Error { QDict *obj; - const char *fmt; char *msg; }; @@ -39,7 +38,7 @@ void error_set(Error **errp, const char *fmt, ...) va_start(ap, fmt); err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap)); va_end(ap); - err->fmt = fmt; + err->msg = qerror_format(fmt, err->obj); *errp = err; } @@ -50,7 +49,6 @@ Error *error_copy(const Error *err) err_new = g_malloc0(sizeof(*err)); err_new->msg = g_strdup(err->msg); - err_new->fmt = err->fmt; err_new->obj = err->obj; QINCREF(err_new->obj); @@ -64,10 +62,6 @@ bool error_is_set(Error **errp) const char *error_get_pretty(Error *err) { - if (err->msg == NULL) { - err->msg = qerror_format(err->fmt, err->obj); - } - return err->msg; } diff --git a/qerror.c b/qerror.c index a254f88..5d38428 100644 --- a/qerror.c +++ b/qerror.c @@ -543,7 +543,6 @@ void qerror_report(const char *fmt, ...) struct Error { QDict *obj; - const char *fmt; char *msg; }; @@ -555,8 +554,7 @@ void qerror_report_err(Error *err) loc_save(&qerr->loc); QINCREF(err->obj); qerr->error = err->obj; - - qerr->err_msg = qerror_format(err->fmt, qerr->error); + qerr->err_msg = g_strdup(err->msg); if (monitor_cur_is_qmp()) { monitor_set_error(cur_mon, qerr);