diff options
author | Eric Blake <eblake@redhat.com> | 2016-06-09 10:48:34 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2016-07-06 10:52:04 +0200 |
commit | 1158bb2a058fcdd0c8fc3e60dc77f7a57ddbb271 (patch) | |
tree | 664c9629ebc73d9677d0aaba207ecab5cc87582f /qapi/qmp-input-visitor.c | |
parent | 911ee36d411ee9b3540855642b53219b6a974992 (diff) |
qapi: Add parameter to visit_end_*
Rather than making the dealloc visitor track of stack of pointers
remembered during visit_start_* in order to free them during
visit_end_*, it's a lot easier to just make all callers pass the
same pointer to visit_end_*. The generated code has access to the
same pointer, while all other users are doing virtual walks and
can pass NULL. The dealloc visitor is then greatly simplified.
All three visit_end_*() functions intentionally take a void**,
even though the visit_start_*() functions differ between void**,
GenericList**, and GenericAlternate**. This is done for several
reasons: when doing a virtual walk, passing NULL doesn't care
what the type is, but when doing a generated walk, we already
have to cast the caller's specific FOO* to call visit_start,
while using void** lets us use visit_end without a cast. Also,
an upcoming patch will add a clone visitor that wants to use
the same implementation for all three visit_end callbacks,
which is made easier if all three share the same signature.
For visitors with already track per-object state (the QMP visitors
via a stack, and the string visitors which do not allow nesting),
add an assertion that the caller is indeed passing the same
pointer to paired calls.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-4-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qapi/qmp-input-visitor.c')
-rw-r--r-- | qapi/qmp-input-visitor.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index aea90a1378..e16b4b0725 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -26,6 +26,7 @@ typedef struct StackObject { QObject *obj; /* Object being visited */ + void *qapi; /* sanity check that caller uses same pointer */ GHashTable *h; /* If obj is dict: unvisited keys */ const QListEntry *entry; /* If obj is list: unvisited tail */ @@ -96,7 +97,7 @@ static void qdict_add_key(const char *key, QObject *obj, void *opaque) } static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj, - Error **errp) + void *qapi, Error **errp) { GHashTable *h; StackObject *tos = &qiv->stack[qiv->nb_stack]; @@ -108,6 +109,7 @@ static const QListEntry *qmp_input_push(QmpInputVisitor *qiv, QObject *obj, } tos->obj = obj; + tos->qapi = qapi; assert(!tos->h); assert(!tos->entry); @@ -145,12 +147,13 @@ static void qmp_input_check_struct(Visitor *v, Error **errp) } } -static void qmp_input_pop(Visitor *v) +static void qmp_input_pop(Visitor *v, void **obj) { QmpInputVisitor *qiv = to_qiv(v); StackObject *tos = &qiv->stack[qiv->nb_stack - 1]; assert(qiv->nb_stack > 0); + assert(tos->qapi == obj); if (qiv->strict) { GHashTable * const top_ht = qiv->stack[qiv->nb_stack - 1].h; @@ -179,7 +182,7 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj, return; } - qmp_input_push(qiv, qobj, &err); + qmp_input_push(qiv, qobj, obj, &err); if (err) { error_propagate(errp, err); return; @@ -207,7 +210,7 @@ static void qmp_input_start_list(Visitor *v, const char *name, return; } - entry = qmp_input_push(qiv, qobj, errp); + entry = qmp_input_push(qiv, qobj, list, errp); if (list) { if (entry) { *list = g_malloc0(size); |