[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/35] qerror: don't delay error message constructio
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 09/35] qerror: don't delay error message construction |
Date: |
Tue, 7 Aug 2012 12:53:20 -0300 |
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 <address@hidden>
---
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);
--
1.7.11.2.249.g31c7954.dirty
- [Qemu-devel] [PATCH v2 00/35]: add new error format, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 05/35] qerror: drop qerror_abort(), Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 07/35] qerror: QError: drop file, linenr, func, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 12/35] hmp: hmp_cont(): don't rely on QERR_DEVICE_ENCRYPTED, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 02/35] qerror: QERR_AMBIGUOUS_PATH: drop %(object) from human msg, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 09/35] qerror: don't delay error message construction,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 13/35] hmp_change(): don't access DeviceEncrypted's data, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 20/35] qapi: generate correct enum names for camel case enums, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 17/35] block: block_int: include qerror.h, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 03/35] qerror: QERR_DEVICE_ENCRYPTED: change error message, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 24/35] error, qerror: add ErrorClass argument to error functions, Luiz Capitulino, 2012/08/07
- [Qemu-devel] [PATCH 35/35] docs: writing-qmp-commands.txt: update error section, Luiz Capitulino, 2012/08/07