From e88a7e260b2fc737659d623265a1aafcd0a2cbdb Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sun, 25 Feb 2018 01:08:00 -0500 Subject: [PATCH] string-input-visitor: Favor new visit_free() function Now that we have a polymorphic visit_free(), we no longer need string_input_visitor_cleanup(); which in turn means we no longer need to return a subtype from string_input_visitor_new() nor a public upcast function. Backports commit 7a0525c7be6b38d32d586e3fd12e7377ded21faa from qemu --- qemu/include/qapi/string-input-visitor.h | 5 +---- qemu/qapi/string-input-visitor.c | 20 +++++--------------- qemu/qom/object.c | 8 +++----- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/qemu/include/qapi/string-input-visitor.h b/qemu/include/qapi/string-input-visitor.h index 7b76c2b9..33551340 100644 --- a/qemu/include/qapi/string-input-visitor.h +++ b/qemu/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/qemu/qapi/string-input-visitor.c b/qemu/qapi/string-input-visitor.c index f7563118..e7884afd 100644 --- a/qemu/qapi/string-input-visitor.c +++ b/qemu/qapi/string-input-visitor.c @@ -304,26 +304,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; @@ -343,5 +333,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/qemu/qom/object.c b/qemu/qom/object.c index b1b674b9..eb2e5dc5 100644 --- a/qemu/qom/object.c +++ b/qemu/qom/object.c @@ -1099,11 +1099,9 @@ int64_t object_property_get_int(struct uc_struct *uc, Object *obj, const char *n void object_property_parse(struct uc_struct *uc, Object *obj, const char *string, const char *name, Error **errp) { - StringInputVisitor *siv; - siv = string_input_visitor_new(string); - object_property_set(uc, obj, string_input_get_visitor(siv), name, errp); - - string_input_visitor_cleanup(siv); + Visitor *v = string_input_visitor_new(string); + object_property_set(uc, obj, v, name, errp); + visit_free(v); } const char *object_property_get_type(struct uc_struct *uc, Object *obj,