Received: from eggs.gnu.org ([2001:4830:134:3::10]:46467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vlblx-0005Vj-J8 for qemu-devel@nongnu.org; Wed, 27 Nov 2013 04:51:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vlblt-0000HZ-5x for qemu-devel@nongnu.org; Wed, 27 Nov 2013 04:51:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vlbls-0000HO-U4 for qemu-devel@nongnu.org; Wed, 27 Nov 2013 04:51:01 -0500 Date: Wed, 27 Nov 2013 10:51:02 +0100 From: Kevin Wolf Message-ID: <20131127095102.GB2884@dhcp-200-207.str.redhat.com> References: <1373971062-28909-1-git-send-email-akong@redhat.com> <1373971062-28909-3-git-send-email-akong@redhat.com> <51E9B81C.2090105@redhat.com> <20131127023217.GA6629@amosk.info> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/9DWx/yDrRhgMJTb" Content-Disposition: inline In-Reply-To: <20131127023217.GA6629@amosk.info> Subject: Re: [Qemu-devel] [PATCH v2 2/2] full introspection support for QMP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amos Kong Cc: aliguori@us.ibm.com, armbru@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 27.11.2013 um 03:32 hat Amos Kong geschrieben: > On Fri, Jul 19, 2013 at 04:05:16PM -0600, Eric Blake wrote: > > On 07/16/2013 04:37 AM, Amos Kong wrote: > > > { 'type': 'DataObject', > > > 'data': { '*key': 'str', '*type': 'str', '*data': ['DataObject'] } } > > >=20 > > > Not all the keys in data will be used. > > > # List: type > > > # Dict: key, type > > > # nested List: type, data > > > # nested Dict: key, type, data > >=20 > > I wonder if we can take advantage of Kevin's work on unions to make this > > MUCH easier to use: > >=20 > > https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg01407.html > >=20 > > { 'enum': 'DataObjectType', > > 'data': [ 'command', 'struct', 'union', 'enum' ] } > > # extend to add 'event' later > >=20 > > { 'type': 'DataObjectBase', > > 'data': { 'name': 'str' } } > >=20 > > { 'union': 'DataObjectMemberType', > > 'discriminator': {}, > > 'data': { 'reference': 'str', > > 'inline': 'DataObject' } } > >=20 > > { 'type': DataObjectMember', > > 'data': { 'name': 'str', 'type': 'DataObjectMemberType', > > '*optional': 'bool', '*recursive': 'bool' } } > >=20 > > { 'type': 'DataObjectStruct', > > 'data': { 'data': [ 'DataObjectMember' ] } } > > { 'type': 'DataObjectEnum', > > 'data': { 'data': [ 'str' ] } } > > { 'type': 'DataObjectUnion', > > 'data': { 'data': [ 'DataObjectMember' ], '*base': 'str', > > '*discriminator': 'str' } } > > { 'type': 'DataObjectCommand', > > 'data': { 'data': [ 'DataObjectMember' ], '*returns': 'DataObject' } } >=20 > =20 > > { 'union': 'DataObject', > > 'base': 'DataObjectBase', > > 'discriminator': 'type', > > 'data': { > > 'struct': 'DataObjectStruct', > > 'enum': 'DataObjectEnum', > > 'union': 'DataObjectUnion', > > 'command': 'DataObjectCommand', >=20 > > 'array': {} } >=20 >=20 > In my patch, I used a _dictionary_ to describe this kind of thing > 1) dict, 2) list, 3) str >=20 > The above line is used for Dictionary or List, it should be: > 'array': ['DataObject'] >=20 > But I touched a new error: > qapi-visit.c: In function =E2=80=98visit_type_DataObject=E2=80=99: > qapi-visit.c:7255:29: error: implicit declaration of function =E2=80=98vi= sit_type_DataObjectList_fields=E2=80=99 [-Werror=3Dimplicit-function-declar= ation] > visit_type_DataObjectList_fields(m, &(*obj)-= >array, &err); >=20 > ---- > So I try to defined=20 >=20 > { 'type': 'DataObjectArray', 'data': ['DataObject'] } > 'DataObjectArrayType' } } >=20 > { 'union': 'DataObject', > 'base': 'DataObjectBase', > 'discriminator': 'name', > 'data': { > 'array': 'DataObjectArray', >=20 > got error: > Traceback (most recent call last): > File "/home/devel/qemu/scripts/qapi-types.py", line 471, in > ret +=3D generate_struct(expr) + "\n" > File "/home/devel/qemu/scripts/qapi-types.py", line 101, in generate_st= ruct > ret +=3D generate_struct_fields(members) > File "/home/devel/qemu/scripts/qapi-types.py", line 67, in generate_str= uct_fields > for argname, argentry, optional, structured in parse_args(members): > File "/home/devel/qemu/scripts/qapi.py", line 197, in parse_args > argentry =3D typeinfo[member] > TypeError: list indices must be integers, not str I've never had a need for unions inside an array so far, but that doesn't make them less useful. We'll need them in more places than just here. So instead of working around the current limitations, the right thing to do is to modify the QAPI generator to allow this kind of definitions. Kevin --/9DWx/yDrRhgMJTb Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) iQIcBAEBAgAGBQJSlcCGAAoJEH8JsnLIjy/W5y4P/1DzJSTHmL+N97Ayq/yhCHhK l6Bw932TPNBw7a5gMUm9Z9s/SreubFgZeaIbgxsNlEv6H5DTnaIOzWk5fLT0395V KBpUdHHxh/tVOD0AJp5mxi0GFoHz/kp1tMT092aZCPQtl/BSJdDP3Fx206wg51IA xsmpc3eloH18EzjIeAUButdwKBfYC4M4S+Sr7iAhdo3vbgpGt+ouCuoVrtXUwKMZ elZQ8wMxSFx3VqpEhNJx9iEXIgtaVE+wqy3VILv1EIjRDBxCj+3LQtxjDhbsRoG3 GWjIkwUsXx5ah9FsWuyB840QWj4S7ffZb6I4rhPui45u1XufTYQzpdyKfaC4mZh4 0Exv7DtynBSwFPZa/00aY14DPHPNdki5K0CPLHYL6eppj6tzNWUa4eRDU+LsE9Rz x6yirsHUoamoW1ITB8icUuZwfEmw6ErmELYLlTA+c3kwh4LkpvqilBZQlJd3eG+b IFx8e1CqCgW7TfJIFYzrDF7mop3/n6T4YEmEKTHFM9oRXiHzecF+nLAQwPtJXe6P D5FOltP3ld++wrcb+j/AlaEhHaClRjc3lDHpFwyDKzpEhozteOPJLFm3M40+k3ZI rFGxiCg3F1HbwuyuqsVpkNUPqOECk8Y6H6f2mdDstyflsE7XrLa5iQeodEXDO7T/ /cMTrFFZRyH26qb+1/qk =LNRW -----END PGP SIGNATURE----- --/9DWx/yDrRhgMJTb--