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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 30, 2010 at 11:26:47AM -0400, Stefan Berger wrote:
> A cosmetic change that makes the entries in the int-2-string maps look
> more readable. Add some missing entries.
> 
> Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
> 
> 
> ---
>  src/conf/nwfilter_conf.c |   97 +++++++++++++----------------------------------
>  1 file changed, 28 insertions(+), 69 deletions(-)
> 
> Index: libvirt-acl/src/conf/nwfilter_conf.c
> ===================================================================
> --- libvirt-acl.orig/src/conf/nwfilter_conf.c
> +++ libvirt-acl/src/conf/nwfilter_conf.c
> @@ -105,6 +105,9 @@ struct int_map {
>      const char *val;
>  };
>  
> +#define INTMAP_ENTRY(ATT, VAL) { .attr = ATT, .val = VAL }
> +#define INTMAP_ENTRY_LAST      { .val = NULL }
> +
>  
>  /*
>   * only one filter update allowed
> @@ -388,18 +391,10 @@ struct _virXMLAttr2Struct
>  
>  
>  static const struct int_map macProtoMap[] = {
> -    {
> -      .attr = ETHERTYPE_ARP,
> -      .val  = "arp",
> -    }, {
> -      .attr = ETHERTYPE_IP,
> -      .val  = "ipv4",
> -    }, {
> -      .attr = ETHERTYPE_IPV6,
> -      .val  = "ipv6",
> -    }, {
> -      .val  = NULL,
> -    }
> +    INTMAP_ENTRY(ETHERTYPE_ARP , "arp"),
> +    INTMAP_ENTRY(ETHERTYPE_IP  , "ipv4"),
> +    INTMAP_ENTRY(ETHERTYPE_IPV6, "ipv6"),
> +    INTMAP_ENTRY_LAST
>  };

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).

Regards,
Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]