From patchwork Fri Jul 27 21:31:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 173810 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 D662D2C0099 for ; Sat, 28 Jul 2012 08:36:47 +1000 (EST) Received: from localhost ([::1]:37240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus9d-0000Fm-In for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 17:33:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8T-0006TF-7Y for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sus8S-00088y-1S for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8R-00088W-Pd for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:47 -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 q6RLVlqW001824 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jul 2012 17:31:47 -0400 Received: from localhost (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6RLVkOi030023; Fri, 27 Jul 2012 17:31:46 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 18:31:50 -0300 Message-Id: <1343424728-22461-10-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1343424728-22461-1-git-send-email-lcapitulino@redhat.com> References: <1343424728-22461-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, pbonzini@redhat.com, aliguori@us.ibm.com, eblake@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 09/27] 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 b630b05..acb10a2 100644 --- a/error.c +++ b/error.c @@ -20,7 +20,6 @@ struct Error { QDict *obj; - const char *fmt; char *msg; }; @@ -38,7 +37,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; } @@ -49,7 +48,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); @@ -63,10 +61,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 5b7d67d..691d8a8 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);