string-output-visitor: Favor new visit_free() function
authorEric Blake <eblake@redhat.com>
Thu, 9 Jun 2016 16:48:39 +0000 (10:48 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Wed, 6 Jul 2016 08:52:04 +0000 (10:52 +0200)
Now that we have a polymorphic visit_free(), we no longer need
string_output_visitor_cleanup(); however, we still need to
expose the subtype for string_output_get_string().

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-9-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
hmp.c
include/qapi/string-output-visitor.h
net/net.c
qapi/string-output-visitor.c
qom/object.c
tests/test-string-output-visitor.c
tests/test-visitor-serialization.c

diff --git a/hmp.c b/hmp.c
index fd5daa75b7d5b3823699cc1a2e3a90bdd680a351..559cad1bb53554d297dbb76b9c3339450b781d6c 100644 (file)
--- a/hmp.c
+++ b/hmp.c
@@ -2006,7 +2006,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "  host nodes: %s\n", str);
 
         g_free(str);
-        string_output_visitor_cleanup(ov);
+        visit_free(string_output_get_visitor(ov));
         m = m->next;
         i++;
     }
index e10522a35bee49332163ff9f31853b7664ba5fa9..03e377e50bcc4fb0e9328112b1ef5f48b3e0e0e1 100644 (file)
@@ -23,7 +23,6 @@ typedef struct StringOutputVisitor StringOutputVisitor;
  * requires a non-null list argument to visit_start_list().
  */
 StringOutputVisitor *string_output_visitor_new(bool human);
-void string_output_visitor_cleanup(StringOutputVisitor *v);
 
 char *string_output_get_string(StringOutputVisitor *v);
 Visitor *string_output_get_visitor(StringOutputVisitor *v);
index d25f80232aba1aa568afa5cb7cba4e32b6205f0a..336469f9cc1f92f7a1ffaf865257764e2ed23193 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -1210,7 +1210,7 @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
         object_property_get(OBJECT(nf), string_output_get_visitor(ov),
                             prop->name, NULL);
         str = string_output_get_string(ov);
-        string_output_visitor_cleanup(ov);
+        visit_free(string_output_get_visitor(ov));
         monitor_printf(mon, ",%s=%s", prop->name, str);
         g_free(str);
     }
index ff9ddf068a4ec7c6f34479fcfdb691b3b56ac95b..78aab876e39f4898b510024f1e85a215410dee45 100644 (file)
@@ -326,11 +326,6 @@ static void string_output_free(Visitor *v)
 {
     StringOutputVisitor *sov = to_sov(v);
 
-    string_output_visitor_cleanup(sov);
-}
-
-void string_output_visitor_cleanup(StringOutputVisitor *sov)
-{
     if (sov->string) {
         g_string_free(sov->string, true);
     }
index 02c0a3a98f4a147f0bbd0e2458d4bab59efc9dd7..2407b667d9f198452c54539a1e013f7037abc648 100644 (file)
@@ -1242,14 +1242,15 @@ int object_property_get_enum(Object *obj, const char *name,
     enumprop = prop->opaque;
 
     sov = string_output_visitor_new(false);
-    object_property_get(obj, string_output_get_visitor(sov), name, &err);
+    v = string_output_get_visitor(sov);
+    object_property_get(obj, v, name, &err);
     if (err) {
         error_propagate(errp, err);
-        string_output_visitor_cleanup(sov);
+        visit_free(v);
         return 0;
     }
     str = string_output_get_string(sov);
-    string_output_visitor_cleanup(sov);
+    visit_free(v);
     v = string_input_visitor_new(str);
     visit_type_enum(v, name, &ret, enumprop->strings, errp);
 
@@ -1281,7 +1282,7 @@ void object_property_get_uint16List(Object *obj, const char *name,
     g_free(str);
     visit_free(v);
 out:
-    string_output_visitor_cleanup(ov);
+    visit_free(string_output_get_visitor(ov));
 }
 
 void object_property_parse(Object *obj, const char *string,
@@ -1309,7 +1310,7 @@ char *object_property_print(Object *obj, const char *name, bool human,
     string = string_output_get_string(sov);
 
 out:
-    string_output_visitor_cleanup(sov);
+    visit_free(string_output_get_visitor(sov));
     return string;
 }
 
index edff5235fe45ba55d4e12d4ad7a948ce649260fa..bfa3e8ec7f7dccb79fc678ac7a8e6864b50cbaad 100644 (file)
@@ -50,7 +50,7 @@ static void visitor_output_setup_human(TestOutputVisitorData *data,
 static void visitor_output_teardown(TestOutputVisitorData *data,
                                     const void *unused)
 {
-    string_output_visitor_cleanup(data->sov);
+    visit_free(data->ov);
     data->sov = NULL;
     data->ov = NULL;
 }
index 0766dcc5a1d3dec5b09a611cd9a9f684be5cd906..377ee3e788146dde9da07f25ba7fbd1b9f983129 100644 (file)
@@ -1047,7 +1047,7 @@ static void qmp_deserialize(void **native_out, void *datap,
 static void qmp_cleanup(void *datap)
 {
     QmpSerializeData *d = datap;
-    qmp_output_visitor_cleanup(d->qov);
+    visit_free(qmp_output_get_visitor(d->qov));
     visit_free(d->qiv);
 
     g_free(d);
@@ -1083,7 +1083,7 @@ static void string_cleanup(void *datap)
 {
     StringSerializeData *d = datap;
 
-    string_output_visitor_cleanup(d->sov);
+    visit_free(string_output_get_visitor(d->sov));
     visit_free(d->siv);
     g_free(d->string);
     g_free(d);