[libvirt] [PATCH] nwfilter: Make entries in a int-2-string map more readable

Eric Blake eblake at redhat.com
Tue Mar 30 21:39:03 UTC 2010

On 03/30/2010 09:55 AM, Daniel P. Berrange wrote:
>> +    INTMAP_ENTRY(ETHERTYPE_IP  , "ipv4"),
>>  };
> This should all really be replaced with a standard call to VIR_ENUM_DECL + 
> VIR_ENUM_IMPL which do compile time validation that you have the correct
> number of strings to match the enum, and allow O(1) int to string conversion,
> though string to int is still O(n).

If I understand util.h right, those macros only work for enumerators
that are consecutive and which start at 0.  But Stefan is mapping
external constants, with no guarantee that they are consecutive nor that
they start at 0.  The only way to use VIR_ENUM_DECL is to write our own
wrapper enums, naming them something like VIR_ETHERTYPE_ARP; but I don't
see what it would buy us, because then we would have to convert from our
wrapper to the known external constants.

Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 323 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100330/063419dd/attachment-0001.sig>

More information about the libvir-list mailing list