Merge pull request #10920 from yuwata/hashmap-destructor

hashmap: make hashmap_free() call destructors of key or value
This commit is contained in:
Lennart Poettering
2018-12-03 17:59:44 +01:00
committed by GitHub
59 changed files with 546 additions and 716 deletions
+5 -9
View File
@@ -460,8 +460,7 @@ finish:
return 0;
}
void dns_name_hash_func(const void *s, struct siphash *state) {
const char *p = s;
void dns_name_hash_func(const char *p, struct siphash *state) {
int r;
assert(p);
@@ -484,15 +483,15 @@ void dns_name_hash_func(const void *s, struct siphash *state) {
string_hash_func("", state);
}
int dns_name_compare_func(const void *a, const void *b) {
int dns_name_compare_func(const char *a, const char *b) {
const char *x, *y;
int r, q;
assert(a);
assert(b);
x = (const char *) a + strlen(a);
y = (const char *) b + strlen(b);
x = a + strlen(a);
y = b + strlen(b);
for (;;) {
char la[DNS_LABEL_MAX], lb[DNS_LABEL_MAX];
@@ -511,10 +510,7 @@ int dns_name_compare_func(const void *a, const void *b) {
}
}
const struct hash_ops dns_name_hash_ops = {
.hash = dns_name_hash_func,
.compare = dns_name_compare_func
};
DEFINE_HASH_OPS(dns_name_hash_ops, char, dns_name_hash_func, dns_name_compare_func);
int dns_name_equal(const char *x, const char *y) {
int r, q;
+2 -2
View File
@@ -57,8 +57,8 @@ static inline int dns_name_is_valid(const char *s) {
return 1;
}
void dns_name_hash_func(const void *s, struct siphash *state);
int dns_name_compare_func(const void *a, const void *b);
void dns_name_hash_func(const char *s, struct siphash *state);
int dns_name_compare_func(const char *a, const char *b);
extern const struct hash_ops dns_name_hash_ops;
int dns_name_between(const char *a, const char *b, const char *c);
+2
View File
@@ -70,6 +70,8 @@ static Image *image_free(Image *i) {
}
DEFINE_TRIVIAL_REF_UNREF_FUNC(Image, image, image_free);
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(image_hash_ops, char, string_hash_func, string_compare_func,
Image, image_unref);
static char **image_settings_path(Image *image) {
_cleanup_strv_free_ char **l = NULL;
+2 -5
View File
@@ -59,12 +59,7 @@ typedef struct Image {
Image *image_unref(Image *i);
Image *image_ref(Image *i);
static inline Hashmap* image_hashmap_free(Hashmap *map) {
return hashmap_free_with_destructor(map, image_unref);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
int image_find(ImageClass class, const char *name, Image **ret);
int image_from_path(const char *path, Image **ret);
@@ -113,3 +108,5 @@ static inline bool IMAGE_IS_HOST(const struct Image *i) {
return false;
}
extern const struct hash_ops image_hash_ops;