summaryrefslogtreecommitdiffstats
path: root/qemu/qapi/string-input-visitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu/qapi/string-input-visitor.c')
-rw-r--r--qemu/qapi/string-input-visitor.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/qemu/qapi/string-input-visitor.c b/qemu/qapi/string-input-visitor.c
index bbd6a5456..5ea2d77b5 100644
--- a/qemu/qapi/string-input-visitor.c
+++ b/qemu/qapi/string-input-visitor.c
@@ -1,7 +1,7 @@
/*
* String parsing visitor
*
- * Copyright Red Hat, Inc. 2012
+ * Copyright Red Hat, Inc. 2012-2016
*
* Author: Paolo Bonzini <pbonzini@redhat.com>
*
@@ -10,6 +10,8 @@
*
*/
+#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qemu-common.h"
#include "qapi/string-input-visitor.h"
#include "qapi/visitor-impl.h"
@@ -32,6 +34,11 @@ struct StringInputVisitor
const char *string;
};
+static StringInputVisitor *to_siv(Visitor *v)
+{
+ return container_of(v, StringInputVisitor, visitor);
+}
+
static void free_range(void *range, void *dummy)
{
g_free(range);
@@ -120,7 +127,7 @@ error:
static void
start_list(Visitor *v, const char *name, Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
parse_str(siv, errp);
@@ -133,10 +140,9 @@ start_list(Visitor *v, const char *name, Error **errp)
}
}
-static GenericList *
-next_list(Visitor *v, GenericList **list, Error **errp)
+static GenericList *next_list(Visitor *v, GenericList **list, size_t size)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
GenericList **link;
Range *r;
@@ -168,21 +174,20 @@ next_list(Visitor *v, GenericList **list, Error **errp)
link = &(*list)->next;
}
- *link = g_malloc0(sizeof **link);
+ *link = g_malloc0(size);
return *link;
}
-static void
-end_list(Visitor *v, Error **errp)
+static void end_list(Visitor *v)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
siv->head = true;
}
-static void parse_type_int(Visitor *v, int64_t *obj, const char *name,
- Error **errp)
+static void parse_type_int64(Visitor *v, const char *name, int64_t *obj,
+ Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
if (!siv->string) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
@@ -217,14 +222,28 @@ static void parse_type_int(Visitor *v, int64_t *obj, const char *name,
return;
error:
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name,
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
"an int64 value or range");
}
-static void parse_type_size(Visitor *v, uint64_t *obj, const char *name,
+static void parse_type_uint64(Visitor *v, const char *name, uint64_t *obj,
+ Error **errp)
+{
+ /* FIXME: parse_type_int64 mishandles values over INT64_MAX */
+ int64_t i;
+ Error *err = NULL;
+ parse_type_int64(v, name, &i, &err);
+ if (err) {
+ error_propagate(errp, err);
+ } else {
+ *obj = i;
+ }
+}
+
+static void parse_type_size(Visitor *v, const char *name, uint64_t *obj,
Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
Error *err = NULL;
uint64_t val;
@@ -243,10 +262,10 @@ static void parse_type_size(Visitor *v, uint64_t *obj, const char *name,
*obj = val;
}
-static void parse_type_bool(Visitor *v, bool *obj, const char *name,
+static void parse_type_bool(Visitor *v, const char *name, bool *obj,
Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
if (siv->string) {
if (!strcasecmp(siv->string, "on") ||
@@ -267,10 +286,10 @@ static void parse_type_bool(Visitor *v, bool *obj, const char *name,
"boolean");
}
-static void parse_type_str(Visitor *v, char **obj, const char *name,
+static void parse_type_str(Visitor *v, const char *name, char **obj,
Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
if (siv->string) {
*obj = g_strdup(siv->string);
} else {
@@ -279,10 +298,10 @@ static void parse_type_str(Visitor *v, char **obj, const char *name,
}
}
-static void parse_type_number(Visitor *v, double *obj, const char *name,
+static void parse_type_number(Visitor *v, const char *name, double *obj,
Error **errp)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
char *endp = (char *) siv->string;
double val;
@@ -299,10 +318,9 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
*obj = val;
}
-static void parse_optional(Visitor *v, bool *present, const char *name,
- Error **errp)
+static void parse_optional(Visitor *v, const char *name, bool *present)
{
- StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+ StringInputVisitor *siv = to_siv(v);
if (!siv->string) {
*present = false;
@@ -331,7 +349,8 @@ StringInputVisitor *string_input_visitor_new(const char *str)
v = g_malloc0(sizeof(*v));
v->visitor.type_enum = input_type_enum;
- v->visitor.type_int = parse_type_int;
+ v->visitor.type_int64 = parse_type_int64;
+ v->visitor.type_uint64 = parse_type_uint64;
v->visitor.type_size = parse_type_size;
v->visitor.type_bool = parse_type_bool;
v->visitor.type_str = parse_type_str;