[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/14] qerror: don't delay error message constructio
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction |
Date: |
Wed, 25 Jul 2012 17:50:23 -0300 |
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 <address@hidden>
---
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
- [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set(), Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 01/14] monitor: drop unused monitor debug code, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 02/14] qerror: reduce public exposure, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort(), Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal(), Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 05/14] qerror: qerror_format(): return an allocated string, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 06/14] qerror: don't delay error message construction,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 07/14] error: don't delay error message construction, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[], Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 09/14] qerror: qerror_report(): take an index and a human error message, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 12/14] error: turn QERR_ macros into an enumeration, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 13/14] qerror: change all qerror_report() calls to use the ErrClass enum, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 10/14] error: error_set(): take an index and a human error message, Luiz Capitulino, 2012/07/25
- [Qemu-devel] [PATCH 14/14] error: change all error_set() calls to use the ErrClass enum, Luiz Capitulino, 2012/07/25