commit-slab: declare functions "static inline"
This shuts up compiler warnings about unused functions. No such warnings are currently triggered, but if someone were to actually use init_NAME_with_stride() as documented, they would get a warning about init_NAME() being unused. While there, write a comment about why the last real declaration of the variable is without a terminating semicolon, while another forward declarations have one. Signed-off-by: Thomas Rast <tr@thomasrast.ch> Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Nov 25, 2013 at 21:04 UTC
e9e03a77994f4bf030760e2644f718776de0eb39
1 file changed
+20
-6
commit-slab.h
+20
-6
@@ -40,6 +40,8 @@
40
#define COMMIT_SLAB_SIZE (512*1024-32)
41
#endif
42
43
+#define MAYBE_UNUSED __attribute__((__unused__))
44
+
45
#define define_commit_slab(slabname, elemtype) \
46
\
47
struct slabname { \
@@ -50,8 +52,8 @@ struct slabname { \
52
}; \
53
static int stat_ ##slabname## realloc; \
54
\
53
-static void init_ ##slabname## _with_stride(struct slabname *s, \
54
- unsigned stride) \
55
+static MAYBE_UNUSED void init_ ##slabname## _with_stride(struct slabname *s, \
56
+ unsigned stride) \
57
{ \
58
unsigned int elem_size; \
59
if (!stride) \
@@ -63,12 +65,12 @@ static void init_ ##slabname## _with_stride(struct slabname *s, \
65
s->slab = NULL; \
66
} \
67
\
66
-static void init_ ##slabname(struct slabname *s) \
68
+static MAYBE_UNUSED void init_ ##slabname(struct slabname *s) \
69
{ \
70
init_ ##slabname## _with_stride(s, 1); \
71
} \
72
\
71
-static void clear_ ##slabname(struct slabname *s) \
73
+static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
74
{ \
75
int i; \
76
for (i = 0; i < s->slab_count; i++) \
@@ -78,8 +80,8 @@ static void clear_ ##slabname(struct slabname *s) \
80
s->slab = NULL; \
81
} \
82
\
81
-static elemtype *slabname## _at(struct slabname *s, \
82
- const struct commit *c) \
83
+static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
84
+ const struct commit *c) \
85
{ \
86
int nth_slab, nth_slot; \
87
\
@@ -103,4 +105,16 @@ static elemtype *slabname## _at(struct slabname *s, \
105
\
106
static int stat_ ##slabname## realloc
107
108
+/*
109
+ * Note that this seemingly redundant second declaration is required
110
+ * to allow a terminating semicolon, which makes instantiations look
111
+ * like function declarations. I.e., the expansion of
112
+ *
113
+ * define_commit_slab(indegree, int);
114
+ *
115
+ * ends in 'static int stat_indegreerealloc;'. This would otherwise
116
+ * be a syntax error according (at least) to ISO C. It's hard to
117
+ * catch because GCC silently parses it by default.
118
+ */
119
+
120
#endif /* COMMIT_SLAB_H */