[libvirt] [PATCH 0/6] Some '#pragma once' conversions

danpb added a BiteSizedTask for '#pragma once' conversions https://wiki.libvirt.org/page/BiteSizedTasks#Switch_headers_to_use_.23pragma... We don't currently have any usage in the code. Turns out we need some syntax check tweaks to make things happy. This series fixes those, and adds a few conversion examples. Tested on Fedora30 and freebsd12.0 with nodedev hal driver build Cole Robinson (6): build-aux: header-ifdef: Fix typos build-aux: header-ifdef: Handle #pragma once node_device_driver.h: Use #pragma once node_device_udev.h: Use #pragma once node_device_hal.h: Use #pragma once vircgrouppriv.h: Use #pragma once build-aux/header-ifdef.pl | 11 ++++++++--- src/node_device/node_device_driver.h | 21 +++++++++------------ src/node_device/node_device_hal.h | 5 +---- src/node_device/node_device_udev.h | 13 +++++-------- src/util/vircgrouppriv.h | 9 +++------ 5 files changed, 26 insertions(+), 33 deletions(-) -- 2.21.0

Signed-off-by: Cole Robinson <crobinso@redhat.com> --- build-aux/header-ifdef.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-aux/header-ifdef.pl b/build-aux/header-ifdef.pl index ccabf14055..297696eb70 100644 --- a/build-aux/header-ifdef.pl +++ b/build-aux/header-ifdef.pl @@ -106,7 +106,7 @@ while (<>) { } } elsif ($state == $STATE_PRIV_START) { if (/^$/) { - &mistake("$file: too many blank lines after coyright header"); + &mistake("$file: too many blank lines after copyright header"); } elsif (/#ifndef $ifdefpriv$/) { $state = $STATE_PRIV_ERROR; } else { @@ -116,7 +116,7 @@ while (<>) { if (/# error ".*"$/) { $state = $STATE_PRIV_END; } else { - &mistake("$file: missing '#error ...priv allow...'"); + &mistake("$file: missing '# error ...priv allow...'"); } } elsif ($state == $STATE_PRIV_END) { if (m,#endif /\* $ifdefpriv \*/,) { @@ -131,7 +131,7 @@ while (<>) { $state = $STATE_GUARD_START; } elsif ($state == $STATE_GUARD_START) { if (/^$/) { - &mistake("$file: too many blank lines after coyright header"); + &mistake("$file: too many blank lines after copyright header"); } elsif (/#ifndef $ifdef$/) { $state = $STATE_GUARD_DEFINE; } else { -- 2.21.0

If we see if, skip all remaining header guard checks Signed-off-by: Cole Robinson <crobinso@redhat.com> --- build-aux/header-ifdef.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build-aux/header-ifdef.pl b/build-aux/header-ifdef.pl index 297696eb70..401f25fb81 100644 --- a/build-aux/header-ifdef.pl +++ b/build-aux/header-ifdef.pl @@ -32,6 +32,7 @@ my $STATE_GUARD_START = 6; my $STATE_GUARD_DEFINE = 7; my $STATE_GUARD_END = 8; my $STATE_EOF = 9; +my $STATE_PRAGMA = 10; my $file = " "; my $ret = 0; @@ -132,6 +133,8 @@ 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; } else { @@ -147,6 +150,8 @@ while (<>) { if (m,#endif /\* $ifdef \*/$,) { $state = $STATE_EOF; } + } elsif ($state == $STATE_PRAGMA) { + next; } elsif ($state == $STATE_EOF) { die "$file: unexpected content after '#endif /* $ifdef */'"; } else { -- 2.21.0

On 4/3/19 4:52 PM, Cole Robinson wrote:
If we see if, skip all remaining header guard checks
s/see if/see it/
Signed-off-by: Cole Robinson <crobinso@redhat.com> --- build-aux/header-ifdef.pl | 5 +++++ 1 file changed, 5 insertions(+)
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org

Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/node_device/node_device_driver.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h index 5876671c03..eae5e2cb17 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -19,24 +19,23 @@ * <http://www.gnu.org/licenses/>. */ -#ifndef LIBVIRT_NODE_DEVICE_DRIVER_H -# define LIBVIRT_NODE_DEVICE_DRIVER_H +#pragma once -# include "internal.h" -# include "driver.h" -# include "virnodedeviceobj.h" +#include "internal.h" +#include "driver.h" +#include "virnodedeviceobj.h" -# define LINUX_NEW_DEVICE_WAIT_TIME 60 +#define LINUX_NEW_DEVICE_WAIT_TIME 60 -# ifdef WITH_HAL +#ifdef WITH_HAL int halNodeRegister(void); -# endif +#endif -# ifdef WITH_UDEV +#ifdef WITH_UDEV int udevNodeRegister(void); -# endif +#endif void nodeDeviceLock(void); @@ -117,5 +116,3 @@ nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, int nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn, int callbackID); - -#endif /* LIBVIRT_NODE_DEVICE_DRIVER_H */ -- 2.21.0

Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/node_device/node_device_udev.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/node_device/node_device_udev.h b/src/node_device/node_device_udev.h index 8c1d8fec1d..996677dfe0 100644 --- a/src/node_device/node_device_udev.h +++ b/src/node_device/node_device_udev.h @@ -18,13 +18,10 @@ * <http://www.gnu.org/licenses/>. */ -#ifndef LIBVIRT_NODE_DEVICE_UDEV_H -# define LIBVIRT_NODE_DEVICE_UDEV_H +#pragma once -# include <libudev.h> +#include <libudev.h> -# define SYSFS_DATA_SIZE 4096 -# define DMI_DEVPATH "/sys/devices/virtual/dmi/id" -# define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id" - -#endif /* LIBVIRT_NODE_DEVICE_UDEV_H */ +#define SYSFS_DATA_SIZE 4096 +#define DMI_DEVPATH "/sys/devices/virtual/dmi/id" +#define DMI_DEVPATH_FALLBACK "/sys/class/dmi/id" -- 2.21.0

Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/node_device/node_device_hal.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/node_device/node_device_hal.h b/src/node_device/node_device_hal.h index ffcf0c84e6..5e9c25ae34 100644 --- a/src/node_device/node_device_hal.h +++ b/src/node_device/node_device_hal.h @@ -19,7 +19,4 @@ * */ -#ifndef LIBVIRT_NODE_DEVICE_HAL_H -# define LIBVIRT_NODE_DEVICE_HAL_H - -#endif /* LIBVIRT_NODE_DEVICE_HAL_H */ +#pragma once -- 2.21.0

Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/util/vircgrouppriv.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index a6fb3bb9f8..9110c77297 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -23,11 +23,10 @@ # error "vircgrouppriv.h may only be included by vircgroup.c or its test suite" #endif /* LIBVIRT_VIRCGROUPPRIV_H_ALLOW */ -#ifndef LIBVIRT_VIRCGROUPPRIV_H -# define LIBVIRT_VIRCGROUPPRIV_H +#pragma once -# include "vircgroup.h" -# include "vircgroupbackend.h" +#include "vircgroup.h" +#include "vircgroupbackend.h" struct _virCgroupV1Controller { int type; @@ -127,5 +126,3 @@ int virCgroupKillRecursiveInternal(virCgroupPtr group, int controller, const char *taskFile, bool dormdir); - -#endif /* LIBVIRT_VIRCGROUPPRIV_H */ -- 2.21.0
participants (2)
-
Cole Robinson
-
Eric Blake