From e1bc2f7b3fb19ab2abcec3d5b15e045b00ae9da1 Mon Sep 17 00:00:00 2001 From: Michael Roth Date: Mon, 19 Sep 2011 19:03:11 -0500 Subject: qapi: modify visitor code generation for list iteration Modify logic such that we never assign values to the list head argument to progress through the list on subsequent iterations, instead rely only on having our return value passed back in as an argument on the next call. Also update QMP I/O visitors and test cases accordingly, and add a missing test case for QmpOutputVisitor. Reviewed-by: Anthony Liguori Signed-off-by: Michael Roth Signed-off-by: Luiz Capitulino --- qapi/qmp-input-visitor.c | 4 ++-- qapi/qmp-output-visitor.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'qapi') diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index fcf8bf920..8cbc0abcf 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -144,8 +144,6 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list, } (*list)->next = entry; } - *list = entry; - return entry; } @@ -240,9 +238,11 @@ static void qmp_input_type_enum(Visitor *v, int *obj, const char *strings[], if (strings[value] == NULL) { error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); + g_free(enum_str); return; } + g_free(enum_str); *obj = value; } diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index 4419a3164..d67724ea4 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -20,6 +20,7 @@ typedef struct QStackEntry { QObject *value; + bool is_list_head; QTAILQ_ENTRY(QStackEntry) node; } QStackEntry; @@ -45,6 +46,9 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value) QStackEntry *e = g_malloc0(sizeof(*e)); e->value = value; + if (qobject_type(e->value) == QTYPE_QLIST) { + e->is_list_head = true; + } QTAILQ_INSERT_HEAD(&qov->stack, e, node); } @@ -122,12 +126,20 @@ static void qmp_output_start_list(Visitor *v, const char *name, Error **errp) qmp_output_push(qov, list); } -static GenericList *qmp_output_next_list(Visitor *v, GenericList **list, +static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp, Error **errp) { - GenericList *retval = *list; - *list = retval->next; - return retval; + GenericList *list = *listp; + QmpOutputVisitor *qov = to_qov(v); + QStackEntry *e = QTAILQ_FIRST(&qov->stack); + + assert(e); + if (e->is_list_head) { + e->is_list_head = false; + return list; + } + + return list ? list->next : NULL; } static void qmp_output_end_list(Visitor *v, Error **errp) -- cgit v1.2.3