hashmap: fix iterators to not skip entries

Currently, the HASHMAP iterators stop at the first NULL entry in a
hashmap. This is non-obvious and breaks users like sd-device, which
legitimately store NULL values in a hashmap.

Fix all the iterators by taking a pointer to the value storage, instead of
returning it. The iterators now return a boolean that tells whether the
end of the list was reached.

Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check
for NULL. If it turns out, there were users that inserted NULL into
hashmaps, but didn't properly check for it during iteration, then we
really want to find those and fix them.
This commit is contained in:
David Herrmann
2015-06-14 16:56:02 +02:00
parent aa75494ad5
commit 8927b1dad2
9 changed files with 56 additions and 41 deletions
+3 -3
View File
@@ -47,12 +47,12 @@ static inline bool ordered_set_isempty(OrderedSet *s) {
return ordered_hashmap_isempty((OrderedHashmap*) s);
}
static inline void *ordered_set_iterate(OrderedSet *s, Iterator *i) {
return ordered_hashmap_iterate((OrderedHashmap*) s, i, NULL);
static inline bool ordered_set_iterate(OrderedSet *s, Iterator *i, void **value) {
return ordered_hashmap_iterate((OrderedHashmap*) s, i, value, NULL);
}
#define ORDERED_SET_FOREACH(e, s, i) \
for ((i) = ITERATOR_FIRST, (e) = ordered_set_iterate((s), &(i)); (e); (e) = ordered_set_iterate((s), &(i)))
for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); )
DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free);