basic: pass allocation info for ordered_set_new() and introduce ordered_set_ensure_put()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-09-01 12:42:35 +02:00
parent b7847e05f5
commit 1f25c71d9d
2 changed files with 28 additions and 11 deletions
+21
View File
@@ -4,6 +4,27 @@
#include "ordered-set.h"
#include "strv.h"
int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) {
if (*s)
return 0;
*s = _ordered_set_new(ops HASHMAP_DEBUG_PASS_ARGS);
if (!*s)
return -ENOMEM;
return 0;
}
int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS) {
int r;
r = _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_PASS_ARGS);
if (r < 0)
return r;
return ordered_set_put(*s, p);
}
int ordered_set_consume(OrderedSet *s, void *p) {
int r;