aboutsummaryrefslogtreecommitdiff
path: root/qapi/qapi-visit-core.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2016-07-06 11:38:09 +0100
committerPeter Maydell <peter.maydell@linaro.org>2016-07-06 11:38:09 +0100
commit975b1c3ac6ae57b3e1356b0156c68f63a8a349dc (patch)
treeecd35419f10196800c44176645084c3691f660df /qapi/qapi-visit-core.c
parentfc5d0a2b243ad7bd4db1f29e6e274507df54a8a8 (diff)
parentb6954712abea03afd686b724060f9873e2c61f2b (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-07-06' into staging
QAPI patches for 2016-07-06 # gpg: Signature made Wed 06 Jul 2016 10:00:51 BST # gpg: using RSA key 0x3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2016-07-06: replay: Use new QAPI cloning sockets: Use new QAPI cloning qapi: Add new clone visitor qapi: Add new visit_complete() function tests: Factor out common code in qapi output tests tests: Clean up test-string-output-visitor qmp-output-visitor: Favor new visit_free() function string-output-visitor: Favor new visit_free() function qmp-input-visitor: Favor new visit_free() function string-input-visitor: Favor new visit_free() function opts-visitor: Favor new visit_free() function qapi: Add new visit_free() function qapi: Add parameter to visit_end_* qemu-img: Don't leak errors when outputting JSON qapi: Improve use of qmp/types.h Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qapi/qapi-visit-core.c')
-rw-r--r--qapi/qapi-visit-core.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index eada4676a2..55f5876dc0 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -20,6 +20,21 @@
#include "qapi/visitor.h"
#include "qapi/visitor-impl.h"
+void visit_complete(Visitor *v, void *opaque)
+{
+ assert(v->type != VISITOR_OUTPUT || v->complete);
+ if (v->complete) {
+ v->complete(v, opaque);
+ }
+}
+
+void visit_free(Visitor *v)
+{
+ if (v) {
+ v->free(v);
+ }
+}
+
void visit_start_struct(Visitor *v, const char *name, void **obj,
size_t size, Error **errp)
{
@@ -27,10 +42,10 @@ void visit_start_struct(Visitor *v, const char *name, void **obj,
if (obj) {
assert(size);
- assert(v->type != VISITOR_OUTPUT || *obj);
+ assert(!(v->type & VISITOR_OUTPUT) || *obj);
}
v->start_struct(v, name, obj, size, &err);
- if (obj && v->type == VISITOR_INPUT) {
+ if (obj && (v->type & VISITOR_INPUT)) {
assert(!err != !*obj);
}
error_propagate(errp, err);
@@ -43,9 +58,9 @@ void visit_check_struct(Visitor *v, Error **errp)
}
}
-void visit_end_struct(Visitor *v)
+void visit_end_struct(Visitor *v, void **obj)
{
- v->end_struct(v);
+ v->end_struct(v, obj);
}
void visit_start_list(Visitor *v, const char *name, GenericList **list,
@@ -55,7 +70,7 @@ void visit_start_list(Visitor *v, const char *name, GenericList **list,
assert(!list || size >= sizeof(GenericList));
v->start_list(v, name, list, size, &err);
- if (list && v->type == VISITOR_INPUT) {
+ if (list && (v->type & VISITOR_INPUT)) {
assert(!(err && *list));
}
error_propagate(errp, err);
@@ -67,9 +82,9 @@ GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size)
return v->next_list(v, tail, size);
}
-void visit_end_list(Visitor *v)
+void visit_end_list(Visitor *v, void **obj)
{
- v->end_list(v);
+ v->end_list(v, obj);
}
void visit_start_alternate(Visitor *v, const char *name,
@@ -79,20 +94,20 @@ void visit_start_alternate(Visitor *v, const char *name,
Error *err = NULL;
assert(obj && size >= sizeof(GenericAlternate));
- assert(v->type != VISITOR_OUTPUT || *obj);
+ assert(!(v->type & VISITOR_OUTPUT) || *obj);
if (v->start_alternate) {
v->start_alternate(v, name, obj, size, promote_int, &err);
}
- if (v->type == VISITOR_INPUT) {
+ if (v->type & VISITOR_INPUT) {
assert(v->start_alternate && !err != !*obj);
}
error_propagate(errp, err);
}
-void visit_end_alternate(Visitor *v)
+void visit_end_alternate(Visitor *v, void **obj)
{
if (v->end_alternate) {
- v->end_alternate(v);
+ v->end_alternate(v, obj);
}
}
@@ -235,10 +250,10 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp)
assert(obj);
/* TODO: Fix callers to not pass NULL when they mean "", so that we
* can enable:
- assert(v->type != VISITOR_OUTPUT || *obj);
+ assert(!(v->type & VISITOR_OUTPUT) || *obj);
*/
v->type_str(v, name, obj, &err);
- if (v->type == VISITOR_INPUT) {
+ if (v->type & VISITOR_INPUT) {
assert(!err != !*obj);
}
error_propagate(errp, err);
@@ -320,9 +335,19 @@ void visit_type_enum(Visitor *v, const char *name, int *obj,
const char *const strings[], Error **errp)
{
assert(obj && strings);
- if (v->type == VISITOR_INPUT) {
+ switch (v->type) {
+ case VISITOR_INPUT:
input_type_enum(v, name, obj, strings, errp);
- } else if (v->type == VISITOR_OUTPUT) {
+ break;
+ case VISITOR_OUTPUT:
output_type_enum(v, name, obj, strings, errp);
+ break;
+ case VISITOR_CLONE:
+ /* nothing further to do, scalar value was already copied by
+ * g_memdup() during visit_start_*() */
+ break;
+ case VISITOR_DEALLOC:
+ /* nothing to deallocate for a scalar */
+ break;
}
}