Re: [RFC PATCH] hashmap API: introduce for_each_hashmap_entry() helper macro

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

 



Alexander Kuleshov <kuleshovmail@xxxxxxxxx> writes:

> diff --git a/hashmap.h b/hashmap.h
> index ab7958a..b8b158c 100644
> --- a/hashmap.h
> +++ b/hashmap.h
> @@ -95,4 +95,11 @@ static inline const char *strintern(const char *string)
>  	return memintern(string, strlen(string));
>  }
>  
> +#define for_each_hashmap_entry(map, type)		\
> +	struct type *entry;				\
> +	struct hashmap_iter iter;			\
> +							\
> +	hashmap_iter_init(map, &iter);			\
> +	while ((entry = hashmap_iter_next(&iter)))
> +

This is an easy way to introduce decl-after-statement, i.e. needs an
extra pair of {} around the thing.  It also forbids the callers from
defining "entry" and "iter" as their own identifier outside the
scope of this macro and use them inside the block that is iterated
over by shadowing these two variables.

Other than that, it looks like a good concept.  The syntax however
needs more thought because of the above two issues, I think.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]