basic/set: add set_ensure_consume()

This combines set_ensure_allocated() with set_consume(). The cool thing is that
because we know the hash ops, we can correctly free the item if appropriate.
Similarly to set_consume(), the goal is to simplify handling of the case where
the item needs to be freed on error and if already present in the set.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-06-24 10:38:15 +02:00
parent 6cd55d6f74
commit fcc1d0315d
4 changed files with 42 additions and 0 deletions
+3
View File
@@ -123,6 +123,9 @@ static inline char **set_get_strv(Set *s) {
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS);
#define set_ensure_put(s, hash_ops, key) _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS);
#define set_ensure_consume(s, hash_ops, key) _set_ensure_consume(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int set_consume(Set *s, void *value);
int set_put_strdup(Set **s, const char *p);
int set_put_strdupv(Set **s, char **l);