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

2013-12-01 Thread Duy Nguyen
Thomas,

As you're touching this, perhaps you coud fix this line in slabname_at() too?

s->slab = xrealloc(s->slab, (nth_slab + 1) * sizeof(s->slab));

I think it should be sizeof(*s->slab), not sizeof(s->slab), even
though the end result is the same.
-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-11-25 Thread Thomas Rast
Junio C Hamano  writes:

> Thomas Rast  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?

Oooh.  The sudden enlightenment.

-- 
Thomas Rast
t...@thomasrast.ch
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-11-25 Thread Junio C Hamano
Thomas Rast  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?

>
> Signed-off-by: Thomas Rast 
> ---
>  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 */
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-11-25 Thread Thomas Rast
This shuts up compiler warnings about unused functions.

While there, also remove the redundant second declaration of
stat_##slabname##realloc.

Signed-off-by: Thomas Rast 
---
 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 */
-- 
1.8.5.rc3.397.g2a3acd5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html