qmp: Don't abuse stack to track qmp-output root
authorEric Blake <eblake@redhat.com>
Fri, 29 Jan 2016 13:49:01 +0000 (06:49 -0700)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 8 Feb 2016 16:29:57 +0000 (17:29 +0100)
commit455ba08afde784466420449d01c6458f88349d55
treee98e5fcc34b727f2258025de0a6a219bd4d70d7e
parenta86156401559cb4401cf9ecc704faeab6fc8bb19
qmp: Don't abuse stack to track qmp-output root

The previous commit documented an inconsistency in how we are
using the stack of qmp-output-visitor.  Normally, pushing a
single top-level object puts the object on the stack twice:
once as the root, and once as the current container being
appended to; but popping that struct only pops once.  However,
qmp_ouput_add() was trying to either set up the added object
as the new root (works if you parse two top-level scalars in a
row: the second replaces the first as the root) or as a member
of the current container (works as long as you have an open
container on the stack; but if you have popped the first
top-level container, it then resolves to the root and still
tries to add into that existing container).

Fix the stupidity by not tracking two separate things in the
stack.  Drop the now-useless qmp_output_first() and
qmp_output_last() while at it.

Saved for a later patch: we still are rather sloppy in that
qmp_output_get_object() can be called in the middle of a parse,
rather than requiring that a visit is complete.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1454075341-13658-26-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
qapi/qmp-output-visitor.c