[ovs-dev] [PATCH 4/7] shash: New function shash_steal().

Justin Pettit jpettit at nicira.com
Thu Sep 23 06:17:27 UTC 2010


Interesting.  I'm tingly with anticipation with how you will use this...

--Justin


On Sep 22, 2010, at 4:45 PM, Ben Pfaff wrote:

> ---
> lib/shash.c |   15 ++++++++++++++-
> lib/shash.h |    1 +
> 2 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/shash.c b/lib/shash.c
> index 8fd2eb1..cc45efb 100644
> --- a/lib/shash.c
> +++ b/lib/shash.c
> @@ -167,12 +167,25 @@ shash_replace(struct shash *sh, const char *name, const void *data)
>     }
> }
> 
> +/* Deletes 'node' from 'sh' and frees the node's name.  The caller is still
> + * responsible for freeing the node's data, if necessary. */
> void
> shash_delete(struct shash *sh, struct shash_node *node)
> {
> +    free(shash_steal(sh, node));
> +}
> +
> +/* Deletes 'node' from 'sh'.  Neither the node's name nor its data is freed;
> + * instead, ownership is transferred to the caller.  Returns the node's
> + * name. */
> +char *
> +shash_steal(struct shash *sh, struct shash_node *node)
> +{
> +    char *name = node->name;
> +
>     hmap_remove(&sh->map, &node->node);
> -    free(node->name);
>     free(node);
> +    return name;
> }
> 
> static struct shash_node *
> diff --git a/lib/shash.h b/lib/shash.h
> index eab0af4..8a736e8 100644
> --- a/lib/shash.h
> +++ b/lib/shash.h
> @@ -57,6 +57,7 @@ bool shash_add_once(struct shash *, const char *, const void *);
> void shash_add_assert(struct shash *, const char *, const void *);
> void *shash_replace(struct shash *, const char *, const void *data);
> void shash_delete(struct shash *, struct shash_node *);
> +char *shash_steal(struct shash *, struct shash_node *);
> struct shash_node *shash_find(const struct shash *, const char *);
> void *shash_find_data(const struct shash *, const char *);
> void *shash_find_and_delete(struct shash *, const char *);
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org





More information about the dev mailing list