All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v11 12/15] qapi: Don't box struct branch of alternate
Date: Thu, 18 Feb 2016 17:43:45 +0100	[thread overview]
Message-ID: <874md69dfi.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1455778109-6278-13-git-send-email-eblake@redhat.com> (Eric Blake's message of "Wed, 17 Feb 2016 23:48:26 -0700")

Eric Blake <eblake@redhat.com> writes:

> There's no reason to do two malloc's for an alternate type visiting
> a QAPI struct; let's just inline the struct directly as the C union
> branch of the struct.
>
> Surprisingly, no clients were actually using the struct member prior
> to this patch outside of the testsuite; an earlier patch in the series
> added some testsuite coverage to make the effect of this patch more
> obvious.
>
> In qapi.py, c_type() gains a new is_unboxed flag to control when we
> are emitting a C struct unboxed within the context of an outer
> struct (different from our other two modes of usage with no flags
> for normal local variable declarations, and with is_param for adding
> 'const' in a parameter list).  I don't know if there is any more
> pythonic way of collapsing the two flags into a single parameter,
> as we never have a caller setting both flags at once.
>
> Ultimately, we want to also unbox branches for QAPI unions, but as
> that touches a lot more client code, it is better as separate
> patches.  But since unions and alternates share gen_variants(), I
> had to hack in a way to test if we are visiting an alternate type
> for setting the is_unboxed flag: look for a non-object branch.
> This works because alternates have at least two branches, with at
> most one object branch, while unions have only object branches.
> The hack will go away in a later patch.
>
> The generated code difference to qapi-types.h is relatively small:
>
> | struct BlockdevRef {
> |     QType type;
> |     union { /* union tag is @type */
> |         void *data;
> |-        BlockdevOptions *definition;
> |+        BlockdevOptions definition;
> |         char *reference;
> |     } u;
> | };
>
> meanwhile, in qapi-visit.h, we trade the previous visit_type_FOO(obj)

Meanwhile

> (which allocates a pointer, handles a layer of {} from the JSON stream,
> and visits the fields) with an inline call to visit_type_FOO(NULL) (to
> consume the {} without allocation) and a direct visit of the fields:

I don't see a call to visit_type_FOO(NULL).

Suggest not to abbreviate argument lists, it's mildly confusing.

>
> |     switch ((*obj)->type) {
> |     case QTYPE_QDICT:
> |-        visit_type_BlockdevOptions(v, name, &(*obj)->u.definition, &err);
> |+        visit_start_struct(v, name, NULL, 0, &err);
> |+        if (err) {
> |+            break;
> |+        }
> |+        visit_type_BlockdevOptions_fields(v, &(*obj)->u.definition, &err);
> |+        error_propagate(errp, err);
> |+        err = NULL;
> |+        visit_end_struct(v, &err);
> |         break;
> |     case QTYPE_QSTRING:
> |         visit_type_str(v, name, &(*obj)->u.reference, &err);
>
> The visit of non-object fields is unchanged.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>

Patch looks good.

  reply	other threads:[~2016-02-18 16:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18  6:48 [Qemu-devel] [PATCH v11 00/15] prune some QAPI visitor cruft (was qapi cleanups subset E) Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 01/15] qapi: Simplify excess input reporting in input visitors Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 02/15] qapi: Forbid empty unions and useless alternates Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 03/15] qapi: Forbid 'any' inside an alternate Eric Blake
2016-02-18 12:05   ` Markus Armbruster
2016-02-18 14:40     ` Eric Blake
2016-02-18 17:03       ` Markus Armbruster
2016-02-18 20:11         ` Eric Blake
2016-02-19  8:32           ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 04/15] qapi: Add tests of complex objects within alternate Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 05/15] qapi-visit: Simplify how we visit common union members Eric Blake
2016-02-18 12:16   ` Markus Armbruster
2016-02-18 14:40     ` Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 06/15] qapi: Visit variants in visit_type_FOO_fields() Eric Blake
2016-02-18 13:58   ` Markus Armbruster
2016-02-18 14:43     ` Eric Blake
2016-02-18 17:04       ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 07/15] qapi-visit: Unify struct and union visit Eric Blake
2016-02-18 14:05   ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 08/15] qapi-visit: Less indirection in visit_type_Foo_fields() Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 09/15] qapi: Adjust layout of FooList types Eric Blake
2016-02-18 15:55   ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 10/15] qapi: Emit structs used as variants in topological order Eric Blake
2016-02-18 14:35   ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 11/15] qapi-visit: Use common idiom in gen_visit_fields_decl() Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 12/15] qapi: Don't box struct branch of alternate Eric Blake
2016-02-18 16:43   ` Markus Armbruster [this message]
2016-02-18 16:56     ` Eric Blake
2016-02-18 18:56       ` Markus Armbruster
2016-02-18 20:00         ` Eric Blake
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 13/15] qapi: Don't box branches of flat unions Eric Blake
2016-02-18 16:51   ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 14/15] qapi: Delete visit_start_union(), gen_visit_implicit_struct() Eric Blake
2016-02-18 16:52   ` Markus Armbruster
2016-02-18 17:00     ` Eric Blake
2016-02-18 17:12       ` Markus Armbruster
2016-02-18  6:48 ` [Qemu-devel] [PATCH v11 15/15] qapi: Change visit_start_implicit_struct to visit_start_alternate Eric Blake
2016-02-18 10:09 ` [Qemu-devel] [PATCH v11 00/15] prune some QAPI visitor cruft (was qapi cleanups subset E) Markus Armbruster
2016-02-18 14:44   ` Eric Blake
2016-02-18 20:08 ` Markus Armbruster
2016-02-18 20:24   ` Eric Blake

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=874md69dfi.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.