From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UT3q4-00027J-CI for qemu-devel@nongnu.org; Fri, 19 Apr 2013 01:26:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UT3q2-0005b4-AW for qemu-devel@nongnu.org; Fri, 19 Apr 2013 01:26:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UT3q2-0005aF-1e for qemu-devel@nongnu.org; Fri, 19 Apr 2013 01:26:22 -0400 Date: Fri, 19 Apr 2013 13:26:12 +0800 From: Amos Kong Message-ID: <20130419052612.GA10011@t430s.nay.redhat.com> References: <8738urblx3.fsf@fimbulvetr.bsc.es> <20130416084919.GG6308@stefanha-thinkpad.redhat.com> <20130416145017.GA1599@vm> <20130417083303.GA3856@t430s.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20130417083303.GA3856@t430s.nay.redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [RFC PATCH] qapi: introduce strList and visit_type_strList() (was Re: [qapi] Cannot use list of strings) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mdroth Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , Anthony Liguori , =?iso-8859-1?Q?Llu=EDs?= Vilanova , Luiz Capitulino On Wed, Apr 17, 2013 at 04:33:03PM +0800, Amos Kong wrote: > On Tue, Apr 16, 2013 at 09:50:17AM -0500, mdroth wrote: > > On Tue, Apr 16, 2013 at 10:49:19AM +0200, Stefan Hajnoczi wrote: > > > On Mon, Apr 15, 2013 at 10:04:24PM +0200, Llu=C3=ADs Vilanova wrote= : > > > > Tried using a list of strings as an argument to a command, but th= e generated > > > > code references the 'strList' type, which does not exist. > > > >=20 > > > > Is a specialized version for "['str']" missing, or should I defin= e my own type > > > > with a single field of 'str' type? > >=20 > > I would say just give that a shot. Stick: > >=20 > > typedef struct strList > > { > > char *value; > > struct strList *next; > > } strList; > >=20 > > in include/qapi/visitor.h and see what happens. >=20 > Hi Michael, >=20 > | In file included from /home/devel/qemu/include/qapi/error.h:16, > | from /home/devel/qemu/include/qapi/visitor.h:16, > | from /home/devel/qemu/include/qapi/dealloc-visitor.h= :17, > | from qapi-types.c:17: > | ./qapi-types.h:2158: error: expected specifier-qualifier-list before = =E2=80=98strList=E2=80=99 > | make: *** [qapi-types.o] Error 1 >=20 >=20 > ("->" means "is include to") > qapi-types.h -> include/qapi/error.h -> include/qapi/visitor.h >=20 > 'strList' is used in qapi-types.h, we should not declare strList in > include/qapi/visitor.h. I changed scripts/qapi-types.py to declare > strList in qapi-types.h, but got a redefinition error. >=20 > | In file included from qga/qapi-generated/qga-qmp-commands.h:19, > | from qga/commands.c:15: > | qga/qapi-generated/qga-qapi-types.h:23: error: redefinition of =E2=80= =98struct strList=E2=80=99 > | qga/qapi-generated/qga-qapi-types.h:26: error: conflicting types for = =E2=80=98strList=E2=80=99 > | ./qapi-types.h:26: note: previous declaration of =E2=80=98strList=E2=80= =99 was here > | make: *** [qga/commands.o] Error 1 >=20 >=20 > I used an _ugly_ "#ifndef" to limit it only be defined in qapi-types.h. > Michael, others do you have some suggestion? =20 >>From ecbd69a8ad4b5e600ac56b1cda4c4c04e0175742 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Thu, 18 Apr 2013 10:56:24 +0800 Subject: [RFC PATCH] qapi: introduce strList and visit_type_strList() Currently we can only use ['String'] to add string to a list, it contains some additional JSON structure. "multicast": [ { "str": "01:80:c2:00:00:21" }, { "str": "00:00:00:00:00:00" } ] This patch introdued strList, we can use ['str'] "multicast": [ "01:00:5e:00:00:01", "33:33:ff:12:34:57" ] Signed-off-by: Amos Kong --- I used an _ugly_ "#ifndef" to limit it only be defined in qapi-types.h. Michael, others do you have some suggestion? --- include/qapi/visitor.h | 1 + qapi/qapi-visit-core.c | 22 ++++++++++++++++++++++ scripts/qapi-types.py | 8 ++++++++ 3 files changed, 31 insertions(+), 0 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 1fef18c..2e36edb 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -50,6 +50,7 @@ void visit_type_int64(Visitor *v, int64_t *obj, const c= har *name, Error **errp); void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error = **errp); void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **er= rp); void visit_type_str(Visitor *v, char **obj, const char *name, Error **er= rp); +void visit_type_strList(Visitor *m, strList ** obj, const char *name, Er= ror **errp); void visit_type_number(Visitor *v, double *obj, const char *name, Error = **errp); =20 #endif diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 401ee6e..aefe227 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -257,6 +257,28 @@ void visit_type_str(Visitor *v, char **obj, const ch= ar *name, Error **errp) } } =20 +void visit_type_strList(Visitor *m, strList ** obj, const char *name, Er= ror **errp) +{ + GenericList *i, **prev =3D (GenericList **)obj; + Error *err =3D NULL; + + if (!error_is_set(errp)) { + visit_start_list(m, name, &err); + if (!err) { + for (; (i =3D visit_next_list(m, prev, &err)) !=3D NULL; pre= v =3D &i) { + strList *native_i =3D (strList *)i; + visit_type_str(m, &native_i->value, NULL, &err); + } + error_propagate(errp, err); + err =3D NULL; + + /* Always call end_list if start_list succeeded. */ + visit_end_list(m, &err); + } + error_propagate(errp, err); + } +} + void visit_type_number(Visitor *v, double *obj, const char *name, Error = **errp) { if (!error_is_set(errp)) { diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 9e19920..f2ca373 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -276,6 +276,14 @@ fdecl.write(mcgen(''' #include #include =20 +#ifndef QGA_QAPI_TYPES_H +typedef struct strList +{ + char *value; + struct strList *next; +} strList; +#endif + ''', guard=3Dguardname(h_file))) =20 --=20 1.7.1