|
|
be0c12 |
From cfa7b3d0a1900b725e5489dfec2c39abb8569c29 Mon Sep 17 00:00:00 2001
|
|
|
be0c12 |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
be0c12 |
Date: Wed, 28 Nov 2018 14:10:04 +0900
|
|
|
be0c12 |
Subject: [PATCH] hash-funcs: introduce macro to create typesafe hash_ops
|
|
|
be0c12 |
|
|
|
be0c12 |
(cherry picked from commit d1005d1c0050d3dc3a24c054bac4c4916073cbba)
|
|
|
be0c12 |
|
|
|
be0c12 |
Resolves: #2037807
|
|
|
be0c12 |
---
|
|
|
be0c12 |
src/basic/hash-funcs.h | 14 ++++++++++++++
|
|
|
be0c12 |
1 file changed, 14 insertions(+)
|
|
|
be0c12 |
|
|
|
be0c12 |
diff --git a/src/basic/hash-funcs.h b/src/basic/hash-funcs.h
|
|
|
be0c12 |
index 5e5989f021..2ff687e5f9 100644
|
|
|
be0c12 |
--- a/src/basic/hash-funcs.h
|
|
|
be0c12 |
+++ b/src/basic/hash-funcs.h
|
|
|
be0c12 |
@@ -13,6 +13,20 @@ struct hash_ops {
|
|
|
be0c12 |
compare_func_t compare;
|
|
|
be0c12 |
};
|
|
|
be0c12 |
|
|
|
be0c12 |
+#define _DEFINE_HASH_OPS(uq, name, type, hash_func, compare_func, scope) \
|
|
|
be0c12 |
+ _unused_ static void (* UNIQ_T(static_hash_wrapper, uq))(const type *, struct siphash *) = hash_func; \
|
|
|
be0c12 |
+ _unused_ static int (* UNIQ_T(static_compare_wrapper, uq))(const type *, const type *) = compare_func; \
|
|
|
be0c12 |
+ scope const struct hash_ops name = { \
|
|
|
be0c12 |
+ .hash = (hash_func_t) hash_func, \
|
|
|
be0c12 |
+ .compare = (compare_func_t) compare_func, \
|
|
|
be0c12 |
+ }
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+#define DEFINE_HASH_OPS(name, type, hash_func, compare_func) \
|
|
|
be0c12 |
+ _DEFINE_HASH_OPS(UNIQ, name, type, hash_func, compare_func,)
|
|
|
be0c12 |
+
|
|
|
be0c12 |
+#define DEFINE_PRIVATE_HASH_OPS(name, type, hash_func, compare_func) \
|
|
|
be0c12 |
+ _DEFINE_HASH_OPS(UNIQ, name, type, hash_func, compare_func, static)
|
|
|
be0c12 |
+
|
|
|
be0c12 |
void string_hash_func(const void *p, struct siphash *state);
|
|
|
be0c12 |
int string_compare_func(const void *a, const void *b) _pure_;
|
|
|
be0c12 |
extern const struct hash_ops string_hash_ops;
|