mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 15:10:33 +00:00
hashmap,set: make hashmap_clear_with_destructor() or friends safer
This commit is contained in:
@@ -371,28 +371,26 @@ static inline void *ordered_hashmap_first_key(OrderedHashmap *h) {
|
||||
return _hashmap_first_key(HASHMAP_BASE(h), false);
|
||||
}
|
||||
|
||||
#define hashmap_clear_with_destructor(_s, _f) \
|
||||
#define hashmap_clear_with_destructor(h, f) \
|
||||
({ \
|
||||
Hashmap *_h = (h); \
|
||||
void *_item; \
|
||||
while ((_item = hashmap_steal_first(_s))) \
|
||||
_f(_item); \
|
||||
while ((_item = hashmap_steal_first(_h))) \
|
||||
f(_item); \
|
||||
_h; \
|
||||
})
|
||||
#define hashmap_free_with_destructor(_s, _f) \
|
||||
({ \
|
||||
hashmap_clear_with_destructor(_s, _f); \
|
||||
hashmap_free(_s); \
|
||||
})
|
||||
#define ordered_hashmap_clear_with_destructor(_s, _f) \
|
||||
#define hashmap_free_with_destructor(h, f) \
|
||||
hashmap_free(hashmap_clear_with_destructor(h, f))
|
||||
#define ordered_hashmap_clear_with_destructor(h, f) \
|
||||
({ \
|
||||
OrderedHashmap *_h = (h); \
|
||||
void *_item; \
|
||||
while ((_item = ordered_hashmap_steal_first(_s))) \
|
||||
_f(_item); \
|
||||
})
|
||||
#define ordered_hashmap_free_with_destructor(_s, _f) \
|
||||
({ \
|
||||
ordered_hashmap_clear_with_destructor(_s, _f); \
|
||||
ordered_hashmap_free(_s); \
|
||||
while ((_item = ordered_hashmap_steal_first(_h))) \
|
||||
f(_item); \
|
||||
_h; \
|
||||
})
|
||||
#define ordered_hashmap_free_with_destructor(h, f) \
|
||||
ordered_hashmap_free(ordered_hashmap_clear_with_destructor(h, f))
|
||||
|
||||
/* no hashmap_next */
|
||||
void* ordered_hashmap_next(OrderedHashmap *h, const void *key);
|
||||
|
||||
@@ -95,17 +95,16 @@ static inline void *set_steal_first(Set *s) {
|
||||
return _hashmap_first_key_and_value(HASHMAP_BASE(s), true, NULL);
|
||||
}
|
||||
|
||||
#define set_clear_with_destructor(_s, _f) \
|
||||
#define set_clear_with_destructor(s, f) \
|
||||
({ \
|
||||
Set *_s = (s); \
|
||||
void *_item; \
|
||||
while ((_item = set_steal_first(_s))) \
|
||||
_f(_item); \
|
||||
})
|
||||
#define set_free_with_destructor(_s, _f) \
|
||||
({ \
|
||||
set_clear_with_destructor(_s, _f); \
|
||||
set_free(_s); \
|
||||
f(_item); \
|
||||
_s; \
|
||||
})
|
||||
#define set_free_with_destructor(s, f) \
|
||||
set_free(set_clear_with_destructor(s, f))
|
||||
|
||||
/* no set_steal_first_key */
|
||||
/* no set_first_key */
|
||||
|
||||
Reference in New Issue
Block a user