From 527b9e2437e3dad6838de4bb8fa5e9fbce6fbe70 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 12 Sep 2024 19:06:02 +0200 Subject: [PATCH] basic/strv: make string_strv_hash_ops static, add missing assertions --- src/basic/strv.c | 17 +++++++++++++++-- src/basic/strv.h | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/basic/strv.c b/src/basic/strv.c index 5b71c36dbfe..0c3733a02b1 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -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; diff --git a/src/basic/strv.h b/src/basic/strv.h index b7845eeeccb..1ef3ea5faf8 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -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) -- 2.47.3