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 05/15] qapi-visit: Simplify how we visit common union members
Date: Thu, 18 Feb 2016 13:16:46 +0100 [thread overview]
Message-ID: <87mvqygqmp.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1455778109-6278-6-git-send-email-eblake@redhat.com> (Eric Blake's message of "Wed, 17 Feb 2016 23:48:19 -0700")
Eric Blake <eblake@redhat.com> writes:
> From: Markus Armbruster <armbru@redhat.com>
>
> For a simple union SU, gen_visit_union() generates a visit of its
> single tag member, like this:
>
> visit_type_SUKind(v, "type", &(*obj)->type, &err);
>
> For a flat union FU with base B, it generates a visit of its base
> fields:
>
> visit_type_B_fields(v, (B **)obj, &err);
>
> Instead, we can simply visit the common members using the same fields
> visit function we use for structs, generated with
> gen_visit_struct_fields(). This function visits the base if any, then
> the local members.
>
> For a simple union SU, visit_type_SU_fields() contains exactly the old
> tag member visit, because there is no base, and the tag member is the
> only member. For instance, the code generated for qapi-schema.json's
> KeyValue changes like this:
>
> +static void visit_type_KeyValue_fields(Visitor *v, KeyValue **obj, Error **errp)
> +{
> + Error *err = NULL;
> +
> + visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
> + if (err) {
> + goto out;
> + }
> +
> +out:
> + error_propagate(errp, err);
> +}
> +
> void visit_type_KeyValue(Visitor *v, const char *name, KeyValue **obj, Error **errp)
> {
> Error *err = NULL;
> @@ -4863,7 +4911,7 @@ void visit_type_KeyValue(Visitor *v, con
> if (!*obj) {
> goto out_obj;
> }
> - visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
> + visit_type_KeyValue_fields(v, obj, &err);
> if (err) {
> goto out_obj;
> }
>
> For a flat union FU, visit_type_FU_fields() contains exactly the old
> base fields visit, because there is a base, but no members. For
> instance, the code generated for qapi-schema.json's CpuInfo changes
> like this:
>
> static void visit_type_CpuInfoBase_fields(Visitor *v, CpuInfoBase **obj, Error **errp);
>
> +static void visit_type_CpuInfo_fields(Visitor *v, CpuInfo **obj, Error **errp)
> +{
> + Error *err = NULL;
> +
> + visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
> + if (err) {
> + goto out;
> + }
> +
> +out:
> + error_propagate(errp, err);
> +}
> +
> static void visit_type_CpuInfoX86_fields(Visitor *v, CpuInfoX86 **obj, Error **errp)
> ...
> @@ -3485,7 +3509,7 @@ void visit_type_CpuInfo(Visitor *v, cons
> if (!*obj) {
> goto out_obj;
> }
> - visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
> + visit_type_CpuInfo_fields(v, obj, &err);
> if (err) {
> goto out_obj;
> }
>
> As you see, the generated code grows a bit, but in practice, it's lost
> in the noise: qapi-schema.json's qapi-visit.c gains roughly 1%.
>
> This simplification became possible with commit 441cbac "qapi-visit:
> Convert to QAPISchemaVisitor, fixing bugs". It's a step towards
> unifying gen_struct() and gen_union().
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Message-Id: <1453902888-20457-2-git-send-email-armbru@redhat.com>
> [rebase, improve commit message example]
> Signed-off-by: Eric Blake <eblake@redhat.com>
v10 had a noteworthy rebase, but v11 is the original patch again, with
only the line numbers shifted a bit. Suggest to drop "rebase, ".
next prev parent reply other threads:[~2016-02-18 12:16 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 [this message]
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
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=87mvqygqmp.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 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).