[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/18] qemu-option: qemu_opt_parse(): use error_set(
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 05/18] qemu-option: qemu_opt_parse(): use error_set() |
Date: |
Tue, 17 Apr 2012 16:36:08 -0300 |
The functions opt_set() and qemu_opts_validate() both call qemu_opt_parse(),
but their callers expect QError semantics. Thus, both functions call
qerro_report_err() to keep the expected semantics.
Signed-off-by: Luiz Capitulino <address@hidden>
---
qemu-option.c | 54 +++++++++++++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 61354af..4829de5 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -584,38 +584,27 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char
*name, uint64_t defval)
return opt->value.uint;
}
-static int qemu_opt_parse(QemuOpt *opt)
+static void qemu_opt_parse(QemuOpt *opt, Error **errp)
{
- Error *local_err = NULL;
-
if (opt->desc == NULL)
- return 0;
+ return;
switch (opt->desc->type) {
case QEMU_OPT_STRING:
/* nothing */
- return 0;
+ return;
case QEMU_OPT_BOOL:
- parse_option_bool(opt->name, opt->str, &opt->value.boolean,
&local_err);
+ parse_option_bool(opt->name, opt->str, &opt->value.boolean, errp);
break;
case QEMU_OPT_NUMBER:
- parse_option_number(opt->name, opt->str, &opt->value.uint,
- &local_err);
+ parse_option_number(opt->name, opt->str, &opt->value.uint, errp);
break;
case QEMU_OPT_SIZE:
- parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err);
+ parse_option_size(opt->name, opt->str, &opt->value.uint, errp);
break;
default:
abort();
}
-
- if (error_is_set(&local_err)) {
- qerror_report_err(local_err);
- error_free(local_err);
- return -1;
- }
-
- return 0;
}
static void qemu_opt_del(QemuOpt *opt)
@@ -631,6 +620,7 @@ static int opt_set(QemuOpts *opts, const char *name, const
char *value,
{
QemuOpt *opt;
const QemuOptDesc *desc = opts->list->desc;
+ Error *local_err = NULL;
int i;
for (i = 0; desc[i].name != NULL; i++) {
@@ -642,8 +632,8 @@ static int opt_set(QemuOpts *opts, const char *name, const
char *value,
if (i == 0) {
/* empty list -> allow any */;
} else {
- qerror_report(QERR_INVALID_PARAMETER, name);
- return -1;
+ error_set(&local_err, QERR_INVALID_PARAMETER, name);
+ goto exit_err;
}
}
@@ -661,11 +651,18 @@ static int opt_set(QemuOpts *opts, const char *name,
const char *value,
if (value) {
opt->str = g_strdup(value);
}
- if (qemu_opt_parse(opt) < 0) {
+ qemu_opt_parse(opt, &local_err);
+ if (error_is_set(&local_err)) {
qemu_opt_del(opt);
- return -1;
+ goto exit_err;
}
+
return 0;
+
+exit_err:
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
}
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)
@@ -1053,6 +1050,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc)
{
QemuOpt *opt;
+ Error *local_err = NULL;
assert(opts->list->desc[0].name == NULL);
@@ -1065,18 +1063,24 @@ int qemu_opts_validate(QemuOpts *opts, const
QemuOptDesc *desc)
}
}
if (desc[i].name == NULL) {
- qerror_report(QERR_INVALID_PARAMETER, opt->name);
- return -1;
+ error_set(&local_err, QERR_INVALID_PARAMETER, opt->name);
+ goto exit_err;
}
opt->desc = &desc[i];
- if (qemu_opt_parse(opt) < 0) {
- return -1;
+ qemu_opt_parse(opt, &local_err);
+ if (error_is_set(&local_err)) {
+ goto exit_err;
}
}
return 0;
+
+exit_err:
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
}
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void
*opaque,
--
1.7.9.2.384.g4a92a
- [Qemu-devel] [PATCH 00/18]: qapi: convert netdev_add & netdev_del, Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 02/18] qemu-option: parse_option_number(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 01/18] qemu-option: qemu_opts_create(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 06/18] qemu-option: qemu_opts_validate(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 05/18] qemu-option: qemu_opt_parse(): use error_set(),
Luiz Capitulino <=
- [Qemu-devel] [PATCH 07/18] qemu-option: opt_set(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 10/18] qemu-option: introduce qemu_opt_set_err(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 08/18] qemu-option: opts_do_parse(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 09/18] qemu-option: qemu_opts_do_parse(): convert error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 04/18] qemu-option: parse_option_size(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 14/18] qstring: introduce qstring_len(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 03/18] qemu-option: parse_option_bool(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 11/18] qerror: introduce QERR_INVALID_OPTION_GROUP, Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 12/18] qemu-config: find_list(): use error_set(), Luiz Capitulino, 2012/04/17
- [Qemu-devel] [PATCH 16/18] net: purge the monitor object from all init functions, Luiz Capitulino, 2012/04/17