From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScQYD-0003nm-MP for qemu-devel@nongnu.org; Wed, 06 Jun 2012 20:26:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ScQYB-0004Xh-I9 for qemu-devel@nongnu.org; Wed, 06 Jun 2012 20:26:09 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:44683) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScQYB-0004Tj-8v for qemu-devel@nongnu.org; Wed, 06 Jun 2012 20:26:07 -0400 Received: by obbwd20 with SMTP id wd20so82682obb.4 for ; Wed, 06 Jun 2012 17:26:05 -0700 (PDT) Sender: fluxion Date: Wed, 6 Jun 2012 19:26:00 -0500 From: Michael Roth Message-ID: <20120607002600.GF7733@illuin> References: <1338591268-23962-1-git-send-email-akong@redhat.com> <1338591268-23962-6-git-send-email-akong@redhat.com> <20120606154037.48405791@doriath.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120606154037.48405791@doriath.home> Subject: Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: Paolo Bonzini , aliguori@us.ibm.com, Amos Kong , eblake@redhat.com, qemu-devel@nongnu.org On Wed, Jun 06, 2012 at 03:40:37PM -0300, Luiz Capitulino wrote: > On Sat, 2 Jun 2012 06:54:27 +0800 > Amos Kong wrote: > > > Currently, if define an 'enum' and use it in one command's data, > > List struct for enum could not be generated, but it's used in > > qmp function. > > > > For example: KeyCodesList could not be generated. > > >>> qapi-schema.json: > > { 'enum': 'KeyCodes', > > 'data': [ 'shift', 'alt' ... ] } > > { 'command': 'sendkey', > > 'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } } > > > > >>> qmp-command.h: > > void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t > > hold_time, Error **errp); > > > > This patch makes qapi can generate List struct for enum. > > This patch does it the simple way, just like any type. It generates a enum list > type and the functions qapi_free_yourenum() and qapi_free_yourenumlist(). Had a couple suggestions, but approach/patch seems reasonable to me. > > The qapi_free_yourenum() list ends up doing nothing, so it could be a good > idea to generate an empty body (also note that we're copying the argument's > value, this could bite us in the future). I think we can omit qapi_free_yourenum() completely. Humans will know not to free non-allocated types, and the generated marshallers don't use these interfaces. > > Another point I was wondering is that, all enums will end up having the > exact same code. So maybe we could generate a default int list and use it > for all enums. Not sure it's worth it though. Since it's generated code I don't think it's worth it, personally. > > Michael, Paolo, ideas? > > More review comments below. > > > > > > Signed-off-by: Amos Kong > > --- > > scripts/qapi-types.py | 33 +++++++++++++++++++++++++++++---- > > scripts/qapi-visit.py | 14 +++++++++----- > > 2 files changed, 38 insertions(+), 9 deletions(-) > > > > diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py > > index 4a734f5..c9641fb 100644 > > --- a/scripts/qapi-types.py > > +++ b/scripts/qapi-types.py > > @@ -16,17 +16,36 @@ import os > > import getopt > > import errno > > > > -def generate_fwd_struct(name, members): > > - return mcgen(''' > > +def generate_fwd_struct(name, members, enum=False): > > I think it's better to have generate_fwd_enum_struct(). > > > + ret = "" > > + if not enum: > > + ret += mcgen(''' > > typedef struct %(name)s %(name)s; > > > > +''', > > + name=name) > > + ret += mcgen(''' > > typedef struct %(name)sList > > { > > - %(name)s *value; > > +''', > > + name=name) > > + if enum: > > + ret += mcgen(''' > > + %(name)s value; > > +''', > > + name=name) > > + else: > > + ret += mcgen(''' > > + %(name)s * value; > > +''', > > + name=name) > > + > > + ret += mcgen(''' > > struct %(name)sList *next; > > } %(name)sList; > > ''', > > name=name) > > + return ret > > > > def generate_struct(structname, fieldname, members): > > ret = mcgen(''' > > @@ -265,7 +284,8 @@ for expr in exprs: > > if expr.has_key('type'): > > ret += generate_fwd_struct(expr['type'], expr['data']) > > elif expr.has_key('enum'): > > - ret += generate_enum(expr['enum'], expr['data']) > > + ret += generate_enum(expr['enum'], expr['data']) + "\n" > > The new-line should be returned by generate_enum(). Same applies for the > occurrences below. > > > + ret += generate_fwd_struct(expr['enum'], expr['data'], True) > > fdef.write(generate_enum_lookup(expr['enum'], expr['data'])) > > elif expr.has_key('union'): > > ret += generate_fwd_struct(expr['union'], expr['data']) + "\n" > > @@ -289,6 +309,11 @@ for expr in exprs: > > fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n") > > ret += generate_type_cleanup_decl(expr['union']) > > fdef.write(generate_type_cleanup(expr['union']) + "\n") > > + elif expr.has_key('enum'): > > + ret += generate_type_cleanup_decl(expr['enum'] + "List") > > + fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n") > > + ret += generate_type_cleanup_decl(expr['enum']) > > + fdef.write(generate_type_cleanup(expr['enum']) + "\n") > > else: > > continue > > fdecl.write(ret) > > diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py > > index 8d4e94a..e44edfa 100644 > > --- a/scripts/qapi-visit.py > > +++ b/scripts/qapi-visit.py > > @@ -81,7 +81,7 @@ end: > > ''') > > return ret > > > > -def generate_visit_list(name, members): > > +def generate_visit_list(name, members, enum=False): > > return mcgen(''' > > > > void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp) > > @@ -160,12 +160,14 @@ end: > > > > return ret > > > > -def generate_declaration(name, members, genlist=True): > > - ret = mcgen(''' > > +def generate_declaration(name, members, genlist=True, enum=False): > > + ret = "" > > + if not enum: > > + ret = mcgen(''' > > > > void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp); > > ''', > > - name=name) > > + name=name) > > Why this change? > > > > > if genlist: > > ret += mcgen(''' > > @@ -293,10 +295,12 @@ for expr in exprs: > > ret += generate_declaration(expr['union'], expr['data']) > > fdecl.write(ret) > > elif expr.has_key('enum'): > > - ret = generate_visit_enum(expr['enum'], expr['data']) > > + ret = generate_visit_list(expr['enum'], expr['data'], True) > > + ret += generate_visit_enum(expr['enum'], expr['data']) > > fdef.write(ret) > > > > ret = generate_decl_enum(expr['enum'], expr['data']) > > + ret += generate_declaration(expr['enum'], expr['data'], enum=True) > > fdecl.write(ret) > > > > fdecl.write(''' > >