From patchwork Fri Jul 27 21:31:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 173797 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 8927A2C008F for ; Sat, 28 Jul 2012 07:56:35 +1000 (EST) Received: from localhost ([::1]:36341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus9N-0008E2-5w for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 17:32:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8R-0006Oh-TD for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sus8Q-00088G-Dt for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8Q-000885-5G for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:46 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6RLVjXl031451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jul 2012 17:31:45 -0400 Received: from localhost (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6RLViUt014273; Fri, 27 Jul 2012 17:31:44 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 18:31:49 -0300 Message-Id: <1343424728-22461-9-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.68 on 10.5.11.23 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 08/27] 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 that 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 5b4266c..5b7d67d 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);