From 4a7abec7c92337ada5ed60b49bd39403286a1c2e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 7 Mar 2018 16:49:20 -0500 Subject: [PATCH] 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 --- qemu/include/qapi/visitor-impl.h | 3 ++- qemu/include/qapi/visitor.h | 8 ++++---- qemu/qapi/qapi-clone-visitor.c | 5 +++-- qemu/qapi/qapi-dealloc-visitor.c | 6 +++++- qemu/qapi/qapi-visit-core.c | 5 +++-- qemu/qapi/qobject-input-visitor.c | 7 ++++++- qemu/qapi/qobject-output-visitor.c | 3 ++- qemu/qapi/string-input-visitor.c | 8 +++++++- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/qemu/include/qapi/visitor-impl.h b/qemu/include/qapi/visitor-impl.h index 48bb36d2..b7a0906b 100644 --- a/qemu/include/qapi/visitor-impl.h +++ b/qemu/include/qapi/visitor-impl.h @@ -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. */ diff --git a/qemu/include/qapi/visitor.h b/qemu/include/qapi/visitor.h index 7563589c..6394096a 100644 --- a/qemu/include/qapi/visitor.h +++ b/qemu/include/qapi/visitor.h @@ -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 diff --git a/qemu/qapi/qapi-clone-visitor.c b/qemu/qapi/qapi-clone-visitor.c index ed16d3a1..d8b62792 100644 --- a/qemu/qapi/qapi-clone-visitor.c +++ b/qemu/qapi/qapi-clone-visitor.c @@ -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) diff --git a/qemu/qapi/qapi-dealloc-visitor.c b/qemu/qapi/qapi-dealloc-visitor.c index 7b6b5768..9074f32f 100644 --- a/qemu/qapi/qapi-dealloc-visitor.c +++ b/qemu/qapi/qapi-dealloc-visitor.c @@ -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) diff --git a/qemu/qapi/qapi-visit-core.c b/qemu/qapi/qapi-visit-core.c index 3c1a0520..beaa128d 100644 --- a/qemu/qapi/qapi-visit-core.c +++ b/qemu/qapi/qapi-visit-core.c @@ -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, diff --git a/qemu/qapi/qobject-input-visitor.c b/qemu/qapi/qobject-input-visitor.c index d5daff5a..fccd12c9 100644 --- a/qemu/qapi/qobject-input-visitor.c +++ b/qemu/qapi/qobject-input-visitor.c @@ -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) diff --git a/qemu/qapi/qobject-output-visitor.c b/qemu/qapi/qobject-output-visitor.c index cc8c85b5..5f3f2a51 100644 --- a/qemu/qapi/qobject-output-visitor.c +++ b/qemu/qapi/qobject-output-visitor.c @@ -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()); diff --git a/qemu/qapi/string-input-visitor.c b/qemu/qapi/string-input-visitor.c index de3546f6..0fc36c0b 100644 --- a/qemu/qapi/string-input-visitor.c +++ b/qemu/qapi/string-input-visitor.c @@ -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)