[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation acr
From: |
Andreas Färber |
Subject: |
Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors |
Date: |
Tue, 21 Feb 2012 21:31:02 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1 |
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 <address@hidden>
Reviewed-by: Andreas Färber <address@hidden>
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
- [Qemu-devel] [PATCH 0/9] qdev deconstruction, command-line episode, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors, Paolo Bonzini, 2012/02/09
- Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors,
Andreas Färber <=
- [Qemu-devel] [PATCH 2/9] qapi: drop qmp_input_end_optional, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 3/9] qapi: add string-based visitors, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 6/9] qdev: accept both strings and integers for PCI addresses, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 4/9] qapi: add tests for string-based visitors, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 7/9] qdev: accept hex properties only if prefixed by 0x, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 8/9] qdev: use built-in QOM string parser, Paolo Bonzini, 2012/02/09
- [Qemu-devel] [PATCH 5/9] qom: add generic string parsing/printing, Paolo Bonzini, 2012/02/09