]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/strv: make string_strv_hash_ops static, add missing assertions
authorMike Yuan <me@yhndnzj.com>
Thu, 12 Sep 2024 17:06:02 +0000 (19:06 +0200)
committerMike Yuan <me@yhndnzj.com>
Fri, 20 Sep 2024 20:44:35 +0000 (22:44 +0200)
src/basic/strv.c
src/basic/strv.h

index 5b71c36dbfe74f5f6e7b898a1338600319d04bb6..0c3733a02b1d6aacf9a56f66d36a7adf262be9bf 100644 (file)
@@ -952,10 +952,16 @@ int fputstrv(FILE *f, char * const *l, const char *separator, bool *space) {
         return 0;
 }
 
+DEFINE_PRIVATE_HASH_OPS_FULL(string_strv_hash_ops, char, string_hash_func, string_compare_func, free, char*, strv_free);
+
 static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const char *value) {
         char **l;
         int r;
 
+        assert(h);
+        assert(key);
+        assert(value);
+
         l = hashmap_get(h, key);
         if (l) {
                 /* A list for this key already exists, let's append to it if it is not listed yet */
@@ -983,6 +989,7 @@ static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const c
                 r = hashmap_put(h, t, l2);
                 if (r < 0)
                         return r;
+
                 TAKE_PTR(t);
                 TAKE_PTR(l2);
         }
@@ -993,6 +1000,10 @@ static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const c
 int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value  HASHMAP_DEBUG_PARAMS) {
         int r;
 
+        assert(h);
+        assert(key);
+        assert(value);
+
         r = _hashmap_ensure_allocated(h, &string_strv_hash_ops  HASHMAP_DEBUG_PASS_ARGS);
         if (r < 0)
                 return r;
@@ -1003,6 +1014,10 @@ int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value  HA
 int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value  HASHMAP_DEBUG_PARAMS) {
         int r;
 
+        assert(h);
+        assert(key);
+        assert(value);
+
         r = _ordered_hashmap_ensure_allocated(h, &string_strv_hash_ops  HASHMAP_DEBUG_PASS_ARGS);
         if (r < 0)
                 return r;
@@ -1010,8 +1025,6 @@ int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const
         return string_strv_hashmap_put_internal(PLAIN_HASHMAP(*h), key, value);
 }
 
-DEFINE_HASH_OPS_FULL(string_strv_hash_ops, char, string_hash_func, string_compare_func, free, char*, strv_free);
-
 int strv_rebreak_lines(char **l, size_t width, char ***ret) {
         _cleanup_strv_free_ char **broken = NULL;
         int r;
index b7845eeeccb27870633a5d860c6d468c524576a7..1ef3ea5faf8092b0fc295374c450567520b5e2c8 100644 (file)
@@ -253,7 +253,6 @@ int fputstrv(FILE *f, char * const *l, const char *separator, bool *space);
 #define strv_free_and_replace(a, b)             \
         free_and_replace_full(a, b, strv_free)
 
-extern const struct hash_ops string_strv_hash_ops;
 int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value  HASHMAP_DEBUG_PARAMS);
 int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value  HASHMAP_DEBUG_PARAMS);
 #define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v  HASHMAP_DEBUG_SRC_ARGS)