Commit af920e36 authored by Johannes Sixt's avatar Johannes Sixt Committed by Junio C Hamano

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: default avatarJohannes Sixt <j6t@kdbg.org>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent dc29ddeb
......@@ -102,16 +102,16 @@ static MAYBE_UNUSED elemtype *slabname## _at(struct slabname *s, \
return &s->slab[nth_slab][nth_slot * s->stride]; \
} \
\
static int stat_ ##slabname## realloc
struct slabname
/*
* Note that this seemingly redundant second declaration is required
* Note that this redundant forward 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
* ends in 'struct indegree;'. 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.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment