diff mbox

[v16A,17/24] qmp: Don't reuse qmp visitor after grabbing output

Message ID 1462854006-24658-1-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake May 10, 2016, 4:20 a.m. UTC
The testsuite was the only client that attempted to reuse a
QmpOutputVisitor for a second visit after encountering an
error and/or calling qmp_output_get_qobject() on a first
visit.  The next patch is about to tighten the semantics to
be one-shot usage of the visitor, like all other visitors
(which will enable further simplifications down the road).

Signed-off-by: Eric Blake <eblake@redhat.com>
---

This commit is designed to completely replace commit 51750617
on Markus' qapi-next branch; all other patches in that series
remain unchanged and the testsuite still passes.  Doing this
now will make it easier for my next series to introduce a
generalized visit_free(Visitor*) instead of our current
duplication of a per-subtype foo_visit_cleanup(FooVisitor*),
without having to revert the addition of qmp_output_visitor_reset().

 tests/test-qmp-output-visitor.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Markus Armbruster May 10, 2016, 8:18 a.m. UTC | #1
Eric Blake <eblake@redhat.com> writes:

> The testsuite was the only client that attempted to reuse a
> QmpOutputVisitor for a second visit after encountering an
> error and/or calling qmp_output_get_qobject() on a first
> visit.  The next patch is about to tighten the semantics to
> be one-shot usage of the visitor, like all other visitors
> (which will enable further simplifications down the road).
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>
> This commit is designed to completely replace commit 51750617
> on Markus' qapi-next branch; all other patches in that series
> remain unchanged and the testsuite still passes.  Doing this
> now will make it easier for my next series to introduce a
> generalized visit_free(Visitor*) instead of our current
> duplication of a per-subtype foo_visit_cleanup(FooVisitor*),
> without having to revert the addition of qmp_output_visitor_reset().

Patch looks good to me.  I massaged qapi-next as instructed.  Thanks!
diff mbox

Patch

diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 8acc229..5543511 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -43,6 +43,12 @@  static void visitor_output_teardown(TestOutputVisitorData *data,
     data->ov = NULL;
 }

+static void visitor_reset(TestOutputVisitorData *data)
+{
+    visitor_output_teardown(data, NULL);
+    visitor_output_setup(data, NULL);
+}
+
 static void test_visitor_out_int(TestOutputVisitorData *data,
                                  const void *unused)
 {
@@ -139,6 +145,7 @@  static void test_visitor_out_enum(TestOutputVisitorData *data,
         g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), ==,
                         EnumOne_lookup[i]);
         qobject_decref(obj);
+        visitor_reset(data);
     }
 }

@@ -153,6 +160,7 @@  static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
         visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err);
         g_assert(err);
         error_free(err);
+        visitor_reset(data);
     }
 }

@@ -262,6 +270,7 @@  static void test_visitor_out_struct_errors(TestOutputVisitorData *data,
         visit_type_UserDefOne(data->ov, "unused", &pu, &err);
         g_assert(err);
         error_free(err);
+        visitor_reset(data);
     }
 }

@@ -366,6 +375,7 @@  static void test_visitor_out_any(TestOutputVisitorData *data,
     qobject_decref(obj);
     qobject_decref(qobj);

+    visitor_reset(data);
     qdict = qdict_new();
     qdict_put(qdict, "integer", qint_from_int(-42));
     qdict_put(qdict, "boolean", qbool_from_bool(true));
@@ -442,6 +452,7 @@  static void test_visitor_out_alternate(TestOutputVisitorData *data,
     qapi_free_UserDefAlternate(tmp);
     qobject_decref(arg);

+    visitor_reset(data);
     tmp = g_new0(UserDefAlternate, 1);
     tmp->type = QTYPE_QSTRING;
     tmp->u.s = g_strdup("hello");
@@ -455,6 +466,7 @@  static void test_visitor_out_alternate(TestOutputVisitorData *data,
     qapi_free_UserDefAlternate(tmp);
     qobject_decref(arg);

+    visitor_reset(data);
     tmp = g_new0(UserDefAlternate, 1);
     tmp->type = QTYPE_QDICT;
     tmp->u.udfu.integer = 1;