From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIObY-000774-G6 for qemu-devel@nongnu.org; Thu, 23 Jul 2015 18:04:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIObU-0001mt-QO for qemu-devel@nongnu.org; Thu, 23 Jul 2015 18:04:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIObU-0001mW-Jb for qemu-devel@nongnu.org; Thu, 23 Jul 2015 18:04:36 -0400 References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-41-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <55B164EE.7060507@redhat.com> Date: Thu, 23 Jul 2015 16:04:30 -0600 MIME-Version: 1.0 In-Reply-To: <1435782155-31412-41-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3qJsQr64qmSr6hRJqlo9QUIKc5P51g6pN" Subject: Re: [Qemu-devel] [PATCH RFC v2 40/47] qapi: Introduce a first class 'any' type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kwolf@redhat.com, berto@igalia.com, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --3qJsQr64qmSr6hRJqlo9QUIKc5P51g6pN Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/01/2015 02:22 PM, Markus Armbruster wrote: > It's first class, because unlike '**', it actually works, i.e. doesn't > require 'gen': false. Generated code grows in order to accommodate visiting the new anyList typ= e: qapi-types.c | 15 +++++++++++++++ qapi-types.h | 13 +++++++++++++ qapi-visit.c | 24 ++++++++++++++++++++++++ qapi-visit.h | 1 + qga/qapi-generated/qga-qapi-types.h | 13 +++++++++++++ qga/qapi-generated/qga-qapi-visit.h | 1 + 6 files changed, 67 insertions(+) But do we really need anyList as a representation of qapi ['any'] ? Or will a later pass that minimizes array creation only to places where it is needed help? >=20 > '**' will go away next. >=20 > Signed-off-by: Markus Armbruster > --- > docs/qapi-code-gen.txt | 1 + > include/qapi/visitor-impl.h | 2 ++ > include/qapi/visitor.h | 1 + > qapi/qapi-dealloc-visitor.c | 9 +++++++ > qapi/qapi-visit-core.c | 6 +++++ > qapi/qmp-input-visitor.c | 11 ++++++++ > qapi/qmp-output-visitor.c | 9 +++++++ > scripts/qapi-types.py | 1 + > scripts/qapi.py | 9 ++++--- > tests/qapi-schema/type-bypass.out | 4 +-- > tests/test-qmp-input-visitor.c | 45 +++++++++++++++++++++++++++++++= ++ > tests/test-qmp-output-visitor.c | 53 +++++++++++++++++++++++++++++++= ++++++++ > 12 files changed, 146 insertions(+), 5 deletions(-) Touches a bit more this time, but that's okay. >=20 > diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt > index cb0fe75..bf9e854 100644 > --- a/docs/qapi-code-gen.txt > +++ b/docs/qapi-code-gen.txt > @@ -158,6 +158,7 @@ The following types are predefined, and map to C as= follows: > size uint64_t like uint64_t, except StringInputVisitor > accepts size suffixes > bool bool JSON true or false > + any QObject * any JSON value And with this, an 'alternate' type is just a special subset of 'any' that limits the set of valid JSON values according to the qapi descriptio= n. > +++ b/qapi/qapi-visit-core.c > @@ -260,6 +260,12 @@ void visit_type_number(Visitor *v, double *obj, co= nst char *name, Error **errp) > v->type_number(v, obj, name, errp); > } > =20 > +void visit_type_any(Visitor *v, QObject **obj, const char *name, > + Error **errp) Indentation looks off. > @@ -1048,8 +1048,9 @@ class QAPISchema(object): > ('uint64', 'int', 'uint64_t', '0'), > ('size', 'int', 'uint64_t', '0'), > ('bool', 'boolean', 'bool', 'false'), > - ('**', 'value', None, None)]: > + ('any', 'value', 'QObject' + pointer_suffix , '= NULL')]: > self._def_builtin_type(*t) > + self.entity_dict['**'] =3D self.lookup_type('any') # TODO drop= this alias > =20 > def _make_implicit_enum_type(self, name, values): > name =3D name + 'Kind' > @@ -1190,6 +1191,8 @@ class QAPISchema(object): > def visit(self, visitor): > visitor.visit_begin() > for name in sorted(self.entity_dict.keys()): > + if self.entity_dict[name].name !=3D name: > + continue # ignore alias TODO drop alias and rem= ove Nice back-compat hacks while you transition into using it. > +++ b/tests/test-qmp-input-visitor.c > @@ -298,6 +298,49 @@ static void test_visitor_in_list(TestInputVisitorD= ata *data, > qapi_free_UserDefOneList(head); > } > =20 > +static void test_visitor_in_any(TestInputVisitorData *data, > + const void *unused) > +{ > + > + v =3D visitor_input_test_init(data, "-42"); So we prove it accepts ints,... > + v =3D visitor_input_test_init(data, "{ 'integer': -42, 'boolean': = true, 'string': 'foo' }"); objects,... > + visit_type_any(v, &res, NULL, &err); > + g_assert(!err); > + qdict =3D qobject_to_qdict(res); > + g_assert(qdict); worth asserting the dictionary has 3 keys? > +} =2E..but no test of string, boolean, or array? > +++ b/tests/test-qmp-output-visitor.c > @@ -428,6 +428,57 @@ static void test_visitor_out_list_qapi_free(TestOu= tputVisitorData *data, > qapi_free_UserDefTwoList(head); > } > =20 > +static void test_visitor_out_any(TestOutputVisitorData *data, > + const void *unused) > +{ > +} Same tests of 'int' and 'object' but not of other JSON types. Incomplete tests are still better than no tests, so what you have is a good start. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --3qJsQr64qmSr6hRJqlo9QUIKc5P51g6pN Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVsWTuAAoJEKeha0olJ0NqqNcIAJm4kFktjulX2121kRff65X9 cV8Hv4Szu2D65MKAswIDc3KxJh6An+KLmhEmyqQr4lLfjfdpJufvubVzQ7OaDko/ tUV+zMKDuhH1NJfGIpceJr49CUlc7QSntxTOnU7fNazfa1nULJBcQzzJjpeSO6Jh wfRCUU25/dwm1oxiMQDXcl4tgNu1EHoPVh5CN+nXKmMnH36JumwUnoFInUavmw2Z nI20o3UwPjWDLGQX/TxBfxfJWmmRruBW9i3IVdcG4kZgLZ3j1cKFwp8Ayhu/I4S4 +B631Q3g26+lNZbzgDwPwnvFhnAx06/APJYmmY6CRulwB/yIZgotP4jydZDskr8= =XYN5 -----END PGP SIGNATURE----- --3qJsQr64qmSr6hRJqlo9QUIKc5P51g6pN--