git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] commit-slab: declare functions "static inline"

From
Thomas Rast <tr@thomasrast.ch>
Date
Nov 25, 2013, 20:04 UTC
Message-ID
<89b534b37f5689a675f0f97d3627a0668ce2a71d.1385409724.git.tr@thomasrast.ch>
In-Reply-To
<878uwc2r7c.fsf@thomasrast.ch>

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 we need two declarations of the same variable.

Signed-off-by: Thomas Rast <tr@thomasrast.ch>
---
Here's a version that has a fat comment instead of the removal.

Also, since I was rerolling anyway I put a reason why we need this. In the original motivation I actually created more functions afterwards, which made it more convincing, but the problem already exists.

 commit-slab.h | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/commit-slab.h b/commit-slab.h
index d77aaea..21d54f1 100644
--- a/commit-slab.h
+++ b/commit-slab.h
@@ -45,8 +45,8 @@ struct slabname {							\
 };									\
 static int stat_ ##slabname## realloc;					\
 									\
-static void init_ ##slabname## _with_stride(struct slabname *s,		\
-					    unsigned stride)		\
+static inline void init_ ##slabname## _with_stride(struct slabname *s,	\
+						   unsigned stride)	\
 {									\
 	unsigned int elem_size;						\
 	if (!stride)							\
@@ -58,12 +58,12 @@ struct slabname {							\
 	s->slab = NULL;							\
 }									\
 									\
-static void init_ ##slabname(struct slabname *s)			\
+static inline void init_ ##slabname(struct slabname *s)			\
 {									\
 	init_ ##slabname## _with_stride(s, 1);				\
 }									\
 									\
-static void clear_ ##slabname(struct slabname *s)			\
+static inline void clear_ ##slabname(struct slabname *s)		\
 {									\
 	int i;								\
 	for (i = 0; i < s->slab_count; i++)				\
@@ -73,8 +73,8 @@ struct slabname {							\
 	s->slab = NULL;							\
 }									\
 									\
-static elemtype *slabname## _at(struct slabname *s,			\
-				const struct commit *c)			\
+static inline elemtype *slabname## _at(struct slabname *s,		\
+				       const struct commit *c)		\
 {									\
 	int nth_slab, nth_slot;						\
 									\
@@ -98,4 +98,16 @@ struct slabname {							\
 									\
 static int stat_ ##slabname## realloc
 
+/*
+ * Note that this seemingly redundant second declaration is required
+ * to allow a terminating semicolon, which makes instantiations look
+ * like function declarations.  I.e., the expansion of
+ *
+ *    define_commit_slab(indegree, int);
+ *
+ * ends in 'static int stat_indegreerealloc;'.  This would otherwise
+ * be a syntax error according (at least) to ISO C.  It's hard to
+ * catch because GCC silently parses it by default.
+ */
+
 #endif /* COMMIT_SLAB_H */
-- 
1.8.5.rc2.355.g6969a19
Previous: Thomas RastNext: Jonathan Nieder
Message 10 of 18 in “commit-slab cleanups”
  1. 0/2 commit-slab cleanupsThomas Rast, Nov 25, 2013
  2. 1/2 commit-slab: document clear_$slabname()Thomas Rast, Nov 25, 2013
  3. Jonathan NiederNov 25, 2013
  4. Thomas RastNov 29, 2013
  5. Junio C HamanoNov 25, 2013
  6. Eric SunshineNov 27, 2013
  7. 2/2 commit-slab: declare functions "static inline"Thomas Rast, Nov 25, 2013
  8. Junio C HamanoNov 25, 2013
  9. Thomas RastNov 25, 2013
  10. commit-slab: declare functions "static inline"Thomas Rast, Nov 25, 2013
  11. Jonathan NiederNov 25, 2013
  12. Thomas RastNov 25, 2013
  13. Jonathan NiederNov 25, 2013
  14. Junio C HamanoNov 25, 2013
  15. Junio C HamanoNov 25, 2013
  16. Duy NguyenDec 1, 2013
  17. commit-slab: sizeof() the right type in xreallocThomas Rast, Dec 1, 2013
  18. Jeff KingDec 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.