]> git.ozlabs.org Git - ccan/commitdiff
htable: Mark functions constructed by HTABLE_DEFINE_TYPE as UNNEEDED
authorDavid Gibson <david@gibson.dropbear.id.au>
Wed, 27 Jan 2016 13:06:02 +0000 (00:06 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Tue, 2 Feb 2016 12:00:06 +0000 (23:00 +1100)
The HTABLE_DEFINE_TYPE macro builds a type-specific hash table by
constructing a bunch of simple wrapper functions.  The user of the hash
table may not end up using all of these.  With gcc the fact that the
functions are inline stops an warnings about unused functions, but that's
not the case with clang.

Suppress these warnings by marking all the constructed functions except
for name##_add() as UNNEEDED (using the macro from ccan/compiler).  _add
is left alone on the grounds that a hash table you never add anything to
isn't much use, so this will help you to spot an entirely redundant
HTABLE_DEFINE_TYPE invocation.  *_init() would be a more obvious choice,
except that there is both *_init() and *_init_sized() and you only need
to use one of these.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/htable/htable_type.h

index ad3974c5e446dc74be147371d74dafb09feea631..6764c3f24ae103c8bccbcc8949c283ff56dcca1e 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef CCAN_HTABLE_TYPE_H
 #define CCAN_HTABLE_TYPE_H
 #include <ccan/htable/htable.h>
+#include <ccan/compiler/compiler.h>
 #include "config.h"
 
 /**
        {                                                               \
                return hashfn(keyof((const type *)elem));               \
        }                                                               \
-       static inline void name##_init(struct name *ht)                 \
+       static inline UNNEEDED void name##_init(struct name *ht)        \
        {                                                               \
                htable_init(&ht->raw, name##_hash, NULL);               \
        }                                                               \
-       static inline void name##_init_sized(struct name *ht, size_t s) \
+       static inline UNNEEDED void name##_init_sized(struct name *ht,  \
+                                                     size_t s)         \
        {                                                               \
                htable_init_sized(&ht->raw, name##_hash, NULL, s);      \
        }                                                               \
-       static inline void name##_clear(struct name *ht)                \
+       static inline UNNEEDED void name##_clear(struct name *ht)       \
        {                                                               \
                htable_clear(&ht->raw);                                 \
        }                                                               \
        {                                                               \
                return htable_add(&ht->raw, hashfn(keyof(elem)), elem); \
        }                                                               \
-       static inline bool name##_del(struct name *ht, const type *elem) \
+       static inline UNNEEDED bool name##_del(struct name *ht,         \
+                                              const type *elem)        \
        {                                                               \
                return htable_del(&ht->raw, hashfn(keyof(elem)), elem); \
        }                                                               \
-       static inline type *name##_get(const struct name *ht,           \
+       static inline UNNEEDED type *name##_get(const struct name *ht,  \
                                       const HTABLE_KTYPE(keyof) k)     \
        {                                                               \
                /* Typecheck for eqfn */                                \
@@ -81,7 +84,7 @@
                                  (bool (*)(const void *, void *))(eqfn), \
                                  k);                                   \
        }                                                               \
-       static inline bool name##_delkey(struct name *ht,               \
+       static inline UNNEEDED bool name##_delkey(struct name *ht,      \
                                         const HTABLE_KTYPE(keyof) k)   \
        {                                                               \
                type *elem = name##_get(ht, k);                         \
                        return name##_del(ht, elem);                    \
                return false;                                           \
        }                                                               \
-       static inline type *name##_first(const struct name *ht,         \
+       static inline UNNEEDED type *name##_first(const struct name *ht, \
                                         struct name##_iter *iter)      \
        {                                                               \
                return htable_first(&ht->raw, &iter->i);                \
        }                                                               \
-       static inline type *name##_next(const struct name *ht,          \
+       static inline UNNEEDED type *name##_next(const struct name *ht, \
                                        struct name##_iter *iter)       \
        {                                                               \
                return htable_next(&ht->raw, &iter->i);                 \