The compiler might optimize based on our declaration that something
is unused. Putting that declaration in the header risks getting
out of sync with the actual implementation, so it belongs better
only in the .c files. We were mostly compliant, and a new syntax
check will help us in the future.
* cfg.mk (sc_avoic_attribute_unused_in_header): New syntax check.
* src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Delete
attribute already present in .c file.
* src/qemu/qemu_domain.h (qemuDomainEventFlush): Likewise.
* src/util/virterror_internal.h (virReportErrorHelper): Parameters
are actually used by .c file.
* src/xenxs/xen_sxpr.h (xenFormatSxprDisk): Adjust prototype.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk): Delete unused argument.
(xenFormatSxpr): Adjust caller.
* src/xen/xend_internal.c (xenDaemonAttachDeviceFlags)
(xenDaemonUpdateDeviceFlags): Likewise.
Suggested by Daniel Veillard.
---
As suggested here:
https://www.redhat.com/archives/libvir-list/2011-July/msg00501.html
cfg.mk | 8 ++++++++
src/nodeinfo.h | 4 ++--
src/qemu/qemu_domain.h | 2 +-
src/util/virterror_internal.h | 8 ++++----
src/xen/xend_internal.c | 12 +++++-------
src/xenxs/xen_sxpr.c | 5 ++---
src/xenxs/xen_sxpr.h | 3 +--
7 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index a9ee9ea..ffecc50 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -432,6 +432,14 @@ sc_prohibit_xmlGetProp:
halt='use virXMLPropString, not xmlGetProp' \
$(_sc_search_regexp)
+# ATTRIBUTE_UNUSED should only be applied in implementations, not
+# header declarations
+sc_avoid_attribute_unused_in_header:
+ @prohibit='^[^#]*ATTRIBUTE_UNUSED([^:]|$$)' \
+ in_vc_files='\.h$$' \
+ halt='use ATTRIBUTE_UNUSED in .c rather than .h files' \
+ $(_sc_search_regexp)
+
# Many of the function names below came from this filter:
# git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]*
?\(.*[,;]$' \
# |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index e5ac1e0..4766152 100644
--- a/src/nodeinfo.h
+++ b/src/nodeinfo.h
@@ -30,12 +30,12 @@
int nodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo);
int nodeCapsInitNUMA(virCapsPtr caps);
-int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
+int nodeGetCPUStats(virConnectPtr conn,
int cpuNum,
virNodeCPUStatsPtr params,
int *nparams,
unsigned int flags);
-int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
+int nodeGetMemoryStats(virConnectPtr conn,
int cellNum,
virNodeMemoryStatsPtr params,
int *nparams,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 794eef7..ba3afc5 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -101,7 +101,7 @@ struct qemuDomainWatchdogEvent
int action;
};
-void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque);
+void qemuDomainEventFlush(int timer, void *opaque);
/* driver must be locked before calling */
void qemuDomainEventQueue(struct qemud_driver *driver,
diff --git a/src/util/virterror_internal.h b/src/util/virterror_internal.h
index df4b1d2..d61ea0d 100644
--- a/src/util/virterror_internal.h
+++ b/src/util/virterror_internal.h
@@ -1,7 +1,7 @@
/*
* virterror.h: internal error handling
*
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2009, 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -56,9 +56,9 @@ void virRaiseErrorFull(const char *filename,
const char *virErrorMsg(virErrorNumber error, const char *info);
void virReportErrorHelper(int domcode, int errcode,
- const char *filename ATTRIBUTE_UNUSED,
- const char *funcname ATTRIBUTE_UNUSED,
- size_t linenr ATTRIBUTE_UNUSED,
+ const char *filename,
+ const char *funcname,
+ size_t linenr,
const char *fmt, ...)
ATTRIBUTE_FMT_PRINTF(6, 7);
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 17be97e..0cb36bb 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2726,11 +2726,10 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
- if (xenFormatSxprDisk(domain->conn,
- dev->data.disk,
- &buf,
- STREQ(def->os.type, "hvm") ? 1 : 0,
- priv->xendConfigVersion, 1) < 0)
+ if (xenFormatSxprDisk(dev->data.disk,
+ &buf,
+ STREQ(def->os.type, "hvm") ? 1 : 0,
+ priv->xendConfigVersion, 1) < 0)
goto cleanup;
if (dev->data.disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
@@ -2896,8 +2895,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
- if (xenFormatSxprDisk(domain->conn,
- dev->data.disk,
+ if (xenFormatSxprDisk(dev->data.disk,
&buf,
STREQ(def->os.type, "hvm") ? 1 : 0,
priv->xendConfigVersion, 1) < 0)
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 13ca015..0b0267c 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -1605,8 +1605,7 @@ xenFormatSxprChr(virDomainChrDefPtr def,
* Returns 0 in case of success, -1 in case of error.
*/
int
-xenFormatSxprDisk(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainDiskDefPtr def,
+xenFormatSxprDisk(virDomainDiskDefPtr def,
virBufferPtr buf,
int hvm,
int xendConfigVersion,
@@ -2264,7 +2263,7 @@ xenFormatSxpr(virConnectPtr conn,
}
for (i = 0 ; i < def->ndisks ; i++)
- if (xenFormatSxprDisk(conn, def->disks[i],
+ if (xenFormatSxprDisk(def->disks[i],
&buf, hvm, xendConfigVersion, 0) < 0)
goto error;
diff --git a/src/xenxs/xen_sxpr.h b/src/xenxs/xen_sxpr.h
index b2f8790..a66c60a 100644
--- a/src/xenxs/xen_sxpr.h
+++ b/src/xenxs/xen_sxpr.h
@@ -46,8 +46,7 @@ int xenParseSxprSound(virDomainDefPtr def, const char *str);
virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty);
-int xenFormatSxprDisk(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainDiskDefPtr def, virBufferPtr buf, int hvm,
+int xenFormatSxprDisk(virDomainDiskDefPtr def, virBufferPtr buf, int hvm,
int xendConfigVersion, int isAttach);
int xenFormatSxprNet(virConnectPtr conn,
--
1.7.4.4