commit-slab.h: avoid duplicated global static variables

The gigantic define_commit_slab() macro repeats the definition of a static variable that occurs earlier in the macro text. The purpose of the repeated definition at the end of the macro is that it takes the semicolon that occurs where the macro is used. We cannot just remove the first definition of the variable because it is referenced elsewhere in the macro text, and defining the macro later would produce undefined identifier errors. We cannot have a "forward" declaration, either. (This works only with "extern" global variables.) The solution is to use a declaration of a struct that is already defined earlier. This language construct can serve the same purpose as the duplicated static variable definition, but without the confusion. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Aug 9, 2016 at 16:17 UTC af920e369778a4cc42519ef523131d29451bf79b
1 file changed +3 -3
commit-slab.h
+3 -3
@@ -102,16 +102,16 @@ static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
102 return &s->slab[nth_slab][nth_slot * s->stride]; \
103 } \
104 \
105 -static int stat_ ##slabname## realloc
105 +struct slabname
106
107 /*
108 - * Note that this seemingly redundant second declaration is required
108 + * Note that this redundant forward declaration is required
109 * to allow a terminating semicolon, which makes instantiations look
110 * like function declarations. I.e., the expansion of
111 *
112 * define_commit_slab(indegree, int);
113 *
114 - * ends in 'static int stat_indegreerealloc;'. This would otherwise
114 + * ends in 'struct indegree;'. This would otherwise
115 * be a syntax error according (at least) to ISO C. It's hard to
116 * catch because GCC silently parses it by default.
117 */