From nobody Mon Feb 9 02:27:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500538052150722.0523900816364; Thu, 20 Jul 2017 01:07:32 -0700 (PDT) Received: from localhost ([::1]:36586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY6Ub-0007bi-MY for importer@patchew.org; Thu, 20 Jul 2017 04:07:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY6HT-0003kX-Cn for qemu-devel@nongnu.org; Thu, 20 Jul 2017 03:53:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY6HR-00039O-1r for qemu-devel@nongnu.org; Thu, 20 Jul 2017 03:53:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44490) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dY6HK-0002sd-Hm; Thu, 20 Jul 2017 03:53:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4A5D356C6; Thu, 20 Jul 2017 07:53:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 120B817981; Thu, 20 Jul 2017 07:53:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7563C1138648; Thu, 20 Jul 2017 09:53:41 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A4A5D356C6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A4A5D356C6 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 20 Jul 2017 09:53:33 +0200 Message-Id: <1500537221-20556-3-git-send-email-armbru@redhat.com> In-Reply-To: <1500537221-20556-1-git-send-email-armbru@redhat.com> References: <1500537221-20556-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 20 Jul 2017 07:53:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 02/10] qapi: Use QNull for a more regular visit_type_null() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make visit_type_null() take an @obj argument like its buddies. This helps keep the next commit simple. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Daniel P. Berrange --- hw/ppc/spapr_drc.c | 4 +++- include/qapi/visitor-impl.h | 3 ++- include/qapi/visitor.h | 8 ++++---- qapi/qapi-clone-visitor.c | 5 +++-- qapi/qapi-dealloc-visitor.c | 6 +++++- qapi/qapi-visit-core.c | 7 ++++--- qapi/qobject-input-visitor.c | 6 +++++- qapi/qobject-output-visitor.c | 3 ++- qapi/string-input-visitor.c | 8 +++++++- qapi/string-output-visitor.c | 3 ++- qapi/trace-events | 2 +- target/ppc/translate_init.c | 5 ++++- tests/check-qnull.c | 9 +++++++-- tests/test-qobject-input-visitor.c | 13 +++++++++---- tests/test-qobject-output-visitor.c | 3 ++- 15 files changed, 60 insertions(+), 25 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 0ffcec6..15bae5c 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -297,12 +297,14 @@ static void prop_get_fdt(Object *obj, Visitor *v, con= st char *name, void *opaque, Error **errp) { sPAPRDRConnector *drc =3D SPAPR_DR_CONNECTOR(obj); + QNull *null =3D NULL; Error *err =3D NULL; int fdt_offset_next, fdt_offset, fdt_depth; void *fdt; =20 if (!drc->fdt) { - visit_type_null(v, NULL, errp); + visit_type_null(v, NULL, &null, errp); + QDECREF(null); return; } =20 diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index dcd656a..8ccb3b6 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -103,7 +103,8 @@ struct Visitor Error **errp); =20 /* 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); =20 /* 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/include/qapi/visitor.h b/include/qapi/visitor.h index 74768aa..fe9faf4 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -618,10 +618,10 @@ void visit_type_any(Visitor *v, const char *name, QOb= ject **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); =20 #endif diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c index ed16d3a..d8b6279 100644 --- a/qapi/qapi-clone-visitor.c +++ b/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() */ } =20 -static void qapi_clone_type_null(Visitor *v, const char *name, Error **err= p) +static void qapi_clone_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { QapiCloneVisitor *qcv =3D to_qcv(v); =20 assert(qcv->depth); - /* Nothing to do */ + *obj =3D qnull(); } =20 static void qapi_clone_free(Visitor *v) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index fd6f9fb..ed70a01 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -103,8 +103,12 @@ static void qapi_dealloc_type_anything(Visitor *v, con= st char *name, } } =20 -static void qapi_dealloc_type_null(Visitor *v, const char *name, Error **e= rrp) +static void qapi_dealloc_type_null(Visitor *v, const char *name, + QNull **obj, Error **errp) { + if (obj) { + QDECREF(*obj); + } } =20 static void qapi_dealloc_free(Visitor *v) diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 935a2c5..ed6d2af 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -325,10 +325,11 @@ void visit_type_any(Visitor *v, const char *name, QOb= ject **obj, Error **errp) error_propagate(errp, err); } =20 -void visit_type_null(Visitor *v, const char *name, Error **errp) +void visit_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { - trace_visit_type_null(v, name); - v->type_null(v, name, errp); + trace_visit_type_null(v, name, obj); + v->type_null(v, name, obj, errp); } =20 static void output_type_enum(Visitor *v, const char *name, int *obj, diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index 35aff78..ee9e47d 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -587,11 +587,13 @@ static void qobject_input_type_any(Visitor *v, const = char *name, QObject **obj, *obj =3D qobj; } =20 -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 =3D to_qiv(v); QObject *qobj =3D qobject_input_get_object(qiv, name, true, errp); =20 + *obj =3D NULL; if (!qobj) { return; } @@ -599,7 +601,9 @@ static void qobject_input_type_null(Visitor *v, const c= har *name, Error **errp) if (qobject_type(qobj) !=3D QTYPE_QNULL) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "null"); + return; } + *obj =3D qnull(); } =20 static void qobject_input_type_size_keyval(Visitor *v, const char *name, diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c index 398dcb5..d325163 100644 --- a/qapi/qobject-output-visitor.c +++ b/qapi/qobject-output-visitor.c @@ -187,7 +187,8 @@ static void qobject_output_type_any(Visitor *v, const c= har *name, qobject_output_add_obj(qov, name, *obj); } =20 -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 =3D to_qov(v); qobject_output_add(qov, name, qnull()); diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index 63ae115..67a0a4a 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -326,14 +326,20 @@ static void parse_type_number(Visitor *v, const char = *name, double *obj, *obj =3D val; } =20 -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 =3D to_siv(v); =20 + *obj =3D NULL; + if (!siv->string || siv->string[0]) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "null"); + return; } + + *obj =3D qnull(); } =20 static void string_input_free(Visitor *v) diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index af649e1..7ab6446 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -256,7 +256,8 @@ static void print_type_number(Visitor *v, const char *n= ame, double *obj, string_output_set(sov, g_strdup_printf("%f", *obj)); } =20 -static void print_type_null(Visitor *v, const char *name, Error **errp) +static void print_type_null(Visitor *v, const char *name, QNull **obj, + Error **errp) { StringOutputVisitor *sov =3D to_sov(v); char *out; diff --git a/qapi/trace-events b/qapi/trace-events index 3b57aba..9e9008a 100644 --- a/qapi/trace-events +++ b/qapi/trace-events @@ -31,4 +31,4 @@ visit_type_bool(void *v, const char *name, bool *obj) "v= =3D%p name=3D%s obj=3D%p" visit_type_str(void *v, const char *name, char **obj) "v=3D%p name=3D%s ob= j=3D%p" visit_type_number(void *v, const char *name, double *obj) "v=3D%p name=3D%= s obj=3D%p" visit_type_any(void *v, const char *name, void *obj) "v=3D%p name=3D%s obj= =3D%p" -visit_type_null(void *v, const char *name) "v=3D%p name=3D%s" +visit_type_null(void *v, const char *name, void *obj) "v=3D%p name=3D%s ob= j=3D%p" diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index b325c2c..01723bd 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -8428,11 +8428,14 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data) static void getset_compat_deprecated(Object *obj, Visitor *v, const char *= name, void *opaque, Error **errp) { + QNull *null =3D NULL; + if (!qtest_enabled()) { error_report("CPU 'compat' property is deprecated and has no effec= t; " "use max-cpu-compat machine property instead"); } - visit_type_null(v, name, NULL); + visit_type_null(v, name, &null, NULL); + QDECREF(null); } =20 static const PropertyInfo ppc_compat_deprecated_propinfo =3D { diff --git a/tests/check-qnull.c b/tests/check-qnull.c index 1ab7c98..5c6eb0a 100644 --- a/tests/check-qnull.c +++ b/tests/check-qnull.c @@ -38,6 +38,7 @@ static void qnull_visit_test(void) { QObject *obj; Visitor *v; + QNull *null; =20 /* * Most tests of interactions between QObject and visitors are in @@ -49,13 +50,17 @@ static void qnull_visit_test(void) obj =3D QOBJECT(qnull()); v =3D qobject_input_visitor_new(obj); qobject_decref(obj); - visit_type_null(v, NULL, &error_abort); + visit_type_null(v, NULL, &null, &error_abort); + g_assert(obj =3D=3D QOBJECT(&qnull_)); + QDECREF(null); visit_free(v); =20 + null =3D NULL; v =3D qobject_output_visitor_new(&obj); - visit_type_null(v, NULL, &error_abort); + visit_type_null(v, NULL, &null, &error_abort); visit_complete(v, &obj); g_assert(obj =3D=3D QOBJECT(&qnull_)); + QDECREF(null); qobject_decref(obj); visit_free(v); =20 diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index 34bab8a..f98caf9 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -510,6 +510,7 @@ static void test_visitor_in_null(TestInputVisitorData *= data, { Visitor *v; Error *err =3D NULL; + QNull *null; char *tmp; =20 /* @@ -524,12 +525,15 @@ static void test_visitor_in_null(TestInputVisitorData= *data, v =3D visitor_input_test_init_full(data, false, "{ 'a': null, 'b': '' }"); visit_start_struct(v, NULL, NULL, 0, &error_abort); - visit_type_null(v, "a", &error_abort); - visit_type_null(v, "b", &err); + visit_type_null(v, "a", &null, &error_abort); + g_assert(qobject_type(QOBJECT(null)) =3D=3D QTYPE_QNULL); + QDECREF(null); + visit_type_null(v, "b", &null, &err); error_free_or_abort(&err); + g_assert(!null); visit_type_str(v, "c", &tmp, &err); - g_assert(!tmp); error_free_or_abort(&err); + g_assert(!tmp); visit_check_struct(v, &error_abort); visit_end_struct(v, NULL); } @@ -1087,6 +1091,7 @@ static void test_visitor_in_fail_struct_missing(TestI= nputVisitorData *data, Error *err =3D NULL; Visitor *v; QObject *any; + QNull *null; GenericAlternate *alt; bool present; int en; @@ -1120,7 +1125,7 @@ static void test_visitor_in_fail_struct_missing(TestI= nputVisitorData *data, error_free_or_abort(&err); visit_type_any(v, "any", &any, &err); error_free_or_abort(&err); - visit_type_null(v, "null", &err); + visit_type_null(v, "null", &null, &err); error_free_or_abort(&err); visit_start_list(v, "sub", NULL, 0, &error_abort); visit_start_struct(v, NULL, NULL, 0, &error_abort); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 749c540..8f1fcd4 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -445,11 +445,12 @@ static void test_visitor_out_alternate(TestOutputVisi= torData *data, static void test_visitor_out_null(TestOutputVisitorData *data, const void *unused) { + QNull *null =3D NULL; QDict *qdict; QObject *nil; =20 visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); - visit_type_null(data->ov, "a", &error_abort); + visit_type_null(data->ov, "a", &null, &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); qdict =3D qobject_to_qdict(visitor_get(data)); --=20 2.7.5