qemu-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]