qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v4 05/10] qapi: Utilize implicit struct visits
Date: Tue, 8 Mar 2016 09:11:55 -0700	[thread overview]
Message-ID: <56DEF9CB.6020601@redhat.com> (raw)
In-Reply-To: <87d1r580q0.fsf@blackfin.pond.sub.org>

[-- Attachment #1: Type: text/plain, Size: 3607 bytes --]

On 03/08/2016 08:10 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> Rather than generate inline per-member visits, take advantage
>> of the 'visit_type_FOO_members()' function for both event and
>> command marshalling.  This is possible now that implicit
>> structs can be visited like any other.
>>
>> Generated code shrinks accordingly; events initialize a struct
>> based on parameters, such as:
>>

>>
>> And command marshalling generates call arguments from a stack-allocated
>> struct:
> 
> I see qmp-marshal.c shrink from ~5700 lines to ~4300.  Neat!

Yeah, it nicely balances out the .h getting so much larger, except that
the .h gets parsed a lot more by the compiler.


>>
>> +# Declare and initialize an object 'qapi' using parameters from gen_params()
>> +def gen_struct_init(typ):
> 
> It's not just a "struct init", it's a variable declaration with an
> initializer.  gen_param_var()?
> 
> Name the variable param rather than qapi?

Sure, I'm not tied to a specific name.  I will point out that we have a
potential collision point - any local variable we create here can
collide with members of the QAPI struct passed to the event.  We haven't
hit the collision on any events we've created so far, and it's easy to
rename our local variables at such time if we do run into the collision
down the road, so I won't worry about it now.

> 
>> +    assert not typ.variants
>> +    ret = mcgen('''
>> +    %(c_name)s qapi = {
>> +''',
>> +                c_name=typ.c_name())
>> +    sep = '        '
>> +    for memb in typ.members:
>> +        ret += sep
>> +        sep = ', '
>> +        if memb.optional:
>> +            ret += 'has_' + c_name(memb.name) + sep
>> +        if memb.type.name == 'str':
>> +            # Cast away const added in gen_params()
>> +            ret += '(char *)'
> 
> Why is that useful?

The compiler complains if you try to initialize a 'char *' member of a
QAPI C struct with a 'const char *' parameter.  It's no different than
the fact that the gen_visit_members() call we are getting rid of also
has to cast away const.

> 
>> +        ret += c_name(memb.name)
>> +    ret += mcgen('''
>> +
>> +    };
>> +''')
>> +    return ret
> 
> Odd: you use this only in qapi-event.py, not in qapi-commands.py.
> Should it live in qapi-event.py then?

Yeah, I guess so.  I originally put it in qapi.py thinking that I could
reuse it in qapi-commands.py, then realized that the two are opposite
(event collects parameters into a struct, commands parses a QObject into
parameters), so I couldn't share it after all.


>> @@ -107,17 +96,24 @@ def gen_marshal_input_visit(arg_type, dealloc=False):
>>      qdv = qapi_dealloc_visitor_new();
>>      v = qapi_dealloc_get_visitor(qdv);
>>  ''')
>> +        errp = 'NULL'
>>      else:
>>          ret += mcgen('''
>>      v = qmp_input_get_visitor(qiv);
>>  ''')
>> +        errp = '&err'
>>
>> -    ret += gen_visit_members(arg_type.members, skiperr=dealloc)
> 
> Unless I'm mistaken, this is the only use of skiperr.  Follow up with a
> patch to drop the parameter and simplify?

Oh, nice.  I noticed some cleanups in patch 6/10, but missed this one as
a reasonable improvement.

In fact, gen_visit_members() is now only used in qapi-visits.py, so
maybe I can move it back there (it used to live there before commit
82ca8e469 moved it for sharing with the two files simplified here).


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2016-03-08 16:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-05 16:16 [Qemu-devel] [PATCH v4 00/10] easier unboxed visits/qapi implicit types Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 01/10] qapi: Assert in places where variants are not handled Eric Blake
2016-03-08 10:12   ` Markus Armbruster
2016-03-08 15:49     ` Eric Blake
2016-03-08 17:46       ` Markus Armbruster
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 02/10] qapi: Fix command with named empty argument type Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 03/10] qapi: Make c_type() more OO-like Eric Blake
2016-03-08 10:54   ` Markus Armbruster
2016-03-08 15:50     ` Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 04/10] qapi: Emit implicit structs in generated C Eric Blake
2016-03-08 14:24   ` Markus Armbruster
2016-03-08 16:03     ` Eric Blake
2016-03-08 19:09       ` Markus Armbruster
2016-03-09  5:42         ` Eric Blake
2016-03-09  7:23           ` Markus Armbruster
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 05/10] qapi: Utilize implicit struct visits Eric Blake
2016-03-08 15:10   ` Markus Armbruster
2016-03-08 16:11     ` Eric Blake [this message]
2016-03-08 18:09       ` Markus Armbruster
2016-03-08 18:28         ` Eric Blake
2016-03-08 19:21           ` Markus Armbruster
2016-03-09 23:28       ` Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 06/10] qapi-commands: Inline single-use helpers of gen_marshal() Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 07/10] qapi: Don't special-case simple union wrappers Eric Blake
2016-03-08 15:59   ` Markus Armbruster
2016-03-08 16:16     ` Eric Blake
2016-03-08 18:10       ` Markus Armbruster
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 08/10] qapi: Allow anonymous base for flat union Eric Blake
2016-03-08 16:23   ` Markus Armbruster
2016-03-08 16:29     ` Eric Blake
2016-03-08 18:14       ` Markus Armbruster
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 09/10] qapi: Use anonymous bases in QMP flat unions Eric Blake
2016-03-05 16:16 ` [Qemu-devel] [PATCH v4 10/10] qapi: Populate info['name'] for each entity Eric Blake
2016-03-08 16:46   ` Markus Armbruster
2016-03-08 16:59     ` Eric Blake
2016-03-08 19:14       ` Markus Armbruster

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=56DEF9CB.6020601@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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).