From c09ce222b6379e8f73695e5ce53fce76a44d78c7 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sun, 4 May 2025 13:31:07 +0200 Subject: [PATCH] hashmap: Drop debug params Passing in the func, file and line information complicates the interface. On top of that, it prevents forward declaring Hashmap in strv.h, as we need to pass the macros everywhere that we allocate a hashmap, which means we have to include the hashmap header everywhere we have a function that allocates a hashmap instead of just having to forward declare Hashmap. Let's drop the file, func and line information from the debug information. Instead, in the future we can add a description field to hashmaps like we already have in various other structs to describe the purpose of the hashmap which should be much more useful than having the file, line and function where the hashmap was allocated. --- src/basic/hashmap.c | 78 ++++++++++++++++------------------- src/basic/hashmap.h | 53 +++++++++--------------- src/basic/ordered-set.c | 16 +++---- src/basic/ordered-set.h | 17 +++----- src/basic/set.h | 21 ++++------ src/basic/strv.c | 8 ++-- src/basic/strv.h | 8 ++-- tools/gdb-sd_dump_hashmaps.py | 2 +- 8 files changed, 85 insertions(+), 118 deletions(-) diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 6bbcd70c07a..ccb62e7b2a2 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -138,11 +138,6 @@ struct hashmap_debug_info { LIST_FIELDS(struct hashmap_debug_info, debug_list); unsigned max_entries; /* high watermark of n_entries */ - /* who allocated this hashmap */ - int line; - const char *file; - const char *func; - /* fields to detect modification while iterating */ unsigned put_count; /* counts puts into the hashmap */ unsigned rem_count; /* counts removals from hashmap */ @@ -778,7 +773,7 @@ static void shared_hash_key_initialize(void) { random_bytes(shared_hash_key, sizeof(shared_hash_key)); } -static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) { +static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type) { HashmapBase *h; const struct hashmap_type_info *hi = &hashmap_type_info[type]; @@ -803,9 +798,6 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu assert_se(pthread_once(&once, shared_hash_key_initialize) == 0); #if ENABLE_DEBUG_HASHMAP - h->debug.func = func; - h->debug.file = file; - h->debug.line = line; assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0); LIST_PREPEND(debug_list, hashmap_debug_list, &h->debug); assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0); @@ -814,20 +806,20 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu return h; } -Hashmap *_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS); +Hashmap *hashmap_new(const struct hash_ops *hash_ops) { + return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN); } -OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS); +OrderedHashmap *ordered_hashmap_new(const struct hash_ops *hash_ops) { + return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED); } -Set *_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS); +Set *set_new(const struct hash_ops *hash_ops) { + return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET); } static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops *hash_ops, - enum HashmapType type HASHMAP_DEBUG_PARAMS) { + enum HashmapType type) { HashmapBase *q; assert(h); @@ -835,7 +827,7 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops if (*h) return 0; - q = hashmap_base_new(hash_ops, type HASHMAP_DEBUG_PASS_ARGS); + q = hashmap_base_new(hash_ops, type); if (!q) return -ENOMEM; @@ -843,52 +835,52 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops return 1; } -int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS); +int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops) { + return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN); } -int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS); +int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops) { + return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED); } -int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) { - return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS); +int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops) { + return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET); } -int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) { +int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) { int r; - r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = hashmap_ensure_allocated(h, hash_ops); if (r < 0) return r; return hashmap_put(*h, key, value); } -int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) { +int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) { int r; - r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = ordered_hashmap_ensure_allocated(h, hash_ops); if (r < 0) return r; return ordered_hashmap_put(*h, key, value); } -int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) { +int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) { int r; - r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = ordered_hashmap_ensure_allocated(h, hash_ops); if (r < 0) return r; return ordered_hashmap_replace(*h, key, value); } -int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) { +int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) { int r; - r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = hashmap_ensure_allocated(h, hash_ops); if (r < 0) return r; @@ -1290,20 +1282,20 @@ int set_put(Set *s, const void *key) { return hashmap_put_boldly(s, hash, &swap, true); } -int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS) { +int set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key) { int r; - r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = _set_ensure_allocated(s, hash_ops); if (r < 0) return r; return set_put(*s, key); } -int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS) { +int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key) { int r; - r = _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_PASS_ARGS); + r = set_ensure_put(s, hash_ops, key); if (r <= 0) { if (hash_ops && hash_ops->free_key) hash_ops->free_key(key); @@ -1754,13 +1746,13 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) { return 0; } -HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) { +HashmapBase* _hashmap_copy(HashmapBase *h) { HashmapBase *copy; int r; assert(h); - copy = hashmap_base_new(h->hash_ops, h->type HASHMAP_DEBUG_PASS_ARGS); + copy = hashmap_base_new(h->hash_ops, h->type); if (!copy) return NULL; @@ -1850,10 +1842,10 @@ int set_consume(Set *s, void *value) { return r; } -int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS) { +int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v) { int r; - r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = hashmap_ensure_allocated(h, hash_ops); if (r < 0) return r; @@ -1884,14 +1876,14 @@ int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const return r; } -int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS) { +int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n) { char *c; int r; assert(s); assert(p); - r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS); + r = _set_ensure_allocated(s, hash_ops); if (r < 0) return r; @@ -1908,13 +1900,13 @@ int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char * return set_consume(*s, c); } -int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS) { +int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l) { int n = 0, r; assert(s); STRV_FOREACH(i, l) { - r = _set_put_strndup_full(s, hash_ops, *i, SIZE_MAX HASHMAP_DEBUG_PASS_ARGS); + r = set_put_strndup_full(s, hash_ops, *i, SIZE_MAX); if (r < 0) return r; diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index 8ced7e6a990..f7e02c814e7 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -73,20 +73,8 @@ typedef struct { (Hashmap*)(h), \ (void)0) -#if ENABLE_DEBUG_HASHMAP -# define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line -# define HASHMAP_DEBUG_SRC_ARGS , __func__, PROJECT_FILE, __LINE__ -# define HASHMAP_DEBUG_PASS_ARGS , func, file, line -#else -# define HASHMAP_DEBUG_PARAMS -# define HASHMAP_DEBUG_SRC_ARGS -# define HASHMAP_DEBUG_PASS_ARGS -#endif - -Hashmap* _hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -#define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) -#define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) +Hashmap* hashmap_new(const struct hash_ops *hash_ops); +OrderedHashmap* ordered_hashmap_new(const struct hash_ops *hash_ops); #define hashmap_free_and_replace(a, b) \ free_and_replace_full(a, b, hashmap_free) @@ -104,25 +92,21 @@ static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) { IteratedCache* iterated_cache_free(IteratedCache *cache); int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries); -HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS); -#define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS)) -#define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS)) - -int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS); -int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS); - -#define hashmap_ensure_allocated(h, ops) _hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS) -#define hashmap_ensure_put(s, ops, key, value) _hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS) -#define ordered_hashmap_ensure_allocated(h, ops) _ordered_hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS) -#define hashmap_ensure_replace(s, ops, key, value) _hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS) +HashmapBase* _hashmap_copy(HashmapBase *h); +static inline Hashmap* hashmap_copy(Hashmap *h) { + return (Hashmap*) _hashmap_copy(HASHMAP_BASE(h)); +} +static inline OrderedHashmap* ordered_hashmap_copy(OrderedHashmap *h) { + return (OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h)); +} -int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS); -#define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS) +int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops); +int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value); +int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops); +int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value); -int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS); -#define ordered_hashmap_ensure_replace(s, ops, key, value) _ordered_hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS) +int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value); +int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value); IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h); static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) { @@ -137,9 +121,10 @@ static inline int ordered_hashmap_put(OrderedHashmap *h, const void *key, void * return hashmap_put(PLAIN_HASHMAP(h), key, value); } -int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS); -#define hashmap_put_strdup_full(h, hash_ops, k, v) _hashmap_put_strdup_full(h, hash_ops, k, v HASHMAP_DEBUG_SRC_ARGS) -#define hashmap_put_strdup(h, k, v) hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v) +int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v); +static inline int hashmap_put_strdup(Hashmap **h, const char *k, const char *v) { + return hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v); +} int hashmap_update(Hashmap *h, const void *key, void *value); static inline int ordered_hashmap_update(OrderedHashmap *h, const void *key, void *value) { diff --git a/src/basic/ordered-set.c b/src/basic/ordered-set.c index 65cf3a026f4..b59a9e5f1b9 100644 --- a/src/basic/ordered-set.c +++ b/src/basic/ordered-set.c @@ -4,21 +4,21 @@ #include "ordered-set.h" #include "strv.h" -int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) { +int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) { if (*s) return 0; - *s = _ordered_set_new(ops HASHMAP_DEBUG_PASS_ARGS); + *s = ordered_set_new(ops); if (!*s) return -ENOMEM; return 0; } -int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS) { +int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p) { int r; - r = _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_PASS_ARGS); + r = ordered_set_ensure_allocated(s, ops); if (r < 0) return r; @@ -35,14 +35,14 @@ int ordered_set_consume(OrderedSet *s, void *p) { return r; } -int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) { +int ordered_set_put_strdup(OrderedSet **s, const char *p) { char *c; int r; assert(s); assert(p); - r = _ordered_set_ensure_allocated(s, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS); + r = ordered_set_ensure_allocated(s, &string_hash_ops_free); if (r < 0) return r; @@ -56,11 +56,11 @@ int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) return ordered_set_consume(*s, c); } -int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS) { +int ordered_set_put_strdupv(OrderedSet **s, char **l) { int n = 0, r; STRV_FOREACH(i, l) { - r = _ordered_set_put_strdup(s, *i HASHMAP_DEBUG_PASS_ARGS); + r = ordered_set_put_strdup(s, *i); if (r < 0) return r; diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h index b7113ad918c..77661ced66a 100644 --- a/src/basic/ordered-set.h +++ b/src/basic/ordered-set.h @@ -7,16 +7,13 @@ typedef struct OrderedSet OrderedSet; -static inline OrderedSet* _ordered_set_new(const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) { - return (OrderedSet*) _ordered_hashmap_new(ops HASHMAP_DEBUG_PASS_ARGS); +static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) { + return (OrderedSet*) ordered_hashmap_new(ops); } -#define ordered_set_new(ops) _ordered_set_new(ops HASHMAP_DEBUG_SRC_ARGS) -int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS); -#define ordered_set_ensure_allocated(s, ops) _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_SRC_ARGS) +int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops); -int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS); -#define ordered_set_ensure_put(s, hash_ops, key) _ordered_set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS) +int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p); static inline void ordered_set_clear(OrderedSet *s) { return ordered_hashmap_clear((OrderedHashmap*) s); @@ -71,10 +68,8 @@ 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 HASHMAP_DEBUG_PARAMS); -#define ordered_set_put_strdup(s, p) _ordered_set_put_strdup(s, p HASHMAP_DEBUG_SRC_ARGS) -int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS); -#define ordered_set_put_strdupv(s, l) _ordered_set_put_strdupv(s, l HASHMAP_DEBUG_SRC_ARGS) +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); void ordered_set_print(FILE *f, const char *field, OrderedSet *s); diff --git a/src/basic/set.h b/src/basic/set.h index c7b84e0a54b..789bf9b7334 100644 --- a/src/basic/set.h +++ b/src/basic/set.h @@ -8,17 +8,16 @@ #define set_free_and_replace(a, b) \ free_and_replace_full(a, b, set_free) -Set* _set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -#define set_new(ops) _set_new(ops HASHMAP_DEBUG_SRC_ARGS) +Set* set_new(const struct hash_ops *hash_ops); static inline Set* set_free(Set *s) { return (Set*) _hashmap_free(HASHMAP_BASE(s)); } -#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s) HASHMAP_DEBUG_SRC_ARGS)) +#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s))) -int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); -#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS) +int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops); +#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops) int set_put(Set *s, const void *key); /* no set_update */ @@ -93,22 +92,18 @@ static inline char **set_get_strv(Set *s) { char** set_to_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_put(Set **s, const struct hash_ops *hash_ops, const void *key); -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_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key); int set_consume(Set *s, void *value); -int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS); -#define set_put_strndup_full(s, hash_ops, p, n) _set_put_strndup_full(s, hash_ops, p, n HASHMAP_DEBUG_SRC_ARGS) +int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n); #define set_put_strdup_full(s, hash_ops, p) set_put_strndup_full(s, hash_ops, p, SIZE_MAX) #define set_put_strndup(s, p, n) set_put_strndup_full(s, &string_hash_ops_free, p, n) #define set_put_strdup(s, p) set_put_strndup(s, p, SIZE_MAX) -int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS); -#define set_put_strdupv_full(s, hash_ops, l) _set_put_strdupv_full(s, hash_ops, l HASHMAP_DEBUG_SRC_ARGS) +int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l ); #define set_put_strdupv(s, l) set_put_strdupv_full(s, &string_hash_ops_free, l) int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags); diff --git a/src/basic/strv.c b/src/basic/strv.c index 2f308541464..76b86cbec8b 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -1126,28 +1126,28 @@ static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const c return 1; } -int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) { +int string_strv_hashmap_put(Hashmap **h, const char *key, const char *value) { int r; assert(h); assert(key); assert(value); - r = _hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS); + r = hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free); if (r < 0) return r; return string_strv_hashmap_put_internal(*h, key, value); } -int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) { +int string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value) { int r; assert(h); assert(key); assert(value); - r = _ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS); + r = ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free); if (r < 0) return r; diff --git a/src/basic/strv.h b/src/basic/strv.h index 0ca90087b42..24bdd47cc58 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -262,10 +262,10 @@ void string_strv_hashmap_remove(Hashmap *h, const char *key, const char *value); static inline void string_strv_ordered_hashmap_remove(OrderedHashmap *h, const char *key, const char *value) { string_strv_hashmap_remove(PLAIN_HASHMAP(h), key, value); } -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) -#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS) +int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value); +int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value); +#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v) +#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v) int strv_rebreak_lines(char **l, size_t width, char ***ret); diff --git a/tools/gdb-sd_dump_hashmaps.py b/tools/gdb-sd_dump_hashmaps.py index 57f825a09cc..596ee8d90c3 100644 --- a/tools/gdb-sd_dump_hashmaps.py +++ b/tools/gdb-sd_dump_hashmaps.py @@ -32,7 +32,7 @@ class sd_dump_hashmaps(gdb.Command): t = ["plain", "ordered", "set"][int(h["type"])] - print(f'{t}, {h["hash_ops"]}, {bool(h["has_indirect"])}, {n_entries}, {d["max_entries"]}, {n_buckets}, {d["func"].string()}, {d["file"].string()}:{d["line"]}') + print(f'{t}, {h["hash_ops"]}, {bool(h["has_indirect"])}, {n_entries}, {d["max_entries"]}, {n_buckets}') if arg != "" and n_entries > 0: dib_raw_addr = storage_ptr + hashmap_type_info[h["type"]]["entry_size"] * n_buckets -- 2.47.3