[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: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors |
Date: |
Wed, 22 Feb 2012 08:30:56 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120209 Thunderbird/10.0.1 |
On 02/21/2012 09:31 PM, Andreas Färber wrote:
>> > +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)
I would say that this is the common case and the other one should be
named output_type_sparse_enum or something like that, if the need arises...
Paolo
- [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
- [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
- [Qemu-devel] [PATCH 9/9] qdev: drop unnecessary parse/print methods, Paolo Bonzini, 2012/02/09