qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors
Date: Tue, 21 Feb 2012 21:31:02 +0100	[thread overview]
Message-ID: <4F43FF06.5070306@suse.de> (raw)
In-Reply-To: <1328797918-1316-2-git-send-email-pbonzini@redhat.com>

Am 09.02.2012 15:31, schrieb Paolo Bonzini:
> Most visitors will use the same code for enum parsing.  Move it to
> the core.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Andreas Färber <afaerber@suse.de>

However...

> diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
> index ddef3ed..a4e088c 100644
> --- a/qapi/qapi-visit-core.c
> +++ b/qapi/qapi-visit-core.c

> @@ -116,3 +117,53 @@ void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
>          v->type_number(v, obj, name, errp);
>      }
>  }
> +
> +void output_type_enum(Visitor *v, int *obj, const char *strings[],
> +                      const char *kind, const char *name,
> +                      Error **errp)
> +{
> +    int i = 0;
> +    int value = *obj;
> +    char *enum_str;
> +
> +    assert(strings);
> +    while (strings[i++] != NULL);
> +    if (value < 0 || value >= i - 1) {
> +        error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
> +        return;
> +    }
> +
> +    enum_str = (char *)strings[value];

This does not take into account non-linear enum values.

Maybe name it output_type_linear_enum to allow for alternative enum
lookup implementations? (e.g., hashtable or list of name,value tuples)

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2012-02-21 20:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-09 14:31 [Qemu-devel] [PATCH 0/9] qdev deconstruction, command-line episode Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors Paolo Bonzini
2012-02-21 20:31   ` Andreas Färber [this message]
2012-02-22  7:30     ` Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 2/9] qapi: drop qmp_input_end_optional Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 3/9] qapi: add string-based visitors Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 4/9] qapi: add tests for " Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 5/9] qom: add generic string parsing/printing Paolo Bonzini
2012-02-21 20:47   ` Andreas Färber
2012-02-22  7:31     ` Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 6/9] qdev: accept both strings and integers for PCI addresses Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 7/9] qdev: accept hex properties only if prefixed by 0x Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 8/9] qdev: use built-in QOM string parser Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 9/9] qdev: drop unnecessary parse/print methods Paolo Bonzini
2012-02-21 17:13 ` [Qemu-devel] [PULL v2 0/9] qdev deconstruction, command-line episode Paolo Bonzini
2012-02-22 14:44   ` Anthony Liguori

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=4F43FF06.5070306@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@redhat.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).