[libvirt] [PATCH] Allow hash tables to use generic pointers as keys

Eric Blake eblake at redhat.com
Tue Feb 22 23:16:50 UTC 2011


On 02/22/2011 10:54 AM, Daniel P. Berrange wrote:
> Relax the restriction that the hash table key must be a string
> by allowing an arbitrary hash code generator + comparison func
> to be provided
> 
> * util/hash.c, util/hash.h: Allow any pointer as a key
> * internal.h: Include stdbool.h as standard.
> * conf/domain_conf.c, conf/domain_conf.c,
>   conf/nwfilter_params.c, nwfilter/nwfilter_gentech_driver.c,
>   nwfilter/nwfilter_gentech_driver.h, nwfilter/nwfilter_learnipaddr.c,
>   qemu/qemu_command.c, qemu/qemu_driver.c,
>   qemu/qemu_process.c, uml/uml_driver.c,
>   xen/xm_internal.c: s/char */void */ in hash callbacks

> +++ b/src/internal.h
> @@ -8,6 +8,7 @@
>  # include <errno.h>
>  # include <limits.h>
>  # include <verify.h>
> +# include <stdbool.h>

Should we be scrubbing other files to remove includes rendered redundant
by including "internal.h"?

> +static bool virHashStrEqual(const void *namea, const void *nameb)
> +{
> +    return strcmp(namea, nameb) == 0 ? true : false;

cond == 0 ? true : false always looks like overkill to me (almost like
you were getting stumped by the 'make syntax-check' rules).  What's
wrong with:

return STREQ(namea, nameb);

> @@ -87,8 +110,9 @@ virHashComputeKey(virHashTablePtr table, const char *name)
>   *
>   * Returns the newly created object, or NULL if an error occured.
>   */
> -virHashTablePtr
> -virHashCreate(int size, virHashDeallocator deallocator)
> +virHashTablePtr virHashCreateFull(int size, virHashDeallocator deallocator,

Why the style change? I would have expected a newline between return
type and function name:

virHashTablePtr
virHashCreateFull(int size, ...

ACK with those nits addressed.

-- 
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: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110222/07044281/attachment-0001.sig>


More information about the libvir-list mailing list