Vim treats *.h files as cpp ones with respect to syntax highlighting.
Thus "class" in _virNodeDevCapPCIDev highlighted mistakenly.
This can be fixed by filetype detection code tunables but it
is more convinient to skip this tuning by every project member.
Let's just use "klass" as field name instead of _class or class
and add syntax rule.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
---
cfg.mk | 8 ++++++++
src/conf/node_device_conf.c | 4 ++--
src/conf/node_device_conf.h | 4 ++--
src/node_device/node_device_udev.c | 4 ++--
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index f99b8ae631..88198037cc 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1075,6 +1075,14 @@ sc_require_attribute_cleanup_initialization:
halt='variable declared with a cleanup macro must be initialized' \
$(_sc_search_regexp)
+# "class" in headers is not good because by default Vim treats it as a keyword
+sc_prohibit_class_in_headers:
+ @prohibit=' +_?class *;' \
+ in_vc_files='\.h$$' \
+ halt='use klass instead of class or _class as name in header files' \
+ $(_sc_search_regexp)
+
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 1b1f57d065..5de51d1f6b 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -346,7 +346,7 @@ virNodeDeviceCapUSBInterfaceDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<number>%d</number>\n",
data->usb_if.number);
virBufferAsprintf(buf, "<class>%d</class>\n",
- data->usb_if._class);
+ data->usb_if.klass);
virBufferAsprintf(buf, "<subclass>%d</subclass>\n",
data->usb_if.subclass);
virBufferAsprintf(buf, "<protocol>%d</protocol>\n",
@@ -1216,7 +1216,7 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt,
goto out;
if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt,
- &usb_if->_class, def,
+ &usb_if->klass, def,
_("no USB interface class supplied for '%s'"),
_("invalid USB interface class supplied for '%s'")) < 0)
goto out;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index ce789e9ee9..b13bc13b87 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -153,7 +153,7 @@ struct _virNodeDevCapPCIDev {
unsigned int function;
unsigned int product;
unsigned int vendor;
- unsigned int class;
+ unsigned int klass;
char *product_name;
char *vendor_name;
virPCIDeviceAddressPtr physical_function;
@@ -186,7 +186,7 @@ typedef struct _virNodeDevCapUSBIf virNodeDevCapUSBIf;
typedef virNodeDevCapUSBIf *virNodeDevCapUSBIfPtr;
struct _virNodeDevCapUSBIf {
unsigned int number;
- unsigned int _class; /* "class" is reserved in C */
+ unsigned int klass;
unsigned int subclass;
unsigned int protocol;
char *description;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 32e762009f..f0e61e4236 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -402,7 +402,7 @@ udevProcessPCI(struct udev_device *device,
privileged = driver->privileged;
nodeDeviceUnlock();
- if (udevGetUintProperty(device, "PCI_CLASS", &pci_dev->class, 16) < 0)
+ if (udevGetUintProperty(device, "PCI_CLASS", &pci_dev->klass, 16) < 0)
goto cleanup;
if ((p = strrchr(def->sysfs_path, '/')) == NULL ||
@@ -582,7 +582,7 @@ udevProcessUSBInterface(struct udev_device *device,
return -1;
if (udevGetUintSysfsAttr(device, "bInterfaceClass",
- &usb_if->_class, 16) < 0)
+ &usb_if->klass, 16) < 0)
return -1;
if (udevGetUintSysfsAttr(device, "bInterfaceSubClass",
--
2.16.5
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Mar 12, 2019 at 02:14:39PM +0300, Nikolay Shirokovskiy wrote: > Vim treats *.h files as cpp ones with respect to syntax highlighting. Surprised it doesn't use .hpp for C++ headers, but no matter. > Thus "class" in _virNodeDevCapPCIDev highlighted mistakenly. > This can be fixed by filetype detection code tunables but it > is more convinient to skip this tuning by every project member. > > Let's just use "klass" as field name instead of _class or class > and add syntax rule. I think that's good practice regardless of the vimm issue ! > > Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com> > --- > cfg.mk | 8 ++++++++ > src/conf/node_device_conf.c | 4 ++-- > src/conf/node_device_conf.h | 4 ++-- > src/node_device/node_device_udev.c | 4 ++-- > 4 files changed, 14 insertions(+), 6 deletions(-) > > diff --git a/cfg.mk b/cfg.mk > index f99b8ae631..88198037cc 100644 > --- a/cfg.mk > +++ b/cfg.mk > @@ -1075,6 +1075,14 @@ sc_require_attribute_cleanup_initialization: > halt='variable declared with a cleanup macro must be initialized' \ > $(_sc_search_regexp) > > +# "class" in headers is not good because by default Vim treats it as a keyword > +sc_prohibit_class_in_headers: > + @prohibit=' +_?class *;' \ > + in_vc_files='\.h$$' \ How about extending that rule to '.c' too. The .h check will cause most of the usage in .c files to be removed anyway, so might as well blacklist it explicitly in .c > + halt='use klass instead of class or _class as name in header files' \ > + $(_sc_search_regexp) > + > + > # We don't use this feature of maint.mk. > prev_version_file = /dev/null With or without the .c blacklist too Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.