qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/3] qapi: Add enum_table[] parameter to start_alternate
Date: Fri, 5 May 2017 15:45:01 -0500	[thread overview]
Message-ID: <9f623263-e78c-fbb3-5ac4-5629d68c4bbc@redhat.com> (raw)
In-Reply-To: <20170505201128.12099-3-ehabkost@redhat.com>

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

On 05/05/2017 03:11 PM, Eduardo Habkost wrote:
> The new parameter will be used by the string input visitor to detect
> alternate types that can't be parsed unambiguously.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * (new patch added to series)
> ---

> +++ b/include/qapi/visitor.h
> @@ -411,13 +411,21 @@ void visit_end_list(Visitor *v, void **list);
>   * @supported_qtypes is a bit mask indicating which QTypes are supported
>   * by the alternate.
>   *
> + * @enum_table contains the enum value lookup table, in case
> + * strings in the input are going to be parsed as enums. Visitors
> + * aren't required to validate string input according to
> + * enum_table, as visit_type_enum() will be called automatically
> + * if (*obj)->type is QTYPE_QSTRING.

Presumably, enum_table will be NULL if the alternate type does not
include an enum?  [reads ahead] yes. Should be documented.

I'm less convinced we need this patch, if we can instead guarantee at
QAPI-generation time that alternates are not possible if they would
cause an ambiguity.


> +++ b/scripts/qapi-visit.py
> @@ -166,6 +166,12 @@ def gen_visit_alternate(name, variants):
>      supported_qtypes = ' | '.join(qtypes)
>      ret = ''
>  
> +    enum_table = 'NULL'
> +    for var in variants.variants:
> +        if isinstance(var.type, QAPISchemaEnumType):
> +            enum_table = '%s_lookup' % (var.type.c_name())
> +            break
> +
>      ret += mcgen('''
>  
>  void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp)
> @@ -174,7 +180,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error
>      uint32_t supported_qtypes = %(supported_qtypes)s;
>  
>      visit_start_alternate(v, name, (GenericAlternate **)obj, sizeof(**obj),
> -                          supported_qtypes, &err);
> +                          supported_qtypes, %(enum_table)s, &err);

So there's where you populate the enum through.

I'll have to see where 3/3 goes before deciding if this is worth having.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


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

  reply	other threads:[~2017-05-05 20:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-05 20:11 [Qemu-devel] [PATCH v2 0/3] string-input-visitor: Support enum/bool alternate types Eduardo Habkost
2017-05-05 20:11 ` [Qemu-devel] [PATCH v2 1/3] visitor: Add 'supported_qtypes' parameter to visit_start_alternate() Eduardo Habkost
2017-05-05 20:26   ` Eric Blake
2017-05-10 13:16   ` Markus Armbruster
2017-05-10 21:10     ` Eduardo Habkost
2017-05-11  7:04       ` Markus Armbruster
2017-05-05 20:11 ` [Qemu-devel] [PATCH v2 2/3] qapi: Add enum_table[] parameter to start_alternate Eduardo Habkost
2017-05-05 20:45   ` Eric Blake [this message]
2017-05-05 20:51     ` Eduardo Habkost
2017-05-10 13:34   ` Markus Armbruster
2017-05-10 13:38     ` Eduardo Habkost
2017-05-05 20:11 ` [Qemu-devel] [PATCH v2 3/3] string-input-visitor: Support alternate types Eduardo Habkost
2017-05-05 20:53   ` Eric Blake
2017-05-05 21:09     ` Eduardo Habkost
2017-05-10 13:45       ` Markus Armbruster
2017-05-10 13:43   ` Markus Armbruster
2017-05-05 20:42 ` [Qemu-devel] [PATCH v2 0/3] string-input-visitor: Support enum/bool " no-reply

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=9f623263-e78c-fbb3-5ac4-5629d68c4bbc@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@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).