scripts/checkpatch.pl: fix false error of externs checking.
PATCH 1/1 scripts/checkpatch.pl: fix false error of externs checking.
When adding a function declaration in a .c file without extern keywork decoration, checkpatch.pl will report *externs should be avoided in .c files* false error. This patch fixes the bug.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -2534,7 +2534,7 @@ sub process { # check for new externs in .c files. if ($realfile =~ /\.c$/ && defined $stat && - $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) + $stat =~ /^.\s*(?:extern\s+)$Type\s+($Ident)(\s*)\(/s) { my $function_name = $1; my $paren_space = $2;
Signature · 1 line
2.7.4
Quoted 3 lines · Jiang Biao
When adding a function declaration in a .c file without extern keywork decoration, checkpatch.pl will report *externs should be avoided in .c files* false error. This patch fixes the bug.
I don't think this is a bug. "extern int foo(void);" and "int foo(void);" have the same effect: they declare a function prototype that can be called from outside the file. We don't want to permit that in QEMU. Either:
(1) the function is for use only within this file: the declaration should be "static int foo(void);"
(2) the function is for use by other files too: the declaration should be in a header file, not a .c file, so the other files can use it
Do you have an example of code where this warning is a problem?
thanks
-- PMM
Re: [Qemu-devel] [PATCH] scripts/checkpatch.pl: fix false error ofexterns checking.
Quoted 17 lines · Jiang Biao
Quoted 5 lines
When adding a function declaration in a .c file without extern keywork decoration, checkpatch.pl will report *externs should be avoided in .c files* false error. This patch fixes the bug.
I don't think this is a bug. "extern int foo(void);" and "int foo(void);" have the same effect: they declare a function prototype that can be called from outside the file. We don't want to permit that in QEMU. Either:
(1) the function is for use only within this file: the declaration should be "static int foo(void);"
(2) the function is for use by other files too: the declaration should be in a header file, not a .c file, so the other files can use it
Quoted 1 line
Do you have an example of code where this warning is a problem?
Hi Peter,
I understand external functions should be put in header files. But there
is some rare exceptions, take the code segment in
tcg/mips/tcg-target.inc.c for example,
#if TCG_TARGET_REG_BITS == 32
# define LO_OFF (MIPS_BE * 4) # define HI_OFF (4 - LO_OFF) #else /* To assert at compile-time that these values are never used for TCG_TARGET_REG_BITS == 64. */ /* extern */ int link_error(void); # define LO_OFF link_error() # define HI_OFF link_error() #endif
In this case, the external funciton is just used to assert at complie-time.
If I make a patch to delete the commented out extern before *int link_error()*,
the checkpatch.pl will complain the *externs should be avoided in .c files*
error.
The same usage can also be found in tcg/tcg-op.c,
/* Reduce the number of ifdefs below. This assumes that all uses of
TCGV_HIGH and TCGV_LOW are properly protected by a conditional that the compiler can eliminate. */
#if TCG_TARGET_REG_BITS == 64
extern TCGv_i32 TCGV_LOW_link_error(TCGv_i64);
extern TCGv_i32 TCGV_HIGH_link_error(TCGv_i64);
#define TCGV_LOW TCGV_LOW_link_error
#define TCGV_HIGH TCGV_HIGH_link_error
#endif
I'm not sure if the checkpatch.pl should take these case into consideration. :)
Thanks.
Regards.