X Tutup
Skip to content

Commit add74e8

Browse files
committed
basic/hashmap,set: propagate allocation location info in _copy()
Also use double space before the tracking args at the end. Without the comma this looks ugly, but it's a bit better with the double space. At least it doesn't look like a variable with a type.
1 parent 35e601d commit add74e8

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

src/basic/hashmap.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ static void reset_direct_storage(HashmapBase *h) {
768768
memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets);
769769
}
770770

771-
static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
771+
static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
772772
HashmapBase *h;
773773
const struct hashmap_type_info *hi = &hashmap_type_info[type];
774774
bool up;
@@ -808,27 +808,27 @@ static struct HashmapBase *hashmap_base_new(const struct hash_ops *hash_ops, enu
808808
}
809809

810810
Hashmap *_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
811-
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
811+
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
812812
}
813813

814814
OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
815-
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
815+
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
816816
}
817817

818818
Set *_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
819-
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
819+
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
820820
}
821821

822822
static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops *hash_ops,
823-
enum HashmapType type HASHMAP_DEBUG_PARAMS) {
823+
enum HashmapType type HASHMAP_DEBUG_PARAMS) {
824824
HashmapBase *q;
825825

826826
assert(h);
827827

828828
if (*h)
829829
return 0;
830830

831-
q = hashmap_base_new(hash_ops, type HASHMAP_DEBUG_PASS_ARGS);
831+
q = hashmap_base_new(hash_ops, type HASHMAP_DEBUG_PASS_ARGS);
832832
if (!q)
833833
return -ENOMEM;
834834

@@ -837,15 +837,15 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops
837837
}
838838

839839
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
840-
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
840+
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
841841
}
842842

843843
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
844-
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
844+
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
845845
}
846846

847847
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
848-
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
848+
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
849849
}
850850

851851
static void hashmap_free_no_clear(HashmapBase *h) {
@@ -1711,13 +1711,13 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) {
17111711
return 0;
17121712
}
17131713

1714-
HashmapBase *_hashmap_copy(HashmapBase *h) {
1714+
HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
17151715
HashmapBase *copy;
17161716
int r;
17171717

17181718
assert(h);
17191719

1720-
copy = hashmap_base_new(h->hash_ops, h->type HASHMAP_DEBUG_SRC_ARGS);
1720+
copy = hashmap_base_new(h->hash_ops, h->type HASHMAP_DEBUG_PASS_ARGS);
17211721
if (!copy)
17221722
return NULL;
17231723

@@ -1733,10 +1733,8 @@ HashmapBase *_hashmap_copy(HashmapBase *h) {
17331733
assert_not_reached("Unknown hashmap type");
17341734
}
17351735

1736-
if (r < 0) {
1737-
_hashmap_free(copy, false, false);
1738-
return NULL;
1739-
}
1736+
if (r < 0)
1737+
return _hashmap_free(copy, false, false);
17401738

17411739
return copy;
17421740
}

src/basic/hashmap.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,9 @@ static inline OrderedHashmap *ordered_hashmap_free_free_free(OrderedHashmap *h)
128128
IteratedCache *iterated_cache_free(IteratedCache *cache);
129129
int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries);
130130

131-
HashmapBase *_hashmap_copy(HashmapBase *h);
132-
static inline Hashmap *hashmap_copy(Hashmap *h) {
133-
return (Hashmap*) _hashmap_copy(HASHMAP_BASE(h));
134-
}
135-
static inline OrderedHashmap *ordered_hashmap_copy(OrderedHashmap *h) {
136-
return (OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h));
137-
}
131+
HashmapBase *_hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS);
132+
#define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
133+
#define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
138134

139135
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
140136
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);

src/basic/set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ static inline Set *set_free_free(Set *s) {
2626

2727
/* no set_free_free_free */
2828

29-
static inline Set *set_copy(Set *s) {
30-
return (Set*) _hashmap_copy(HASHMAP_BASE(s));
31-
}
29+
#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
3230

3331
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
3432
#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)

0 commit comments

Comments
 (0)
X Tutup