[libvirt] [PATCH 0/2] More semicolon cleanups

In response to: https://www.redhat.com/archives/libvir-list/2013-May/msg01791.html Eric Blake (2): syntax: prefer space after semicolon in for loop syntax-check: mandate space after mid-line semicolon HACKING | 23 +++++++++++++++++++++++ build-aux/bracket-spacing.pl | 12 ++++++++++++ cfg.mk | 2 +- docs/hacking.html.in | 29 +++++++++++++++++++++++++++++ examples/domsuspend/suspend.c | 2 +- python/libvirt-override.c | 38 +++++++++++++++++++------------------- src/conf/interface_conf.c | 14 +++++++------- src/security/virt-aa-helper.c | 2 +- src/util/virconf.c | 4 ++-- src/util/virhook.c | 2 +- src/util/virlog.c | 10 +++++----- src/util/virsocketaddr.c | 12 ++++++------ src/util/virsysinfo.c | 4 ++-- src/util/viruuid.c | 4 ++-- src/vbox/vbox_tmpl.c | 11 ++++++++--- src/xen/xen_hypervisor.c | 3 ++- tools/virsh-domain-monitor.c | 6 +++--- tools/virsh-domain.c | 6 +++--- 18 files changed, 127 insertions(+), 57 deletions(-) -- 1.8.1.4

I noticed several unusual spacings in for loops, and decided to fix them up. See the next commit for the syntax check that found all of these. * examples/domsuspend/suspend.c (main): Fix spacing. * python/libvirt-override.c: Likewise. * src/conf/interface_conf.c: Likewise. * src/security/virt-aa-helper.c: Likewise. * src/util/virconf.c: Likewise. * src/util/virhook.c: Likewise. * src/util/virlog.c: Likewise. * src/util/virsocketaddr.c: Likewise. * src/util/virsysinfo.c: Likewise. * src/util/viruuid.c: Likewise. * src/vbox/vbox_tmpl.c: Likewise. * src/xen/xen_hypervisor.c: Likewise. * tools/virsh-domain-monitor.c (vshDomainStateToString): Drop default case, to let compiler check us. * tools/virsh-domain.c (vshDomainVcpuStateToString): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- examples/domsuspend/suspend.c | 2 +- python/libvirt-override.c | 38 +++++++++++++++++++------------------- src/conf/interface_conf.c | 14 +++++++------- src/security/virt-aa-helper.c | 2 +- src/util/virconf.c | 4 ++-- src/util/virhook.c | 2 +- src/util/virlog.c | 10 +++++----- src/util/virsocketaddr.c | 12 ++++++------ src/util/virsysinfo.c | 4 ++-- src/util/viruuid.c | 4 ++-- src/vbox/vbox_tmpl.c | 11 ++++++++--- src/xen/xen_hypervisor.c | 3 ++- tools/virsh-domain-monitor.c | 6 +++--- tools/virsh-domain.c | 6 +++--- 14 files changed, 62 insertions(+), 56 deletions(-) diff --git a/examples/domsuspend/suspend.c b/examples/domsuspend/suspend.c index a6311d1..d9f56bb 100644 --- a/examples/domsuspend/suspend.c +++ b/examples/domsuspend/suspend.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Failed to list the domains\n"); goto error; } - for (j = 0;j < i;j++) { + for (j = 0; j < i; j++) { if (ids[j] != 0) { id = ids[j]; break; diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 6ed2624..b6462c2 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -2176,7 +2176,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (ids) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); } VIR_FREE(ids); @@ -2266,7 +2266,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -2745,7 +2745,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -2790,7 +2790,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -2997,7 +2997,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg return VIR_PY_NONE; } py_retval = PyList_New(c_retval); - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_longlongWrap((long long) freeMems[i])); } @@ -3165,7 +3165,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (py_retval == NULL) { if (names) { - for (i = 0;i < c_retval;i++) + for (i = 0; i < c_retval; i++) VIR_FREE(names[i]); VIR_FREE(names); } @@ -3173,7 +3173,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED, } if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -3218,7 +3218,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (py_retval == NULL) { if (names) { - for (i = 0;i < c_retval;i++) + for (i = 0; i < c_retval; i++) VIR_FREE(names[i]); VIR_FREE(names); } @@ -3226,7 +3226,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED, } if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -3317,7 +3317,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (py_retval == NULL) { if (names) { - for (i = 0;i < c_retval;i++) + for (i = 0; i < c_retval; i++) VIR_FREE(names[i]); VIR_FREE(names); } @@ -3325,7 +3325,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED, } if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -3578,7 +3578,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -3668,7 +3668,7 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -3787,7 +3787,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (uuids) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i])); VIR_FREE(uuids[i]); } @@ -4006,7 +4006,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (uuids) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i])); VIR_FREE(uuids[i]); } @@ -4097,7 +4097,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (py_retval == NULL) { if (names) { - for (i = 0;i < c_retval;i++) + for (i = 0; i < c_retval; i++) VIR_FREE(names[i]); VIR_FREE(names); } @@ -4105,7 +4105,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED, } if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } @@ -4151,7 +4151,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, py_retval = PyList_New(c_retval); if (py_retval == NULL) { if (names) { - for (i = 0;i < c_retval;i++) + for (i = 0; i < c_retval; i++) VIR_FREE(names[i]); VIR_FREE(names); } @@ -4159,7 +4159,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED, } if (names) { - for (i = 0;i < c_retval;i++) { + for (i = 0; i < c_retval; i++) { PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i])); VIR_FREE(names[i]); } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index d8100ed..025a454 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -1,7 +1,7 @@ /* * interface_conf.c: interfaces XML handling * - * Copyright (C) 2006-2010 Red Hat, Inc. + * Copyright (C) 2006-2010, 2013 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 @@ -80,7 +80,7 @@ void virInterfaceDefFree(virInterfaceDefPtr def) switch (def->type) { case VIR_INTERFACE_TYPE_BRIDGE: VIR_FREE(def->data.bridge.delay); - for (i = 0;i < def->data.bridge.nbItf;i++) { + for (i = 0; i < def->data.bridge.nbItf; i++) { if (def->data.bridge.itf[i] == NULL) break; /* to cope with half parsed data on errors */ virInterfaceDefFree(def->data.bridge.itf[i]); @@ -89,7 +89,7 @@ void virInterfaceDefFree(virInterfaceDefPtr def) break; case VIR_INTERFACE_TYPE_BOND: VIR_FREE(def->data.bond.target); - for (i = 0;i < def->data.bond.nbItf;i++) { + for (i = 0; i < def->data.bond.nbItf; i++) { if (def->data.bond.itf[i] == NULL) break; /* to cope with half parsed data on errors */ virInterfaceDefFree(def->data.bond.itf[i]); @@ -504,7 +504,7 @@ virInterfaceDefParseBridge(virInterfaceDefPtr def, } def->data.bridge.nbItf = nbItf; - for (i = 0; i < nbItf;i++) { + for (i = 0; i < nbItf; i++) { ctxt->node = interfaces[i]; itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BRIDGE); if (itf == NULL) { @@ -551,7 +551,7 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def, } def->data.bond.nbItf = nbItf; - for (i = 0; i < nbItf;i++) { + for (i = 0; i < nbItf; i++) { ctxt->node = interfaces[i]; itf = virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_BOND); if (itf == NULL) { @@ -886,7 +886,7 @@ virInterfaceBridgeDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " delay='%s'", def->data.bridge.delay); virBufferAddLit(buf, ">\n"); - for (i = 0;i < def->data.bridge.nbItf;i++) { + for (i = 0; i < def->data.bridge.nbItf; i++) { if (virInterfaceDefDevFormat(buf, def->data.bridge.itf[i], level+2) < 0) ret = -1; @@ -948,7 +948,7 @@ virInterfaceBondDefFormat(virBufferPtr buf, virBufferAddLit(buf, " validate='all'"); virBufferAddLit(buf, "/>\n"); } - for (i = 0;i < def->data.bond.nbItf;i++) { + for (i = 0; i < def->data.bond.nbItf; i++) { if (virInterfaceDefDevFormat(buf, def->data.bond.itf[i], level+2) < 0) ret = -1; } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index f16a35b..02359fc 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -71,7 +71,7 @@ typedef struct { char *files; /* list of files */ virDomainDefPtr def; /* VM definition */ virCapsPtr caps; /* VM capabilities */ - virDomainXMLOptionPtr xmlopt;/* XML parser data */ + virDomainXMLOptionPtr xmlopt; /* XML parser data */ char *hvm; /* type of hypervisor (eg hvm, xen) */ virArch arch; /* machine architecture */ char *newfile; /* newly added file */ diff --git a/src/util/virconf.c b/src/util/virconf.c index c578bf4..ef76369 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -1,7 +1,7 @@ /* * virconf.c: parser for a subset of the Python encoded Xen configuration files * - * Copyright (C) 2006-2012 Red Hat, Inc. + * Copyright (C) 2006-2013 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 @@ -67,7 +67,7 @@ struct _virConfParserCtxt { #define SKIP_BLANKS_AND_EOL \ do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR) || IS_EOL(CUR))) { \ if (CUR == '\n') ctxt->line++; \ - ctxt->cur++;}} while (0) + ctxt->cur++; } } while (0) #define SKIP_BLANKS \ do { while ((ctxt->cur < ctxt->end) && (c_isblank(CUR))) \ ctxt->cur++; } while (0) diff --git a/src/util/virhook.c b/src/util/virhook.c index 508c268..507eae2 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -142,7 +142,7 @@ virHookInitialize(void) { int i, res, ret = 0; virHooksFound = 0; - for (i = 0;i < VIR_HOOK_DRIVER_LAST;i++) { + for (i = 0; i < VIR_HOOK_DRIVER_LAST; i++) { res = virHookCheck(i, virHookDriverTypeToString(i)); if (res < 0) return -1; diff --git a/src/util/virlog.c b/src/util/virlog.c index 348bddc..f456cb9 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -371,7 +371,7 @@ virLogDumpAllFD(const char *msg, int len) if (len <= 0) len = strlen(msg); - for (i = 0; i < virLogNbOutputs;i++) { + for (i = 0; i < virLogNbOutputs; i++) { if (virLogOutputs[i].f == virLogOutputToFd) { int fd = (intptr_t) virLogOutputs[i].data; @@ -514,7 +514,7 @@ virLogResetFilters(void) { int i; - for (i = 0; i < virLogNbFilters;i++) + for (i = 0; i < virLogNbFilters; i++) VIR_FREE(virLogFilters[i].match); VIR_FREE(virLogFilters); virLogNbFilters = 0; @@ -550,7 +550,7 @@ virLogDefineFilter(const char *match, return -1; virLogLock(); - for (i = 0;i < virLogNbFilters;i++) { + for (i = 0; i < virLogNbFilters; i++) { if (STREQ(virLogFilters[i].match, match)) { virLogFilters[i].priority = priority; goto cleanup; @@ -597,7 +597,7 @@ virLogFiltersCheck(const char *input, int i; virLogLock(); - for (i = 0;i < virLogNbFilters;i++) { + for (i = 0; i < virLogNbFilters; i++) { if (strstr(input, virLogFilters[i].match)) { ret = virLogFilters[i].priority; *flags = virLogFilters[i].flags; @@ -621,7 +621,7 @@ virLogResetOutputs(void) { int i; - for (i = 0;i < virLogNbOutputs;i++) { + for (i = 0; i < virLogNbOutputs; i++) { if (virLogOutputs[i].c != NULL) virLogOutputs[i].c(virLogOutputs[i].data); VIR_FREE(virLogOutputs[i].name); diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 1a6714e..1071b00 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -49,7 +49,7 @@ static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr val = ntohl(addr->data.inet4.sin_addr.s_addr); - for (i = 0;i < 4;i++) { + for (i = 0; i < 4; i++) { (*tab)[3 - i] = val & 0xFF; val >>= 8; } @@ -63,7 +63,7 @@ static int virSocketAddrGetIPv6Addr(virSocketAddrPtr addr, virSocketAddrIPv6Ptr if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET6)) return -1; - for (i = 0;i < 8;i++) { + for (i = 0; i < 8; i++) { (*tab)[i] = ((addr->data.inet6.sin6_addr.s6_addr[2 * i] << 8) | addr->data.inet6.sin6_addr.s6_addr[2 * i + 1]); } @@ -530,7 +530,7 @@ int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2, (virSocketAddrGetIPv4Addr(netmask, &tm) < 0)) return -1; - for (i = 0;i < 4;i++) { + for (i = 0; i < 4; i++) { if ((t1[i] & tm[i]) != (t2[i] & tm[i])) return 0; } @@ -543,7 +543,7 @@ int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2, (virSocketAddrGetIPv6Addr(netmask, &tm) < 0)) return -1; - for (i = 0;i < 8;i++) { + for (i = 0; i < 8; i++) { if ((t1[i] & tm[i]) != (t2[i] & tm[i])) return 0; } @@ -581,7 +581,7 @@ int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) { (virSocketAddrGetIPv4Addr(end, &t2) < 0)) return -1; - for (i = 0;i < 2;i++) { + for (i = 0; i < 2; i++) { if (t1[i] != t2[i]) return -1; } @@ -596,7 +596,7 @@ int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) { (virSocketAddrGetIPv6Addr(end, &t2) < 0)) return -1; - for (i = 0;i < 7;i++) { + for (i = 0; i < 7; i++) { if (t1[i] != t2[i]) return -1; } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 4868a5f..c6d3a71 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -91,7 +91,7 @@ void virSysinfoDefFree(virSysinfoDefPtr def) VIR_FREE(def->system_sku); VIR_FREE(def->system_family); - for (i = 0;i < def->nprocessor;i++) { + for (i = 0; i < def->nprocessor; i++) { VIR_FREE(def->processor[i].processor_socket_destination); VIR_FREE(def->processor[i].processor_type); VIR_FREE(def->processor[i].processor_family); @@ -105,7 +105,7 @@ void virSysinfoDefFree(virSysinfoDefPtr def) VIR_FREE(def->processor[i].processor_part_number); } VIR_FREE(def->processor); - for (i = 0;i < def->nmemory;i++) { + for (i = 0; i < def->nmemory; i++) { VIR_FREE(def->memory[i].memory_size); VIR_FREE(def->memory[i].memory_form_factor); VIR_FREE(def->memory[i].memory_locator); diff --git a/src/util/viruuid.c b/src/util/viruuid.c index 8f82187..9f4bb13 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -1,7 +1,7 @@ /* * viruuid.h: helper APIs for dealing with UUIDs * - * Copyright (C) 2007-2012 Red Hat, Inc. + * Copyright (C) 2007-2013 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 @@ -160,7 +160,7 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid) { while (c_isspace(*cur)) cur++; - for (i = 0;i < VIR_UUID_BUFLEN;) { + for (i = 0; i < VIR_UUID_BUFLEN;) { uuid[i] = 0; if (*cur == 0) goto error; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d37888c..9ddb3ad 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2938,7 +2938,7 @@ sharedFoldersCleanup: } /* Now get the details about the network cards here */ - for (i = 0;(netAdpIncCnt < def->nnets) && (i < netAdpCnt); i++) { + for (i = 0; netAdpIncCnt < def->nnets && i < netAdpCnt; i++) { INetworkAdapter *adapter = NULL; machine->vtbl->GetNetworkAdapter(machine, i, &adapter); @@ -3216,7 +3216,9 @@ sharedFoldersCleanup: } /* Now get the details about the serial ports here */ - for (i = 0;(serialPortIncCount < def->nserials) && (i < serialPortCount); i++) { + for (i = 0; + serialPortIncCount < def->nserials && i < serialPortCount; + i++) { ISerialPort *serialPort = NULL; machine->vtbl->GetSerialPort(machine, i, &serialPort); @@ -3300,7 +3302,10 @@ sharedFoldersCleanup: } /* Now get the details about the parallel ports here */ - for (i = 0;(parallelPortIncCount < def->nparallels) && (i < parallelPortCount); i++) { + for (i = 0; + parallelPortIncCount < def->nparallels && + i < parallelPortCount; + i++) { IParallelPort *parallelPort = NULL; machine->vtbl->GetParallelPort(machine, i, ¶llelPort); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 11ba516..cfc8139 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2873,7 +2873,8 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn, memset(&op_sys, 0, sizeof(op_sys)); op_sys.cmd = XEN_V2_OP_GETAVAILHEAP; - for (i = startCell, j = 0;(i < priv->nbNodeCells) && (j < maxCells);i++,j++) { + for (i = startCell, j = 0; + i < priv->nbNodeCells && j < maxCells; i++, j++) { if (hv_versions.sys_interface >= 5) op_sys.u.availheap5.node = i; else diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 5ed89d1..b284154 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1,7 +1,7 @@ /* * virsh-domain-monitor.c: Commands to monitor domain status * - * Copyright (C) 2005, 2007-2012 Red Hat, Inc. + * Copyright (C) 2005, 2007-2013 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 @@ -156,8 +156,8 @@ vshDomainStateToString(int state) case VIR_DOMAIN_PMSUSPENDED: return N_("pmsuspended"); case VIR_DOMAIN_NOSTATE: - default: - ;/*FALLTHROUGH*/ + case VIR_DOMAIN_LAST: + break; } return N_("no state"); /* = dom0 state */ } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0402aef..4fdf4ba 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -114,15 +114,15 @@ vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, static const char * vshDomainVcpuStateToString(int state) { - switch (state) { + switch ((virVcpuState) state) { case VIR_VCPU_OFFLINE: return N_("offline"); case VIR_VCPU_BLOCKED: return N_("idle"); case VIR_VCPU_RUNNING: return N_("running"); - default: - ;/*FALLTHROUGH*/ + case VIR_VCPU_LAST: + break; } return N_("no state"); } -- 1.8.1.4

On 05/24/2013 07:19 PM, Eric Blake wrote:
I noticed several unusual spacings in for loops, and decided to fix them up. See the next commit for the syntax check that found all of these.
ACK, Martin

Enforce the style cleanup in the previous patch. * build-aux/bracket-spacing.pl: Enforce trailing spacing. * cfg.mk (bracket-spacing-check): Tweak error wording. * docs/hacking.html.in: Document the rule. * HACKING: Regenerate. Signed-off-by: Eric Blake <eblake@redhat.com> --- HACKING | 23 +++++++++++++++++++++++ build-aux/bracket-spacing.pl | 12 ++++++++++++ cfg.mk | 2 +- docs/hacking.html.in | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/HACKING b/HACKING index 2bd6d69..42f76b6 100644 --- a/HACKING +++ b/HACKING @@ -318,6 +318,29 @@ immediately prior to any closing bracket. E.g. int foo(int wizz); // Good +Semicolons +========== +Semicolons should never have a space beforehand. Inside the condition of a +"for" loop, there should always be a space or line break after each semicolon, +except for the special case of an infinite loop (although more infinite loops +use "while"). While not enforced, loop counters generally use post-increment. + + for (i = 0 ;i < limit ; ++i) { // Bad + for (i = 0; i < limit; i++) { // Good + for (;;) { // ok + while (1) { // Better + +Empty loop bodies are better represented with curly braces and a comment, +although use of a semicolon is not currently rejected. + + while ((rc = waitpid(pid, &st, 0) == -1) && // ok + errno == EINTR); + while ((rc = waitpid(pid, &st, 0) == -1) && // Better + errno == EINTR) { + /* nothing */ + } + + Curly braces ============ Omit the curly braces around an "if", "while", "for" etc. body only when that diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index 2eeeeb4..de40040 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # # bracket-spacing.pl: Report any usage of 'function (..args..)' +# Also check for other syntax issues, such as correct use of ';' # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -31,6 +32,9 @@ foreach my $file (@ARGV) { while (defined (my $line = <FILE>)) { my $data = $line; + # Kill any quoted ; or " + $data =~ s,'[";]','X',g; + # Kill any quoted strings $data =~ s,"([^\\\"]|\\.)*","XXX",g; @@ -125,6 +129,14 @@ foreach my $file (@ARGV) { $ret = 1; last; } + + # Require EOL, macro line continuation, or whitespace after ":". + # Allow "for (;;)" as an exception. + while ($data =~ /;[^ \\\n;)]/) { + print "$file:$.: $line"; + $ret = 1; + last; + } } close FILE; } diff --git a/cfg.mk b/cfg.mk index 55359e8..6e8b6d4 100644 --- a/cfg.mk +++ b/cfg.mk @@ -845,7 +845,7 @@ syntax-check: $(top_srcdir)/HACKING bracket-spacing-check bracket-spacing-check: $(AM_V_GEN)files=`$(VC_LIST) | grep '\.c$$'`; \ $(PERL) $(top_srcdir)/build-aux/bracket-spacing.pl $$files || \ - (echo $(ME): incorrect whitespace around brackets, see HACKING for rules && exit 1) + (echo "$(ME): incorrect whitespace, see HACKING for rules" && exit 1) # sc_po_check can fail if generated files are not built first sc_po_check: \ diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 78959f3..08b8b4c 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -377,6 +377,35 @@ int foo(int wizz); // Good </pre> + <h2><a name="semicolon">Semicolons</a></h2> + + <p> + Semicolons should never have a space beforehand. Inside the + condition of a <code>for</code> loop, there should always be a + space or line break after each semicolon, except for the special + case of an infinite loop (although more infinite loops + use <code>while</code>). While not enforced, loop counters + generally use post-increment. + </p> + <pre> + for (i = 0 ;i < limit ; ++i) { // Bad + for (i = 0; i < limit; i++) { // Good + for (;;) { // ok + while (1) { // Better +</pre> + <p> + Empty loop bodies are better represented with curly braces and a + comment, although use of a semicolon is not currently rejected. + </p> + <pre> + while ((rc = waitpid(pid, &st, 0) == -1) && // ok + errno == EINTR); + while ((rc = waitpid(pid, &st, 0) == -1) && // Better + errno == EINTR) { + /* nothing */ + } +</pre> + <h2><a name="curly_braces">Curly braces</a></h2> <p> -- 1.8.1.4

On 05/24/2013 07:19 PM, Eric Blake wrote:
Enforce the style cleanup in the previous patch.
* build-aux/bracket-spacing.pl: Enforce trailing spacing. * cfg.mk (bracket-spacing-check): Tweak error wording. * docs/hacking.html.in: Document the rule. * HACKING: Regenerate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- HACKING | 23 +++++++++++++++++++++++ build-aux/bracket-spacing.pl | 12 ++++++++++++ cfg.mk | 2 +- docs/hacking.html.in | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-)
[...]
diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index 2eeeeb4..de40040 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # # bracket-spacing.pl: Report any usage of 'function (..args..)' +# Also check for other syntax issues, such as correct use of ';' # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -31,6 +32,9 @@ foreach my $file (@ARGV) { while (defined (my $line = <FILE>)) { my $data = $line;
+ # Kill any quoted ; or " + $data =~ s,'[";]','X',g; +
Good catch, I didn't know this was missing. [...] ACK, Martin

On 05/25/2013 03:13 PM, Martin Kletzander wrote:
@@ -31,6 +32,9 @@ foreach my $file (@ARGV) { while (defined (my $line = <FILE>)) { my $data = $line;
+ # Kill any quoted ; or " + $data =~ s,'[";]','X',g; +
Good catch, I didn't know this was missing.
Yep, I hit some false positives where we parse for ';' if I didn't add this.
[...]
ACK,
Thanks; pushed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 25/05/13 01:19, Eric Blake wrote:
Enforce the style cleanup in the previous patch.
* build-aux/bracket-spacing.pl: Enforce trailing spacing. * cfg.mk (bracket-spacing-check): Tweak error wording. * docs/hacking.html.in: Document the rule. * HACKING: Regenerate.
Signed-off-by: Eric Blake <eblake@redhat.com> --- HACKING | 23 +++++++++++++++++++++++ build-aux/bracket-spacing.pl | 12 ++++++++++++ cfg.mk | 2 +- docs/hacking.html.in | 29 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/HACKING b/HACKING index 2bd6d69..42f76b6 100644 --- a/HACKING +++ b/HACKING @@ -318,6 +318,29 @@ immediately prior to any closing bracket. E.g. int foo(int wizz); // Good
+Semicolons +========== +Semicolons should never have a space beforehand. Inside the condition of a +"for" loop, there should always be a space or line break after each semicolon, +except for the special case of an infinite loop (although more infinite loops +use "while"). While not enforced, loop counters generally use post-increment. + + for (i = 0 ;i < limit ; ++i) { // Bad + for (i = 0; i < limit; i++) { // Good + for (;;) { // ok + while (1) { // Better + +Empty loop bodies are better represented with curly braces and a comment, +although use of a semicolon is not currently rejected. + + while ((rc = waitpid(pid, &st, 0) == -1) && // ok + errno == EINTR); + while ((rc = waitpid(pid, &st, 0) == -1) && // Better + errno == EINTR) { + /* nothing */ + } + + Curly braces ============ Omit the curly braces around an "if", "while", "for" etc. body only when that diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index 2eeeeb4..de40040 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # # bracket-spacing.pl: Report any usage of 'function (..args..)' +# Also check for other syntax issues, such as correct use of ';' # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -31,6 +32,9 @@ foreach my $file (@ARGV) { while (defined (my $line = <FILE>)) { my $data = $line;
+ # Kill any quoted ; or " + $data =~ s,'[";]','X',g; + # Kill any quoted strings $data =~ s,"([^\\\"]|\\.)*","XXX",g;
@@ -125,6 +129,14 @@ foreach my $file (@ARGV) { $ret = 1; last; } + + # Require EOL, macro line continuation, or whitespace after ":". + # Allow "for (;;)" as an exception. + while ($data =~ /;[^ \\\n;)]/) { + print "$file:$.: $line"; + $ret = 1; + last; + } } close FILE; } diff --git a/cfg.mk b/cfg.mk index 55359e8..6e8b6d4 100644 --- a/cfg.mk +++ b/cfg.mk @@ -845,7 +845,7 @@ syntax-check: $(top_srcdir)/HACKING bracket-spacing-check bracket-spacing-check: $(AM_V_GEN)files=`$(VC_LIST) | grep '\.c$$'`; \ $(PERL) $(top_srcdir)/build-aux/bracket-spacing.pl $$files || \ - (echo $(ME): incorrect whitespace around brackets, see HACKING for rules && exit 1) + (echo "$(ME): incorrect whitespace, see HACKING for rules" && exit 1)
I see you changed this when pushing: - (echo $(ME): incorrect whitespace around brackets, see HACKING for rules && exit 1) + { echo "$(ME): incorrect whitespace, see HACKING for rules" 2>&; \ + exit 1; } But it breaks build. I guess you indented to write "2>&1" there. Osier

On 05/28/2013 09:28 AM, Osier Yang wrote:
On 25/05/13 01:19, Eric Blake wrote:
Enforce the style cleanup in the previous patch.
* build-aux/bracket-spacing.pl: Enforce trailing spacing. * cfg.mk (bracket-spacing-check): Tweak error wording. * docs/hacking.html.in: Document the rule. * HACKING: Regenerate.
+ (echo "$(ME): incorrect whitespace, see HACKING for rules" && exit 1)
I see you changed this when pushing:
- (echo $(ME): incorrect whitespace around brackets, see HACKING for rules && exit 1) + { echo "$(ME): incorrect whitespace, see HACKING for rules" 2>&; \ + exit 1; }
But it breaks build. I guess you indented to write "2>&1" there.
Phooey. I was trying to copy how we did it elsewhere, and copied wrong without testing my final edit. I'll push the fix shortly. :( -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Martin Kletzander
-
Osier Yang