[libvirt] [PATCH 46/46] syntax check: update header guard check
Ján Tomko
jtomko at redhat.com
Wed Jun 19 15:11:47 UTC 2019
On Tue, Jun 18, 2019 at 11:13:16AM -0500, Jonathon Jongsma wrote:
>Internal headers should use #pragma once instead of the standard #ifndef
>guard. Public headers still require the existing header guard.
>
>Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
>---
> build-aux/header-ifdef.pl | 35 ++++++++++++++++++++++++++---------
> 1 file changed, 26 insertions(+), 9 deletions(-)
>
>diff --git a/build-aux/header-ifdef.pl b/build-aux/header-ifdef.pl
>index 401f25fb81..d63aae779b 100644
>--- a/build-aux/header-ifdef.pl
>+++ b/build-aux/header-ifdef.pl
>@@ -6,18 +6,26 @@
> # ...copyright header...
> # */
> # <one blank line>
>-# #ifndef SYMBOL
>-# # define SYMBOL
>+# #pragma once
> # ....content....
>-# #endif /* SYMBOL */
> #
>-# For any file ending priv.h, before the #ifndef
>+#---
>+#
>+# For any file ending priv.h, before the #pragma once
> # We will have a further section
> #
> # #ifndef SYMBOL_ALLOW
> # # error ....
> # #endif /* SYMBOL_ALLOW */
> # <one blank line>
>+#
>+#---
>+#
>+# For public headers (files in include/), use the standard header guard instead of #pragma once:
>+# #ifndef SYMBOL
>+# # define SYMBOL
>+# ....content....
>+# #endif /* SYMBOL */
>
> use strict;
> use warnings;
>@@ -38,6 +46,7 @@ my $file = " ";
> my $ret = 0;
> my $ifdef = "";
> my $ifdefpriv = "";
>+my $publicheader = 0;
>
> my $state = $STATE_EOF;
> my $mistake = 0;
>@@ -83,6 +92,7 @@ while (<>) {
> $file = $ARGV;
> $state = $STATE_COPYRIGHT_COMMENT;
> $mistake = 0;
>+ $publicheader = ($ARGV =~ /\/include\//);
The comment above says include/ but this checks for /include/, breaking
the check for me.
Also, the error messages above this code will need tuning - if I delete
everything from qemu_command.h starting with '#pragma once', I get the
wrong error:
src/qemu/qemu_command.h: missing '#ifndef LIBVIRT_QEMU_COMMAND_H' at ./build-aux/header-ifdef.pl line 56, <> line 32534.
> }
>
> if ($mistake ||
>@@ -133,12 +143,19 @@ while (<>) {
> } elsif ($state == $STATE_GUARD_START) {
> if (/^$/) {
> &mistake("$file: too many blank lines after copyright header");
>- } elsif(/#pragma once/) {
>- $state = $STATE_PRAGMA;
>- } elsif (/#ifndef $ifdef$/) {
>- $state = $STATE_GUARD_DEFINE;
>+ }
>+ if ($publicheader) {
>+ if (/#ifndef $ifdef$/) {
>+ $state = $STATE_GUARD_DEFINE;
>+ } else {
>+ &mistake("$file: missing '#ifndef $ifdef'");
>+ }
> } else {
>- &mistake("$file: missing '#ifndef $ifdef'");
>+ if(/#pragma once/) {
Missing space ^
Otherwise looks good.
Jano
>+ $state = $STATE_PRAGMA;
>+ } else {
>+ &mistake("$file: missing '#pragma once' header guard");
>+ }
> }
> } elsif ($state == $STATE_GUARD_DEFINE) {
> if (/# define $ifdef$/) {
>--
>2.20.1
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190619/17305f16/attachment-0001.sig>
More information about the libvir-list
mailing list