From nobody Mon Feb 9 10:29:23 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 1500897569391270.7044340791168; Mon, 24 Jul 2017 04:59:29 -0700 (PDT) Received: from localhost ([::1]:54235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZc1G-0002xa-O8 for importer@patchew.org; Mon, 24 Jul 2017 07:59:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZbyy-00014u-5r for qemu-devel@nongnu.org; Mon, 24 Jul 2017 07:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZbyw-0006rr-MC for qemu-devel@nongnu.org; Mon, 24 Jul 2017 07:57:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dZbyw-0006rE-D6 for qemu-devel@nongnu.org; Mon, 24 Jul 2017 07:57:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41DB27DCF0 for ; Mon, 24 Jul 2017 11:57:01 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D70BB67CF4 for ; Mon, 24 Jul 2017 11:57:00 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 48DFB113864F; Mon, 24 Jul 2017 13:56:59 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 41DB27DCF0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 41DB27DCF0 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 24 Jul 2017 13:56:52 +0200 Message-Id: <1500897419-15539-4-git-send-email-armbru@redhat.com> In-Reply-To: <1500897419-15539-1-git-send-email-armbru@redhat.com> References: <1500897419-15539-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 24 Jul 2017 11:57:01 +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] [PULL v2 03/10] qapi: Introduce a first class 'null' type 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: , 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" I expect the 'null' type to be useful mostly for members of alternate types. Signed-off-by: Markus Armbruster Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.txt | 10 ++++++---- include/qapi/qmp/qobject.h | 4 ++-- include/qemu/typedefs.h | 1 + scripts/qapi.py | 5 ++++- tests/qapi-schema/qapi-schema-test.json | 3 ++- tests/qapi-schema/qapi-schema-test.out | 1 + tests/test-qobject-input-visitor.c | 5 +++++ tests/test-qobject-output-visitor.c | 10 ++++++++++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 52e3874..9903ac4 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -282,6 +282,7 @@ The following types are predefined, and map to C as fol= lows: size uint64_t like uint64_t, except StringInputVisitor accepts size suffixes bool bool JSON true or false + null QNull * JSON null any QObject * any JSON value QType QType JSON string matching enum QType values =20 @@ -536,10 +537,11 @@ can only express a choice between types represented d= ifferently in JSON. If a branch is typed as the 'bool' built-in, the alternate accepts true and false; if it is typed as any of the various numeric built-ins, it accepts a JSON number; if it is typed as a 'str' -built-in or named enum type, it accepts a JSON string; and if it is -typed as a complex type (struct or union), it accepts a JSON object. -Two different complex types, for instance, aren't permitted, because -both are represented as a JSON object. +built-in or named enum type, it accepts a JSON string; if it is typed +as the 'null' built-in, it accepts JSON null; and if it is typed as a +complex type (struct or union), it accepts a JSON object. Two +different complex types, for instance, aren't permitted, because both +are represented as a JSON object. =20 The example alternate declaration above allows using both of the following example objects: diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h index 3543b55..eab29ed 100644 --- a/include/qapi/qmp/qobject.h +++ b/include/qapi/qmp/qobject.h @@ -93,9 +93,9 @@ static inline QType qobject_type(const QObject *obj) return obj->type; } =20 -typedef struct QNull { +struct QNull { QObject base; -} QNull; +}; =20 extern QNull qnull_; =20 diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 7b0d4e7..39bc835 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -89,6 +89,7 @@ typedef struct QEMUSGList QEMUSGList; typedef struct QEMUTimer QEMUTimer; typedef struct QEMUTimerListGroup QEMUTimerListGroup; typedef struct QObject QObject; +typedef struct QNull QNull; typedef struct RAMBlock RAMBlock; typedef struct Range Range; typedef struct SerialState SerialState; diff --git a/scripts/qapi.py b/scripts/qapi.py index 84e2eb4..8aa2775 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -20,6 +20,7 @@ import sys from ordereddict import OrderedDict =20 builtin_types =3D { + 'null': 'QTYPE_QNULL', 'str': 'QTYPE_QSTRING', 'int': 'QTYPE_QNUM', 'number': 'QTYPE_QNUM', @@ -1056,6 +1057,7 @@ class QAPISchemaType(QAPISchemaEntity): =20 def alternate_qtype(self): json2qtype =3D { + 'null': 'QTYPE_QNULL', 'string': 'QTYPE_QSTRING', 'number': 'QTYPE_QNUM', 'int': 'QTYPE_QNUM', @@ -1515,7 +1517,8 @@ class QAPISchema(object): ('uint64', 'int', 'uint64_t'), ('size', 'int', 'uint64_t'), ('bool', 'boolean', 'bool'), - ('any', 'value', 'QObject' + pointer_suffix)]: + ('any', 'value', 'QObject' + pointer_suffix), + ('null', 'null', 'QNull' + pointer_suffix)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( 'q_empty', None, None, None, [], None) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 91ffb26..c72dbd8 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -93,7 +93,8 @@ { 'struct': 'WrapAlternate', 'data': { 'alt': 'UserDefAlternate' } } { 'alternate': 'UserDefAlternate', - 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int' } } + 'data': { 'udfu': 'UserDefFlatUnion', 'e': 'EnumOne', 'i': 'int', + 'n': 'null' } } =20 { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index b88b8aa..3b1e908 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -64,6 +64,7 @@ alternate UserDefAlternate case udfu: UserDefFlatUnion case e: EnumOne case i: int + case n: null object UserDefB member intb: int optional=3DFalse member a-b: bool optional=3DTrue diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index f98caf9..f451844 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -583,6 +583,11 @@ static void test_visitor_in_alternate(TestInputVisitor= Data *data, g_assert_cmpint(tmp->u.e, =3D=3D, ENUM_ONE_VALUE1); qapi_free_UserDefAlternate(tmp); =20 + v =3D visitor_input_test_init(data, "null"); + visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, QTYPE_QNULL); + qapi_free_UserDefAlternate(tmp); + v =3D visitor_input_test_init(data, "{'integer':1, 'string':'str', " "'enum1':'value1', 'boolean':true}"); visit_type_UserDefAlternate(v, NULL, &tmp, &error_abort); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 8f1fcd4..7eb1620 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -424,6 +424,16 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, =20 visitor_reset(data); tmp =3D g_new0(UserDefAlternate, 1); + tmp->type =3D QTYPE_QNULL; + tmp->u.n =3D qnull(); + + visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); + g_assert_cmpint(qobject_type(visitor_get(data)), =3D=3D, QTYPE_QNULL); + + qapi_free_UserDefAlternate(tmp); + + visitor_reset(data); + tmp =3D g_new0(UserDefAlternate, 1); tmp->type =3D QTYPE_QDICT; tmp->u.udfu.integer =3D 1; tmp->u.udfu.string =3D g_strdup("str"); --=20 2.7.5