提交 088473b2 编写于 作者: E Eric Blake

build: avoid ATTRIBUTE_UNUSED in headers

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_avoid_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.
上级 3349f2bb
......@@ -413,6 +413,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 \
......
......@@ -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,
......
......@@ -146,7 +146,7 @@ const char *qemuDomainAsyncJobPhaseToString(enum qemuDomainAsyncJob job,
int qemuDomainAsyncJobPhaseFromString(enum qemuDomainAsyncJob job,
const char *phase);
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,
......
/*
* 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);
......
......@@ -2717,11 +2717,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) {
......@@ -2887,8 +2886,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)
......
......@@ -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,
......@@ -2270,7 +2269,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;
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册