[ccan] [PATCH 2/5] htable: Mark functions constructed by HTABLE_DEFINE_TYPE as UNNEEDED
David Gibson
david at gibson.dropbear.id.au
Thu Jan 28 00:53:29 AEDT 2016
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 at gibson.dropbear.id.au>
---
ccan/htable/htable_type.h | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/ccan/htable/htable_type.h b/ccan/htable/htable_type.h
index ad3974c..6764c3f 100644
--- a/ccan/htable/htable_type.h
+++ b/ccan/htable/htable_type.h
@@ -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"
/**
@@ -50,15 +51,16 @@
{ \
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); \
} \
@@ -66,11 +68,12 @@
{ \
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); \
@@ -89,12 +92,12 @@
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); \
--
2.5.0
More information about the ccan
mailing list