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 25/28] qapi: Simplify visits of optional fields
Date: Thu, 12 Nov 2015 16:11:40 +0100	[thread overview]
Message-ID: <877flnjlqr.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <1447224690-9743-26-git-send-email-eblake@redhat.com> (Eric Blake's message of "Tue, 10 Nov 2015 23:51:27 -0700")

Eric Blake <eblake@redhat.com> writes:

> None of the visitor callbacks would set an error when testing
> if an optional field was present; make this part of the interface
> contract by eliminating the errp argument.  Then, for less code,
> reflect the determined boolean value back to the caller instead
> of making the caller read the boolean after the fact.
>
> The resulting generated code has a nice diff:
>
> |-    visit_optional(v, &has_fdset_id, "fdset-id", &err);
> |-    if (err) {
> |-        goto out;
> |-    }
> |-    if (has_fdset_id) {
> |+    if (visit_optional(v, &has_fdset_id, "fdset-id")) {
> |         visit_type_int(v, &fdset_id, "fdset-id", &err);
> |         if (err) {
> |             goto out;
> |         }
> |     }

Any particular reason not to do

        has_fdset_id = visit_optional(v, "fdset-id");
        if (has_fdset_id) {
            visit_type_int(v, &fdset_id, "fdset-id", &err);
            if (err) {
                goto out;
            }
        }

?

> Signed-off-by: Eric Blake <eblake@redhat.com>
>
> ---
> v11 (no v10): no change
> v9: no change
> v8: no change
> v7: rebase to no member.c_name()
> v6: rebase onto earlier testsuite and gen_err_check() improvements
> ---
>  include/qapi/visitor-impl.h |  5 ++---
>  include/qapi/visitor.h      | 10 ++++++++--
>  qapi/opts-visitor.c         |  2 +-
>  qapi/qapi-visit-core.c      |  6 +++---
>  qapi/qmp-input-visitor.c    |  3 +--
>  qapi/string-input-visitor.c |  3 +--
>  scripts/qapi.py             |  7 +------
>  7 files changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
> index ac6c17e..81d1aa0 100644
> --- a/include/qapi/visitor-impl.h
> +++ b/include/qapi/visitor-impl.h
> @@ -44,9 +44,8 @@ struct Visitor
>      void (*type_any)(Visitor *v, QObject **obj, const char *name,
>                       Error **errp);
>
> -    /* May be NULL */
> -    void (*optional)(Visitor *v, bool *present, const char *name,
> -                     Error **errp);
> +    /* May be NULL; most useful for input visitors. */
> +    void (*optional)(Visitor *v, bool *present, const char *name);
>
>      void (*type_uint8)(Visitor *v, uint8_t *obj, const char *name, Error **errp);
>      void (*type_uint16)(Visitor *v, uint16_t *obj, const char *name, Error **errp);
> diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
> index 250e8e1..dd4f0b3 100644
> --- a/include/qapi/visitor.h
> +++ b/include/qapi/visitor.h
> @@ -39,8 +39,14 @@ void visit_end_implicit_struct(Visitor *v, Error **errp);
>  void visit_start_list(Visitor *v, const char *name, Error **errp);
>  GenericList *visit_next_list(Visitor *v, GenericList **list, Error **errp);
>  void visit_end_list(Visitor *v, Error **errp);
> -void visit_optional(Visitor *v, bool *present, const char *name,
> -                    Error **errp);
> +
> +/**
> + * Check if an optional member @name of an object needs visiting.
> + * For input visitors, set *@present according to whether the
> + * corresponding visit_type_*() needs calling; for other visitors,
> + * leave *@present unchanged.  Return *@present for convenience.
> + */
> +bool visit_optional(Visitor *v, bool *present, const char *name);
>
>  /**
>   * Determine the qtype of the item @name in the current object visit.
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index cd10392..ef5fb8b 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -488,7 +488,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp)
>
>
>  static void
> -opts_optional(Visitor *v, bool *present, const char *name, Error **errp)
> +opts_optional(Visitor *v, bool *present, const char *name)
>  {
>      OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
>
> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index 52c132a..daaa3af 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c
> @@ -73,12 +73,12 @@ void visit_end_union(Visitor *v, bool data_present, Error **errp)
>      }
>  }
>
> -void visit_optional(Visitor *v, bool *present, const char *name,
> -                    Error **errp)
> +bool visit_optional(Visitor *v, bool *present, const char *name)
>  {
>      if (v->optional) {
> -        v->optional(v, present, name, errp);
> +        v->optional(v, present, name);
>      }
> +    return *present;
>  }

Slightly ugly: struct Visitor method optional returns void, but the
wrapper returns bool.

>
>  void visit_get_next_type(Visitor *v, QTypeCode *type, bool promote_int,
> diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
> index 4238faf..9f0ed69 100644
> --- a/qapi/qmp-input-visitor.c
> +++ b/qapi/qmp-input-visitor.c
> @@ -304,8 +304,7 @@ static void qmp_input_type_any(Visitor *v, QObject **obj, const char *name,
>      *obj = qobj;
>  }
>
> -static void qmp_input_optional(Visitor *v, bool *present, const char *name,
> -                               Error **errp)
> +static void qmp_input_optional(Visitor *v, bool *present, const char *name)
>  {
>      QmpInputVisitor *qiv = to_qiv(v);
>      QObject *qobj = qmp_input_get_object(qiv, name, true);
> diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
> index bbd6a54..dee780a 100644
> --- a/qapi/string-input-visitor.c
> +++ b/qapi/string-input-visitor.c
> @@ -299,8 +299,7 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
>      *obj = val;
>  }
>
> -static void parse_optional(Visitor *v, bool *present, const char *name,
> -                           Error **errp)
> +static void parse_optional(Visitor *v, bool *present, const char *name)
>  {
>      StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 1790e8f..b17f843 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -1656,15 +1656,10 @@ def gen_visit_fields(members, prefix='', need_cast=False, skiperr=False):
>      for memb in members:
>          if memb.optional:
>              ret += mcgen('''
> -    visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s", %(errp)s);
> +    if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s")) {
>  ''',
>                           prefix=prefix, c_name=c_name(memb.name),
>                           name=memb.name, errp=errparg)
> -            ret += gen_err_check(skiperr=skiperr)
> -            ret += mcgen('''
> -    if (%(prefix)shas_%(c_name)s) {
> -''',
> -                         prefix=prefix, c_name=c_name(memb.name))
>              push_indent()
>
>          # Ugly: sometimes we need to cast away const

  reply	other threads:[~2015-11-12 15:11 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-11  6:51 [Qemu-devel] [PATCH v11 00/28] qapi member collision, alternate layout (post-introspection cleanups, subset D) Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 01/28] qapi: Track simple union tag in object.local_members Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 02/28] qapi-types: Consolidate gen_struct() and gen_union() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 03/28] qapi-types: Simplify gen_struct_field[s] Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 04/28] qapi: Drop obsolete tag value collision assertions Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 05/28] qapi: Simplify QAPISchemaObjectTypeMember.check() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 06/28] qapi: Clean up after previous commit Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 07/28] qapi: Fix up commit 7618b91's clash sanity checking change Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 08/28] qapi: Eliminate QAPISchemaObjectType.check() variable members Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 09/28] qapi: Factor out QAPISchemaObjectTypeMember.check_clash() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 10/28] qapi: Simplify QAPISchemaObjectTypeVariants.check() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 11/28] qapi: Check for qapi collisions of flat union branches Eric Blake
2015-11-11 13:42   ` Markus Armbruster
2015-11-11 15:49     ` Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 12/28] qapi: Factor out QAPISchemaObjectType.check_clash() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 13/28] qapi: Hoist tag collision check to Variants.check() Eric Blake
2015-11-11 13:56   ` Markus Armbruster
2015-11-11 16:11     ` Eric Blake
2015-11-11 17:03       ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 14/28] qapi: Remove outdated tests related to QMP/branch collisions Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 15/28] qapi: Track owner of each object member Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 16/28] qapi: Detect collisions in C member names Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 17/28] cpu: Convert CpuInfo into flat union Eric Blake
2015-11-11 14:13   ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 18/28] qerror: more error_setg() usage Eric Blake
2015-11-11 13:26   ` Andreas Färber
2015-11-11 14:21   ` Markus Armbruster
2015-11-11 14:23     ` Andreas Färber
2015-11-11 15:51       ` Eric Blake
2015-11-11 16:19     ` Eric Blake
2015-11-11 17:31       ` Markus Armbruster
2015-11-11 17:44         ` Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 19/28] qapi: Change munging of CamelCase enum values Eric Blake
2015-11-11 13:29   ` Andreas Färber
2015-11-11 14:50   ` Markus Armbruster
2015-11-11 16:03     ` Eric Blake
2015-11-11 17:11       ` Markus Armbruster
2015-11-12  8:34         ` Gerd Hoffmann
2015-11-12 11:16           ` Markus Armbruster
2015-11-12  8:29       ` Gerd Hoffmann
2015-11-11 16:06     ` Eric Blake
2015-11-13 17:46   ` Eric Blake
2015-11-13 18:13     ` Markus Armbruster
2015-11-13 21:37       ` Eric Blake
2015-11-16 14:30         ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 20/28] qapi: Forbid case-insensitive clashes Eric Blake
2015-11-11 14:53   ` Markus Armbruster
2015-11-13  5:32     ` Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 21/28] qapi: Convert qtype_code into qapi enum type Eric Blake
2015-11-11 16:42   ` Markus Armbruster
2015-11-11 17:03     ` Eric Blake
2015-11-12 13:16       ` Markus Armbruster
2015-11-18  6:27         ` Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 22/28] qapi: Simplify visiting of alternate types Eric Blake
2015-11-12 14:21   ` Markus Armbruster
2015-11-12 15:54   ` Markus Armbruster
2015-11-13 23:54   ` Eric Blake
2015-11-16 14:31     ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 23/28] qapi: Fix alternates that accept 'number' but not 'int' Eric Blake
2015-11-12 15:01   ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 24/28] qapi: Add positive tests to qapi-schema-test Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 25/28] qapi: Simplify visits of optional fields Eric Blake
2015-11-12 15:11   ` Markus Armbruster [this message]
2015-11-12 15:30     ` Eric Blake
2015-11-12 16:20       ` Markus Armbruster
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 26/28] qapi: Move duplicate member checks to schema check() Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 27/28] qapi: Move duplicate enum value " Eric Blake
2015-11-12 15:46   ` Markus Armbruster
2015-11-12 16:08     ` Eric Blake
2015-11-18  6:48     ` Eric Blake
2015-11-11  6:51 ` [Qemu-devel] [PATCH v11 28/28] qapi: Detect base class loops Eric Blake
2015-11-12 16:06   ` 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=877flnjlqr.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.