From patchwork Tue Aug 7 15:53:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 175743 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 7E7402C0090 for ; Wed, 8 Aug 2012 02:39:44 +1000 (EST) Received: from localhost ([::1]:41475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sym6t-0006zB-1i for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 11:54:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sym6f-0006Tl-7V for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:54:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sym6U-0005dP-UO for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:54:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sym6U-0005dD-Ks for qemu-devel@nongnu.org; Tue, 07 Aug 2012 11:53:54 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q77FrY9Q024877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 Aug 2012 11:53:34 -0400 Received: from localhost (ovpn-113-157.phx2.redhat.com [10.3.113.157]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q77FrWst015823; Tue, 7 Aug 2012 11:53:32 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 7 Aug 2012 12:53:20 -0300 Message-Id: <1344354826-10375-10-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.11 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 09/35] qerror: 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 qerror to construct the error message when the error object is built (ie. when the error is reported). This eliminates the need of storing a pointer to qerror_table[], which will be dropped soon, and also simplifies the code. Signed-off-by: Luiz Capitulino --- qerror.c | 29 ++++------------------------- qerror.h | 2 +- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/qerror.c b/qerror.c index d073ed7..a254f88 100644 --- a/qerror.c +++ b/qerror.c @@ -385,22 +385,6 @@ static QDict *error_obj_from_fmt_no_fail(const char *fmt, va_list *va) return ret; } -static const QErrorStringTable *get_desc_no_fail(const char *fmt) -{ - int i; - - // FIXME: inefficient loop - - for (i = 0; qerror_table[i].error_fmt; i++) { - if (strcmp(qerror_table[i].error_fmt, fmt) == 0) { - return &qerror_table[i]; - } - } - - fprintf(stderr, "error format '%s' not found\n", fmt); - abort(); -} - /** * qerror_from_info(): Create a new QError from error information * @@ -414,7 +398,7 @@ static QError *qerror_from_info(const char *fmt, va_list *va) loc_save(&qerr->loc); qerr->error = error_obj_from_fmt_no_fail(fmt, va); - qerr->entry = get_desc_no_fail(fmt); + qerr->err_msg = qerror_format(fmt, qerr->error); return qerr; } @@ -519,7 +503,7 @@ char *qerror_format(const char *fmt, QDict *error) */ QString *qerror_human(const QError *qerror) { - return qerror_format_desc(qerror->error, qerror->entry); + return qstring_from_str(qerror->err_msg); } /** @@ -566,19 +550,13 @@ struct Error void qerror_report_err(Error *err) { QError *qerr; - int i; qerr = qerror_new(); loc_save(&qerr->loc); QINCREF(err->obj); qerr->error = err->obj; - for (i = 0; qerror_table[i].error_fmt; i++) { - if (strcmp(qerror_table[i].error_fmt, err->fmt) == 0) { - qerr->entry = &qerror_table[i]; - break; - } - } + qerr->err_msg = qerror_format(err->fmt, qerr->error); if (monitor_cur_is_qmp()) { monitor_set_error(cur_mon, qerr); @@ -619,5 +597,6 @@ static void qerror_destroy_obj(QObject *obj) qerr = qobject_to_qerror(obj); QDECREF(qerr->error); + g_free(qerr->err_msg); g_free(qerr); } diff --git a/qerror.h b/qerror.h index aec76b2..de8497d 100644 --- a/qerror.h +++ b/qerror.h @@ -27,7 +27,7 @@ typedef struct QError { QObject_HEAD; QDict *error; Location loc; - const QErrorStringTable *entry; + char *err_msg; } QError; QString *qerror_human(const QError *qerror);