qmp: Support explicit null during visits

Implement the new type_null() callback for the qmp input and
output visitors. While we don't yet have a use for this in QAPI
input (the generator will need some tweaks first), some
potential usages have already been discussed on the list.
Meanwhile, the output visitor could already output explicit null
via type_any, but this gives us finer control.

At any rate, it's easy to test that we can round-trip an explicit
null through manual use of visit_type_null() wrapped by a virtual
visit_start_struct() walk, even if we can't do the visit in a
QAPI type. Repurpose the test_visitor_out_empty test,
particularly since a future patch will tighten semantics to
forbid use of qmp_output_get_qobject() without at least one
intervening visit_type_*.

Backports commit 3df016f185521f8dfa5bd89168722887156405c7 from qemu
This commit is contained in:
Eric Blake 2018-02-23 19:02:11 -05:00 committed by Lioncash
parent ef6b7b50f6
commit e5b2cff2bd
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 9 additions and 2 deletions

View file

@ -345,7 +345,13 @@ static void qmp_input_type_any(Visitor *v, const char *name, QObject **obj,
static void qmp_input_type_null(Visitor *v, const char *name, Error **errp)
{
abort();
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);
if (qobject_type(qobj) != QTYPE_QNULL) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"null");
}
}
static void qmp_input_optional(Visitor *v, const char *name, bool *present)

View file

@ -199,7 +199,8 @@ static void qmp_output_type_any(Visitor *v, const char *name, QObject **obj,
static void qmp_output_type_null(Visitor *v, const char *name, Error **errp)
{
abort();
QmpOutputVisitor *qov = to_qov(v);
qmp_output_add_obj(qov, name, qnull());
}
/* Finish building, and return the root object. Will not be NULL. */