From patchwork Mon Aug 13 19:48:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 177126 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 C51702C0089 for ; Tue, 14 Aug 2012 07:14:35 +1000 (EST) Received: from localhost ([::1]:60566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10dl-0001Wb-9V for incoming@patchwork.ozlabs.org; Mon, 13 Aug 2012 15:49:29 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10d5-0000BM-KN for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T10d3-0003l2-Ba for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19580) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T10d2-0003kk-MV for qemu-devel@nongnu.org; Mon, 13 Aug 2012 15:48:45 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7DJmhv2024371 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 Aug 2012 15:48:43 -0400 Received: from localhost (ovpn-113-98.phx2.redhat.com [10.3.113.98]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q7DJmgsI024851; Mon, 13 Aug 2012 15:48:43 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 13 Aug 2012 16:48:30 -0300 Message-Id: <1344887349-13041-10-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.24 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 09/48] 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 Reviewed-by: Markus Armbruster --- 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);