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

Re: [PATCH 2/2] commit-slab: declare functions "static inline"

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 25, 2013, 19:36 UTC
Message-ID
<xmqqy54cxohs.fsf@gitster.dls.corp.google.com>
In-Reply-To
<f4d1ff9f487f797da35faa86c72d11832903a50d.1385405977.git.tr@thomasrast.ch>
Thomas Rast <tr@thomasrast.ch> writes:
> This shuts up compiler warnings about unused functions.
Thanks.
> While there, also remove the redundant second declaration of
> stat_##slabname##realloc.

I think the latter was done very much deliberately to allow the using code to say:

	define_commit_slab(name, type);

by ending the macro with something that requires a terminating semicolon. If you just remove it, doesn't it break the compilation by forcing the expanded source to define a function

	slabname ## _at(...)
        {
        	...
	};
with a trailing and undesired semicolon?
Show 58 quoted lines
>
> Signed-off-by: Thomas Rast <tr@thomasrast.ch>
> ---
>  commit-slab.h | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/commit-slab.h b/commit-slab.h
> index d77aaea..d5c353e 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;						\
>  									\
> @@ -94,8 +94,7 @@ struct slabname {							\
>  		s->slab[nth_slab] = xcalloc(s->slab_size,		\
>  					    sizeof(**s->slab) * s->stride);		\
>  	return &s->slab[nth_slab][nth_slot * s->stride];				\
> -}									\
> -									\
> -static int stat_ ##slabname## realloc
> +}
> +
>  
>  #endif /* COMMIT_SLAB_H */
Previous: Thomas RastNext: Thomas Rast
Message 8 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.