[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 07/24] qapi: Factor out common qobject_input_get_
From: |
Markus Armbruster |
Subject: |
[Qemu-block] [PATCH v2 07/24] qapi: Factor out common qobject_input_get_keyval() |
Date: |
Tue, 28 Feb 2017 22:26:53 +0100 |
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
qapi/qobject-input-visitor.c | 87 ++++++++++++++++++--------------------------
1 file changed, 35 insertions(+), 52 deletions(-)
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 270033e..6c56040 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -151,6 +151,28 @@ static QObject
*qobject_input_get_object(QObjectInputVisitor *qiv,
return obj;
}
+static const char *qobject_input_get_keyval(QObjectInputVisitor *qiv,
+ const char *name,
+ Error **errp)
+{
+ QObject *qobj;
+ QString *qstr;
+
+ qobj = qobject_input_get_object(qiv, name, true, errp);
+ if (!qobj) {
+ return NULL;
+ }
+
+ qstr = qobject_to_qstring(qobj);
+ if (!qstr) {
+ error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
+ full_name(qiv, name), "string");
+ return NULL;
+ }
+
+ return qstring_get_str(qstr);
+}
+
static void qdict_add_key(const char *key, QObject *obj, void *opaque)
{
GHashTable *h = opaque;
@@ -343,20 +365,13 @@ static void qobject_input_type_int64_keyval(Visitor *v,
const char *name,
int64_t *obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
- QString *qstr;
+ const char *str = qobject_input_get_keyval(qiv, name, errp);
- if (!qobj) {
- return;
- }
- qstr = qobject_to_qstring(qobj);
- if (!qstr) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
- full_name(qiv, name), "string");
+ if (!str) {
return;
}
- if (qemu_strtoi64(qstring_get_str(qstr), NULL, 0, obj) < 0) {
+ if (qemu_strtoi64(str, NULL, 0, obj) < 0) {
/* TODO report -ERANGE more nicely */
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
full_name(qiv, name), "integer");
@@ -388,20 +403,13 @@ static void qobject_input_type_uint64_keyval(Visitor *v,
const char *name,
uint64_t *obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
- QString *qstr;
+ const char *str = qobject_input_get_keyval(qiv, name, errp);
- if (!qobj) {
- return;
- }
- qstr = qobject_to_qstring(qobj);
- if (!qstr) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
- full_name(qiv, name), "string");
+ if (!str) {
return;
}
- if (qemu_strtou64(qstring_get_str(qstr), NULL, 0, obj) < 0) {
+ if (qemu_strtou64(str, NULL, 0, obj) < 0) {
/* TODO report -ERANGE more nicely */
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
full_name(qiv, name), "integer");
@@ -432,21 +440,12 @@ static void qobject_input_type_bool_keyval(Visitor *v,
const char *name,
bool *obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
- QString *qstr;
- const char *str;
+ const char *str = qobject_input_get_keyval(qiv, name, errp);
- if (!qobj) {
- return;
- }
- qstr = qobject_to_qstring(qobj);
- if (!qstr) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
- full_name(qiv, name), "string");
+ if (!str) {
return;
}
- str = qstring_get_str(qstr);
if (!strcmp(str, "on")) {
*obj = true;
} else if (!strcmp(str, "off")) {
@@ -509,22 +508,13 @@ static void qobject_input_type_number_keyval(Visitor *v,
const char *name,
double *obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
- QString *qstr;
- const char *str;
+ const char *str = qobject_input_get_keyval(qiv, name, errp);
char *endp;
- if (!qobj) {
- return;
- }
- qstr = qobject_to_qstring(qobj);
- if (!qstr) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
- full_name(qiv, name), "string");
+ if (!str) {
return;
}
- str = qstring_get_str(qstr);
errno = 0;
*obj = strtod(str, &endp);
if (errno || endp == str || *endp) {
@@ -568,20 +558,13 @@ static void qobject_input_type_size_keyval(Visitor *v,
const char *name,
uint64_t *obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
- QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
- QString *qstr;
+ const char *str = qobject_input_get_keyval(qiv, name, errp);
- if (!qobj) {
- return;
- }
- qstr = qobject_to_qstring(qobj);
- if (!qstr) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
- full_name(qiv, name), "string");
+ if (!str) {
return;
}
- if (qemu_strtosz(qstring_get_str(qstr), NULL, obj) < 0) {
+ if (qemu_strtosz(str, NULL, obj) < 0) {
/* TODO report -ERANGE more nicely */
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
full_name(qiv, name), "size");
--
2.7.4
- [Qemu-block] [PATCH v2 13/24] block: More detailed syntax error reporting for JSON filenames, (continued)
- [Qemu-block] [PATCH v2 13/24] block: More detailed syntax error reporting for JSON filenames, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 11/24] test-qobject-input-visitor: Abort earlier on bad test input, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 03/24] keyval: New keyval_parse(), Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 04/24] qapi: qobject input visitor variant for use with keyval_parse(), Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 15/24] test-visitor-serialization: Pass &error_abort to qobject_from_json(), Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 23/24] docs/qapi-code-gen.txt: Clarify naming rules, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 06/24] qapi: Factor out common part of qobject input visitor creation, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 07/24] qapi: Factor out common qobject_input_get_keyval(),
Markus Armbruster <=
- [Qemu-block] [PATCH v2 16/24] monitor: Assert qmp_schema_json[] is sane, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 20/24] qapi: New qobject_input_visitor_new_str() for convenience, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 19/24] keyval: Restrict key components to valid QAPI names, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 22/24] qapi: Improve how keyval input visitor reports unexpected dicts, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 05/24] test-keyval: Cover use with qobject input visitor, Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 14/24] check-qjson: Test errors from qobject_from_json(), Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 12/24] qobject: Propagate parse errors through qobject_from_json(), Markus Armbruster, 2017/02/28
- [Qemu-block] [PATCH v2 18/24] qapi: New parse_qapi_name(), Markus Armbruster, 2017/02/28