Skip to content

Commit e9e03a7

Browse files
trastgitster
authored andcommitted
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>
1 parent dcbbc8f commit e9e03a7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

commit-slab.h

+20-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define COMMIT_SLAB_SIZE (512*1024-32)
4141
#endif
4242

43+
#define MAYBE_UNUSED __attribute__((__unused__))
44+
4345
#define define_commit_slab(slabname, elemtype) \
4446
\
4547
struct slabname { \
@@ -50,8 +52,8 @@ struct slabname { \
5052
}; \
5153
static int stat_ ##slabname## realloc; \
5254
\
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) \
5557
{ \
5658
unsigned int elem_size; \
5759
if (!stride) \
@@ -63,12 +65,12 @@ static void init_ ##slabname## _with_stride(struct slabname *s, \
6365
s->slab = NULL; \
6466
} \
6567
\
66-
static void init_ ##slabname(struct slabname *s) \
68+
static MAYBE_UNUSED void init_ ##slabname(struct slabname *s) \
6769
{ \
6870
init_ ##slabname## _with_stride(s, 1); \
6971
} \
7072
\
71-
static void clear_ ##slabname(struct slabname *s) \
73+
static MAYBE_UNUSED void clear_ ##slabname(struct slabname *s) \
7274
{ \
7375
int i; \
7476
for (i = 0; i < s->slab_count; i++) \
@@ -78,8 +80,8 @@ static void clear_ ##slabname(struct slabname *s) \
7880
s->slab = NULL; \
7981
} \
8082
\
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) \
8385
{ \
8486
int nth_slab, nth_slot; \
8587
\
@@ -103,4 +105,16 @@ static elemtype *slabname## _at(struct slabname *s, \
103105
\
104106
static int stat_ ##slabname## realloc
105107

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+
106120
#endif /* COMMIT_SLAB_H */

0 commit comments

Comments
 (0)