@@ -1,7 +1,7 @@
/*
* Core Definitions for QAPI/QMP Command Registry
*
- * Copyright (C) 2015 Red Hat, Inc.
+ * Copyright (C) 2015-2016 Red Hat, Inc.
* Copyright IBM, Corp. 2011
*
* Authors:
@@ -57,17 +57,15 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value)
QTAILQ_INSERT_HEAD(&qov->stack, e, node);
}
-/* Grab and remove the most recent QObject from the stack */
-static QObject *qmp_output_pop(QmpOutputVisitor *qov)
+/* Remove the most recent QObject with given type from the stack */
+static void qmp_output_pop(QmpOutputVisitor *qov, QType type)
{
QStackEntry *e = QTAILQ_FIRST(&qov->stack);
- QObject *value;
assert(e);
QTAILQ_REMOVE(&qov->stack, e, node);
- value = e->value;
+ assert(qobject_type(e->value) == type);
g_free(e);
- return value;
}
/* Grab the most recent QObject from the stack, if any */
@@ -120,7 +118,7 @@ static void qmp_output_start_struct(Visitor *v, const char *name, void **obj,
static void qmp_output_end_struct(Visitor *v, Error **errp)
{
QmpOutputVisitor *qov = to_qov(v);
- qmp_output_pop(qov);
+ qmp_output_pop(qov, QTYPE_QDICT);
}
static void qmp_output_start_list(Visitor *v, const char *name, Error **errp)
@@ -151,7 +149,7 @@ static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp,
static void qmp_output_end_list(Visitor *v)
{
QmpOutputVisitor *qov = to_qov(v);
- qmp_output_pop(qov);
+ qmp_output_pop(qov, QTYPE_QLIST);
}
static void qmp_output_type_int64(Visitor *v, const char *name, int64_t *obj,
Nothing was using the return value of qmp_output_pop(). Also, adding a parameter will let us diagnose any programming bugs due to mismatched push(struct)/pop(list) or push(list)/pop(struct). Signed-off-by: Eric Blake <eblake@redhat.com> --- v9: new patch; probably worth squashing into 23/35 --- qapi/qmp-output-visitor.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)