[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 31/34] error, qerror: pass desc string to error
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH 31/34] error, qerror: pass desc string to error calls |
Date: |
Thu, 02 Aug 2012 19:19:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) |
Luiz Capitulino <address@hidden> writes:
> This commit changes all QERR_ macros to contain a human message (ie.
> the desc string found in qerr_table[]) instead of a json dictionary
> in string format.
>
> Before this commit, error_set() and qerror_report() would receive
> a json dictionary in string format and build a qobject from it. Now,
> both function receive a human message instead and the qobject is
> not built anymore.
>
> Signed-off-by: Luiz Capitulino <address@hidden>
> ---
> error.c | 5 ++-
> qerror.c | 44 ++------------------
> qerror.h | 141
> +++++++++++++++++++++++++++++++--------------------------------
> 3 files changed, 76 insertions(+), 114 deletions(-)
>
> diff --git a/error.c b/error.c
> index 15a2d06..740824c 100644
> --- a/error.c
> +++ b/error.c
> @@ -29,6 +29,7 @@ void error_set(Error **errp, ErrorClass err_class, const
> char *fmt, ...)
> {
> Error *err;
> va_list ap;
> + char msg[2048];
>
> if (errp == NULL) {
> return;
> @@ -38,9 +39,9 @@ void error_set(Error **errp, ErrorClass err_class, const
> char *fmt, ...)
> err = g_malloc0(sizeof(*err));
>
> va_start(ap, fmt);
> - err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap));
> + vsnprintf(msg, sizeof(msg), fmt, ap);
> va_end(ap);
> - err->msg = qerror_format(fmt, err->obj);
> + err->msg = g_strdup(msg);
Suggest
err->msg = g_strdup_vprintf(fmt, ap);
> err->err_class = err_class;
>
> *errp = err;
> diff --git a/qerror.c b/qerror.c
> index 19a1902..db6bb47 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -342,45 +342,6 @@ static QError *qerror_new(void)
> return qerr;
> }
>
> -static QDict *error_obj_from_fmt_no_fail(const char *fmt, va_list *va)
> -{
> - QObject *obj;
> - QDict *ret;
> -
> - obj = qobject_from_jsonv(fmt, va);
> - if (!obj) {
> - fprintf(stderr, "invalid json in error dict '%s'\n", fmt);
> - abort();
> - }
> - if (qobject_type(obj) != QTYPE_QDICT) {
> - fprintf(stderr, "error is not a dict '%s'\n", fmt);
> - abort();
> - }
> -
> - ret = qobject_to_qdict(obj);
> - obj = qdict_get(ret, "class");
> - if (!obj) {
> - fprintf(stderr, "missing 'class' key in '%s'\n", fmt);
> - abort();
> - }
> - if (qobject_type(obj) != QTYPE_QSTRING) {
> - fprintf(stderr, "'class' key value should be a string in '%s'\n",
> fmt);
> - abort();
> - }
> -
> - obj = qdict_get(ret, "data");
> - if (!obj) {
> - fprintf(stderr, "missing 'data' key in '%s'\n", fmt);
> - abort();
> - }
> - if (qobject_type(obj) != QTYPE_QDICT) {
> - fprintf(stderr, "'data' key value should be a dict in '%s'\n", fmt);
> - abort();
> - }
> -
> - return ret;
> -}
> -
> /**
> * qerror_from_info(): Create a new QError from error information
> *
> @@ -390,13 +351,14 @@ static QError *qerror_from_info(ErrorClass err_class,
> const char *fmt,
> va_list *va)
> {
> QError *qerr;
> + char msg[2048];
>
> qerr = qerror_new();
> loc_save(&qerr->loc);
>
> qerr->err_class = err_class;
> - qerr->error = error_obj_from_fmt_no_fail(fmt, va);
> - qerr->err_msg = qerror_format(fmt, qerr->error);
> + vsnprintf(msg, sizeof(msg), fmt, *va);
> + qerr->err_msg = g_strdup(msg);
Suggest
qerr->err_msg = g_strdup_vprintf(fmt, *va);
>
> return qerr;
> }
[...]
- [Qemu-devel] [PATCH 28/34] error: add error_get_class(), (continued)
- [Qemu-devel] [PATCH 28/34] error: add error_get_class(), Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 25/34] qerror: qerror_table: don't use C99 struct initializers, Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 34/34] error, qerror: drop QDict member, Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 26/34] error, qerror: add ErrorClass argument to error functions, Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 33/34] error: drop error_get_qobject()/error_set_qobject(), Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 24/34] qapi-schema: add ErrorClass enum, Luiz Capitulino, 2012/08/01
- [Qemu-devel] [PATCH 31/34] error, qerror: pass desc string to error calls, Luiz Capitulino, 2012/08/01
- Re: [Qemu-devel] [PATCH 31/34] error, qerror: pass desc string to error calls,
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH v1 00/34]: add new error format, Luiz Capitulino, 2012/08/02
- Re: [Qemu-devel] [PATCH v1 00/34]: add new error format, Markus Armbruster, 2012/08/02