From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, armbru@redhat.com,
afaerber@suse.de, peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction
Date: Wed, 25 Jul 2012 17:50:23 -0300 [thread overview]
Message-ID: <1343249431-9245-7-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1343249431-9245-1-git-send-email-lcapitulino@redhat.com>
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 <lcapitulino@redhat.com>
---
qerror.c | 34 +++++++---------------------------
qerror.h | 2 +-
2 files changed, 8 insertions(+), 28 deletions(-)
diff --git a/qerror.c b/qerror.c
index 7db28fc..89def8d 100644
--- a/qerror.c
+++ b/qerror.c
@@ -81,22 +81,6 @@ out_free:
return NULL;
}
-static const QErrorStringTable *error_get_desc(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);
- return NULL;
-}
-
static QDict *build_error_no_arg(const char *fmt)
{
return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
@@ -119,8 +103,8 @@ static QError *qerror_from_info(const char *fmt, va_list *va)
goto bad_err;
}
- qerr->entry = error_get_desc(fmt);
- if (!qerr->entry) {
+ qerr->err_msg = qerror_format(fmt, qerr->error);
+ if (!qerr->err_msg) {
QDECREF(qerr->error);
goto bad_err;
}
@@ -129,7 +113,7 @@ static QError *qerror_from_info(const char *fmt, va_list *va)
bad_err:
qerr->error = build_error_no_arg(QERR_UNDEFINED_ERROR);
- qerr->entry = error_get_desc(QERR_UNDEFINED_ERROR);
+ qerr->err_msg = qerror_format(QERR_UNDEFINED_ERROR, qerr->error);
return qerr;
}
@@ -233,7 +217,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);
}
/**
@@ -280,19 +264,14 @@ 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);
+ /* FIXME: should report UndefinedError on error */
if (monitor_cur_is_qmp()) {
monitor_set_error(cur_mon, qerr);
@@ -333,5 +312,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 6bf941b..16401ff 100644
--- a/qerror.h
+++ b/qerror.h
@@ -28,7 +28,7 @@ typedef struct QError {
QObject_HEAD;
QDict *error;
Location loc;
- const QErrorStringTable *entry;
+ char *err_msg;
} QError;
QString *qerror_human(const QError *qerror);
--
1.7.11.2.249.g31c7954.dirty
next prev parent reply other threads:[~2012-07-25 20:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 20:50 [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort() Luiz Capitulino
2012-07-26 12:33 ` Markus Armbruster
2012-07-26 15:02 ` Luiz Capitulino
2012-07-26 12:59 ` Eric Blake
2012-07-25 20:50 ` [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal() Luiz Capitulino
2012-07-26 12:35 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string Luiz Capitulino
2012-07-25 20:50 ` Luiz Capitulino [this message]
2012-07-25 20:50 ` [Qemu-devel] [PATCH 07/14] error: don't delay error message construction Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[] Luiz Capitulino
2012-07-26 12:52 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 10/14] error: error_set(): " Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good Luiz Capitulino
2012-07-26 12:54 ` Markus Armbruster
2012-07-25 20:50 ` [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum Luiz Capitulino
2012-07-25 20:50 ` [Qemu-devel] [PATCH 14/14] error: change all error_set() " Luiz Capitulino
2012-07-26 2:43 ` [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set() Anthony Liguori
2012-07-26 9:45 ` Kevin Wolf
2012-07-26 12:41 ` Anthony Liguori
2012-07-26 14:12 ` Luiz Capitulino
2012-07-26 15:05 ` Anthony Liguori
2012-07-26 15:52 ` Markus Armbruster
2012-07-26 14:40 ` Kevin Wolf
2012-07-26 15:20 ` Anthony Liguori
2012-07-26 16:12 ` Daniel P. Berrange
2012-07-26 16:38 ` Markus Armbruster
2012-07-26 15:54 ` Markus Armbruster
2012-07-26 16:03 ` Paolo Bonzini
2012-07-26 16:37 ` Luiz Capitulino
2012-07-27 13:17 ` Andreas Färber
2012-07-27 13:45 ` Anthony Liguori
2012-07-27 14:27 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343249431-9245-7-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).