From patchwork Tue Aug 7 15:53:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 175731 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 E10282C007F for ; Wed, 8 Aug 2012 02:31:37 +1000 (EST) Received: from localhost ([::1]:44970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Symgy-0007KO-09 for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 12:31:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sym6X-0006H0-9T for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:53:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sym6W-0005dq-25 for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:53:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sym6V-0005de-Py for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:53:55 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q77Fra4f014114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 Aug 2012 11:53:36 -0400 Received: from localhost (ovpn-113-157.phx2.redhat.com [10.3.113.157]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q77FrYXX009481; Tue, 7 Aug 2012 11:53:35 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 7 Aug 2012 12:53:21 -0300 Message-Id: <1344354826-10375-11-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1344354826-10375-1-git-send-email-lcapitulino@redhat.com> References: <1344354826-10375-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com, pbonzini@redhat.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH 10/35] 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 --- 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);