summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-28 14:10:04 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-02 07:48:12 +0100
commitd1005d1c0050d3dc3a24c054bac4c4916073cbba (patch)
treeb8799046f0fc40e70410758b90a2f97e4074ce83 /src
parente30f9c972b789152d67ff34fd3bda294d20d1f51 (diff)
downloadsystemd-d1005d1c0050d3dc3a24c054bac4c4916073cbba.tar.gz
hash-funcs: introduce macro to create typesafe hash_ops
Diffstat (limited to 'src')
-rw-r--r--src/basic/hash-funcs.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/basic/hash-funcs.h b/src/basic/hash-funcs.h
index fa45cfe256..30e8979fe6 100644
--- a/src/basic/hash-funcs.h
+++ b/src/basic/hash-funcs.h
@@ -12,6 +12,20 @@ struct hash_ops {
compare_func_t compare;
};
+#define _DEFINE_HASH_OPS(uq, name, type, hash_func, compare_func, scope) \
+ _unused_ static void (* UNIQ_T(static_hash_wrapper, uq))(const type *, struct siphash *) = hash_func; \
+ _unused_ static int (* UNIQ_T(static_compare_wrapper, uq))(const type *, const type *) = compare_func; \
+ scope const struct hash_ops name = { \
+ .hash = (hash_func_t) hash_func, \
+ .compare = (compare_func_t) compare_func, \
+ }
+
+#define DEFINE_HASH_OPS(name, type, hash_func, compare_func) \
+ _DEFINE_HASH_OPS(UNIQ, name, type, hash_func, compare_func,)
+
+#define DEFINE_PRIVATE_HASH_OPS(name, type, hash_func, compare_func) \
+ _DEFINE_HASH_OPS(UNIQ, name, type, hash_func, compare_func, static)
+
void string_hash_func(const void *p, struct siphash *state);
int string_compare_func(const void *a, const void *b) _pure_;
extern const struct hash_ops string_hash_ops;