qapi: Use QNull for a more regular visit_type_null()

Make visit_type_null() take an @obj argument like its buddies. This
helps keep the next commit simple.

Backports commit d2f95f4d482374485234790a6fc3cca29ebb7355 from qemu
This commit is contained in:
Markus Armbruster 2018-03-07 16:49:20 -05:00 committed by Lioncash
parent 3fd0ff8aa7
commit 4a7abec7c9
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
8 changed files with 32 additions and 13 deletions

View file

@ -104,7 +104,8 @@ struct Visitor
Error **errp);
/* Must be set to visit explicit null values. */
void (*type_null)(Visitor *v, const char *name, Error **errp);
void (*type_null)(Visitor *v, const char *name, QNull **obj,
Error **errp);
/* Must be set for input visitors to visit structs, optional otherwise.
The core takes care of the return type in the public interface. */

View file

@ -618,10 +618,10 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp);
* @name expresses the relationship of the null value to its parent
* container; see the general description of @name above.
*
* Unlike all other visit_type_* functions, no obj parameter is
* needed; rather, this is a witness that an explicit null value is
* expected rather than any other type.
* @obj must be non-NULL. Input visitors set *@obj to the value;
* other visitors ignore *@obj.
*/
void visit_type_null(Visitor *v, const char *name, Error **errp);
void visit_type_null(Visitor *v, const char *name, QNull **obj,
Error **errp);
#endif

View file

@ -127,12 +127,13 @@ static void qapi_clone_type_number(Visitor *v, const char *name, double *obj,
/* Value was already cloned by g_memdup() */
}
static void qapi_clone_type_null(Visitor *v, const char *name, Error **errp)
static void qapi_clone_type_null(Visitor *v, const char *name, QNull **obj,
Error **errp)
{
QapiCloneVisitor *qcv = to_qcv(v);
assert(qcv->depth);
/* Nothing to do */
*obj = qnull();
}
static void qapi_clone_free(Visitor *v)

View file

@ -103,8 +103,12 @@ static void qapi_dealloc_type_anything(Visitor *v, const char *name,
}
}
static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **errp)
static void qapi_dealloc_type_null(Visitor *v, const char *name,
QNull **obj, Error **errp)
{
if (obj) {
QDECREF(*obj);
}
}
static void qapi_dealloc_free(Visitor *v)

View file

@ -280,9 +280,10 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp)
error_propagate(errp, err);
}
void visit_type_null(Visitor *v, const char *name, Error **errp)
void visit_type_null(Visitor *v, const char *name, QNull **obj,
Error **errp)
{
v->type_null(v, name, errp);
v->type_null(v, name, obj, errp);
}
static void output_type_enum(Visitor *v, const char *name, int *obj,

View file

@ -465,11 +465,13 @@ static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
*obj = qobj;
}
static void qobject_input_type_null(Visitor *v, const char *name, Error **errp)
static void qobject_input_type_null(Visitor *v, const char *name,
QNull **obj, Error **errp)
{
QObjectInputVisitor *qiv = to_qiv(v);
QObject *qobj = qobject_input_get_object(qiv, name, true, errp);
*obj = NULL;
if (!qobj) {
return;
}
@ -477,7 +479,10 @@ static void qobject_input_type_null(Visitor *v, const char *name, Error **errp)
if (qobject_type(qobj) != QTYPE_QNULL) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "null");
return;
}
*obj = qnull();
}
static void qobject_input_optional(Visitor *v, const char *name, bool *present)

View file

@ -193,7 +193,8 @@ static void qobject_output_type_any(Visitor *v, const char *name, QObject **obj,
qobject_output_add_obj(qov, name, *obj);
}
static void qobject_output_type_null(Visitor *v, const char *name, Error **errp)
static void qobject_output_type_null(Visitor *v, const char *name,
QNull **obj, Error **errp)
{
QObjectOutputVisitor *qov = to_qov(v);
qobject_output_add(qov, name, qnull());

View file

@ -310,14 +310,20 @@ static void parse_type_number(Visitor *v, const char *name, double *obj,
*obj = val;
}
static void parse_type_null(Visitor *v, const char *name, Error **errp)
static void parse_type_null(Visitor *v, const char *name, QNull **obj,
Error **errp)
{
StringInputVisitor *siv = to_siv(v);
*obj = NULL;
if (!siv->string || siv->string[0]) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"null");
return;
}
*obj = qnull();
}
static void string_input_free(Visitor *v)