From: Luiz Capitulino <lcapitulino@redhat.com>
To: Amos Kong <akong@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
aliguori@us.ibm.com, eblake@redhat.com,
Michael Roth <mdroth@linux.vnet.ibm.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum
Date: Mon, 11 Jun 2012 14:00:11 -0300 [thread overview]
Message-ID: <20120611140011.48c0e682@doriath.home> (raw)
In-Reply-To: <4FD0177E.2040505@redhat.com>
On Thu, 07 Jun 2012 10:52:46 +0800
Amos Kong <akong@redhat.com> wrote:
> On 07/06/12 08:26, Michael Roth wrote:
> > On Wed, Jun 06, 2012 at 03:40:37PM -0300, Luiz Capitulino wrote:
> >> On Sat, 2 Jun 2012 06:54:27 +0800
> >> Amos Kong<akong@redhat.com> 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.
>
>
> Thanks for your review!
>
> >>> Signed-off-by: Amos Kong<akong@redhat.com>
> >>> ---
> >>> 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().
>
> I tried this before, too many duplicate codes would be introduced,
> but it's more clear.
You could try to move the duplicated code to a third function (or move
the specific bits to generate_fwd_enum_struct() and generate_enum_declaration()).
>
> two functions need to be added
> qapi-types.py: def generate_fwd_enum_struct(name, members):
> qapi-visit.py: def generate_enum_declaration(name, members,
> genlist=True):
>
> >>> + 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.
>
>
> "\n" is used to add a blank line here.
>
> >>> + 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?
>
>
> Indent of above "mcgen(" changes, make them aligned.
>
> >>>
> >>> 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('''
> >>
> >>
>
next prev parent reply other threads:[~2012-06-11 18:03 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 22:54 [Qemu-devel] [PATCH v2 0/6] convert sendkey to qapi Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 1/6] qerror: add QERR_OVERFLOW Amos Kong
2012-06-04 5:27 ` Anthony Liguori
2012-06-05 14:29 ` [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16 Amos Kong
[not found] ` <4FD0326F.3010806@redhat.com>
[not found] ` <20120611140642.06be2ee8@doriath.home>
[not found] ` <4FD62827.4060900@us.ibm.com>
[not found] ` <20120611142546.66871522@doriath.home>
2012-06-14 10:20 ` Amos Kong
2012-06-15 7:46 ` Amos Kong
2012-06-15 7:57 ` Gerd Hoffmann
2012-06-15 13:35 ` Luiz Capitulino
2012-06-18 15:30 ` Amos Kong
2012-06-19 9:52 ` Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 2/6] fix doc of using raw values with sendkey Amos Kong
2012-06-06 18:16 ` Luiz Capitulino
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 3/6] rename keyname '<' to 'less' Amos Kong
2012-06-06 18:22 ` Luiz Capitulino
2012-06-06 23:12 ` Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 4/6] hmp: rename arguments Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum Amos Kong
2012-06-05 15:01 ` Amos Kong
2012-06-06 18:40 ` Luiz Capitulino
2012-06-07 0:26 ` Michael Roth
2012-06-07 2:52 ` Amos Kong
2012-06-11 17:00 ` Luiz Capitulino [this message]
2012-06-07 0:15 ` Michael Roth
2012-06-07 3:33 ` Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey Amos Kong
2012-06-04 17:09 ` Eric Blake
2012-06-05 14:55 ` Amos Kong
2012-06-05 15:05 ` Eric Blake
2012-06-06 7:13 ` Amos Kong
2012-06-06 11:58 ` Eric Blake
2012-06-07 4:51 ` Anthony Liguori
2012-06-07 13:08 ` Eric Blake
2012-06-01 23:03 ` [Qemu-devel] [PATCH v2 0/6] convert sendkey to qapi Amos Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120611140011.48c0e682@doriath.home \
--to=lcapitulino@redhat.com \
--cc=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).