htable/htable_type: allow keyof to be a simple macro
authorCody P Schafer <dev@codyps.com>
Tue, 31 May 2016 16:06:16 +0000 (12:06 -0400)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 31 May 2016 21:08:56 +0000 (06:38 +0930)
Without this, one had to either use a function or a macro with casts to
get the expected behavior.

Signed-off-by: Cody P Schafer <dev@codyps.com>
ccan/htable/htable_type.h

index 61535c2c665c43fa611f5b995205e9fccd94f648..15a70fc28d039e31f9285f83a496e14faa09c71f 100644 (file)
@@ -81,7 +81,7 @@
                return htable_del(&ht->raw, hashfn(keyof(elem)), elem); \
        }                                                               \
        static inline UNNEEDED type *name##_get(const struct name *ht,  \
-                                      const HTABLE_KTYPE(keyof) k)     \
+                                      const HTABLE_KTYPE(keyof, type) k) \
        {                                                               \
                /* Typecheck for eqfn */                                \
                (void)sizeof(eqfn((const type *)NULL,                   \
@@ -92,7 +92,7 @@
                                  k);                                   \
        }                                                               \
        static inline UNNEEDED type *name##_getmatch_(const struct name *ht, \
-                                        const HTABLE_KTYPE(keyof) k,   \
+                                        const HTABLE_KTYPE(keyof, type) k, \
                                         size_t h,                      \
                                         type *v,                       \
                                         struct name##_iter *iter)      \
                return v;                                               \
        }                                                               \
        static inline UNNEEDED type *name##_getfirst(const struct name *ht, \
-                                        const HTABLE_KTYPE(keyof) k,   \
+                                        const HTABLE_KTYPE(keyof, type) k, \
                                         struct name##_iter *iter)      \
        {                                                               \
                size_t h = hashfn(k);                                   \
                return name##_getmatch_(ht, k, h, v, iter);                     \
        }                                                               \
        static inline UNNEEDED type *name##_getnext(const struct name *ht, \
-                                        const HTABLE_KTYPE(keyof) k,   \
+                                        const HTABLE_KTYPE(keyof, type) k, \
                                         struct name##_iter *iter)      \
        {                                                               \
                size_t h = hashfn(k);                                   \
                return name##_getmatch_(ht, k, h, v, iter);             \
        }                                                               \
        static inline UNNEEDED bool name##_delkey(struct name *ht,      \
-                                        const HTABLE_KTYPE(keyof) k)   \
+                                        const HTABLE_KTYPE(keyof, type) k) \
        {                                                               \
                type *elem = name##_get(ht, k);                         \
                if (elem)                                               \
        }
 
 #if HAVE_TYPEOF
-#define HTABLE_KTYPE(keyof) typeof(keyof(NULL))
+#define HTABLE_KTYPE(keyof, type) typeof(keyof((const type *)NULL))
 #else
-#define HTABLE_KTYPE(keyof) void *
+#define HTABLE_KTYPE(keyof, type) void *
 #endif
 #endif /* CCAN_HTABLE_TYPE_H */