diff --git a/include/qapi/string-input-visitor.h b/include/qapi/string-input-visitor.h index 7b76c2b9e3..33551340e3 100644 --- a/include/qapi/string-input-visitor.h +++ b/include/qapi/string-input-visitor.h @@ -22,9 +22,6 @@ typedef struct StringInputVisitor StringInputVisitor; * QAPI structs, alternates, null, or arbitrary QTypes. It also * requires a non-null list argument to visit_start_list(). */ -StringInputVisitor *string_input_visitor_new(const char *str); -void string_input_visitor_cleanup(StringInputVisitor *v); - -Visitor *string_input_get_visitor(StringInputVisitor *v); +Visitor *string_input_visitor_new(const char *str); #endif diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 6fb1229586..8dfa561252 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -326,26 +326,16 @@ static void parse_optional(Visitor *v, const char *name, bool *present) *present = true; } -Visitor *string_input_get_visitor(StringInputVisitor *v) -{ - return &v->visitor; -} - static void string_input_free(Visitor *v) { StringInputVisitor *siv = to_siv(v); - string_input_visitor_cleanup(siv); + g_list_foreach(siv->ranges, free_range, NULL); + g_list_free(siv->ranges); + g_free(siv); } -void string_input_visitor_cleanup(StringInputVisitor *v) -{ - g_list_foreach(v->ranges, free_range, NULL); - g_list_free(v->ranges); - g_free(v); -} - -StringInputVisitor *string_input_visitor_new(const char *str) +Visitor *string_input_visitor_new(const char *str) { StringInputVisitor *v; @@ -365,5 +355,5 @@ StringInputVisitor *string_input_visitor_new(const char *str) v->visitor.free = string_input_free; v->string = str; - return v; + return &v->visitor; } diff --git a/qom/object.c b/qom/object.c index 3d6a95518b..02c0a3a98f 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1222,7 +1222,7 @@ int object_property_get_enum(Object *obj, const char *name, { Error *err = NULL; StringOutputVisitor *sov; - StringInputVisitor *siv; + Visitor *v; char *str; int ret; ObjectProperty *prop = object_property_find(obj, name, errp); @@ -1249,13 +1249,12 @@ int object_property_get_enum(Object *obj, const char *name, return 0; } str = string_output_get_string(sov); - siv = string_input_visitor_new(str); string_output_visitor_cleanup(sov); - visit_type_enum(string_input_get_visitor(siv), name, &ret, - enumprop->strings, errp); + v = string_input_visitor_new(str); + visit_type_enum(v, name, &ret, enumprop->strings, errp); g_free(str); - string_input_visitor_cleanup(siv); + visit_free(v); return ret; } @@ -1265,7 +1264,7 @@ void object_property_get_uint16List(Object *obj, const char *name, { Error *err = NULL; StringOutputVisitor *ov; - StringInputVisitor *iv; + Visitor *v; char *str; ov = string_output_visitor_new(false); @@ -1276,11 +1275,11 @@ void object_property_get_uint16List(Object *obj, const char *name, goto out; } str = string_output_get_string(ov); - iv = string_input_visitor_new(str); - visit_type_uint16List(string_input_get_visitor(iv), NULL, list, errp); + v = string_input_visitor_new(str); + visit_type_uint16List(v, NULL, list, errp); g_free(str); - string_input_visitor_cleanup(iv); + visit_free(v); out: string_output_visitor_cleanup(ov); } @@ -1288,11 +1287,9 @@ out: void object_property_parse(Object *obj, const char *string, const char *name, Error **errp) { - StringInputVisitor *siv; - siv = string_input_visitor_new(string); - object_property_set(obj, string_input_get_visitor(siv), name, errp); - - string_input_visitor_cleanup(siv); + Visitor *v = string_input_visitor_new(string); + object_property_set(obj, v, name, errp); + visit_free(v); } char *object_property_print(Object *obj, const char *name, bool human, diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-visitor.c index 7fe7a9c270..d837ebedad 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -20,15 +20,15 @@ #include "qapi/qmp/types.h" typedef struct TestInputVisitorData { - StringInputVisitor *siv; + Visitor *v; } TestInputVisitorData; static void visitor_input_teardown(TestInputVisitorData *data, const void *unused) { - if (data->siv) { - string_input_visitor_cleanup(data->siv); - data->siv = NULL; + if (data->v) { + visit_free(data->v); + data->v = NULL; } } @@ -39,15 +39,9 @@ static Visitor *visitor_input_test_init(TestInputVisitorData *data, const char *string) { - Visitor *v; - - data->siv = string_input_visitor_new(string); - g_assert(data->siv != NULL); - - v = string_input_get_visitor(data->siv); - g_assert(v != NULL); - - return v; + data->v = string_input_visitor_new(string); + g_assert(data->v); + return data->v; } static void test_visitor_in_int(TestInputVisitorData *data, @@ -199,8 +193,6 @@ static void test_visitor_in_enum(TestInputVisitorData *data, visitor_input_teardown(data, NULL); } - - data->siv = NULL; } /* Try to crash the visitors */ diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index bcbfd2aeb7..c3c8634294 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -1056,7 +1056,7 @@ static void qmp_cleanup(void *datap) typedef struct StringSerializeData { char *string; StringOutputVisitor *sov; - StringInputVisitor *siv; + Visitor *siv; } StringSerializeData; static void string_serialize(void *native_in, void **datap, @@ -1076,7 +1076,7 @@ static void string_deserialize(void **native_out, void *datap, d->string = string_output_get_string(d->sov); d->siv = string_input_visitor_new(d->string); - visit(string_input_get_visitor(d->siv), native_out, errp); + visit(d->siv, native_out, errp); } static void string_cleanup(void *datap) @@ -1084,7 +1084,7 @@ static void string_cleanup(void *datap) StringSerializeData *d = datap; string_output_visitor_cleanup(d->sov); - string_input_visitor_cleanup(d->siv); + visit_free(d->siv); g_free(d->string); g_free(d); }