]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ordered-set: introduce ordered_set_put_strdup_full() and friends which take hash ops
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Jun 2025 15:05:59 +0000 (00:05 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Jun 2025 15:06:43 +0000 (00:06 +0900)
src/basic/ordered-set.c
src/basic/ordered-set.h

index 9b4ff5ff39c796aa0c3c706c018838262dcf4aea..4d2c43cf363770ea00993e57f2f92f442f9bb863 100644 (file)
@@ -39,14 +39,14 @@ int ordered_set_consume(OrderedSet *s, void *p) {
         return r;
 }
 
-int ordered_set_put_strdup(OrderedSet **s, const char *p) {
+int ordered_set_put_strdup_full(OrderedSet **s, const struct hash_ops *hash_ops, const char *p) {
         char *c;
         int r;
 
         assert(s);
         assert(p);
 
-        r = ordered_set_ensure_allocated(s, &string_hash_ops_free);
+        r = ordered_set_ensure_allocated(s, hash_ops);
         if (r < 0)
                 return r;
 
@@ -60,11 +60,13 @@ int ordered_set_put_strdup(OrderedSet **s, const char *p) {
         return ordered_set_consume(*s, c);
 }
 
-int ordered_set_put_strdupv(OrderedSet **s, char **l) {
+int ordered_set_put_strdupv_full(OrderedSet **s, const struct hash_ops *hash_ops, char **l) {
         int n = 0, r;
 
+        assert(s);
+
         STRV_FOREACH(i, l) {
-                r = ordered_set_put_strdup(s, *i);
+                r = ordered_set_put_strdup_full(s, hash_ops, *i);
                 if (r < 0)
                         return r;
 
@@ -74,14 +76,16 @@ int ordered_set_put_strdupv(OrderedSet **s, char **l) {
         return n;
 }
 
-int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l) {
+int ordered_set_put_string_set_full(OrderedSet **s, const struct hash_ops *hash_ops, OrderedSet *l) {
         int n = 0, r;
         char *p;
 
+        assert(s);
+
         /* Like ordered_set_put_strv, but for an OrderedSet of strings */
 
         ORDERED_SET_FOREACH(p, l) {
-                r = ordered_set_put_strdup(s, p);
+                r = ordered_set_put_strdup_full(s, hash_ops, p);
                 if (r < 0)
                         return r;
 
index 34f585c9bc2c0ae58fcde6e9993030344e906b62..fb3e53395e259d47f383a834430c34c89c0a2f4e 100644 (file)
@@ -67,9 +67,14 @@ static inline int ordered_set_reserve(OrderedSet *s, unsigned entries_add) {
 }
 
 int ordered_set_consume(OrderedSet *s, void *p);
-int ordered_set_put_strdup(OrderedSet **s, const char *p);
-int ordered_set_put_strdupv(OrderedSet **s, char **l);
-int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l);
+
+int ordered_set_put_strdup_full(OrderedSet **s, const struct hash_ops *hash_ops, const char *p);
+#define ordered_set_put_strdup(s, p) ordered_set_put_strdup_full(s, &string_hash_ops_free, p)
+int ordered_set_put_strdupv_full(OrderedSet **s, const struct hash_ops *hash_ops, char **l);
+#define ordered_set_put_strdupv(s, l) ordered_set_put_strdupv_full(s, &string_hash_ops_free, l)
+int ordered_set_put_string_set_full(OrderedSet **s, const struct hash_ops *hash_ops, OrderedSet *l);
+#define ordered_set_put_string_set(s, l) ordered_set_put_string_set_full(s, &string_hash_ops_free, l)
+
 void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
 
 #define _ORDERED_SET_FOREACH(e, s, i) \