[libvirt] [PATCH] build: avoid C99 for loop

Although we require various C99 features, we don't yet require a complete C99 compiler. On RHEL 5, compilation complained: qemu/qemu_command.c: In function 'qemuBuildGraphicsCommandLine': qemu/qemu_command.c:4688: error: 'for' loop initial declaration used outside C99 mode * src/qemu/qemu_command.c (qemuBuildGraphicsCommandLine): Declare variable sooner. * src/qemu/qemu_process.c (qemuProcessInitPasswords): Likewise. --- Pushing under the build-breaker rule src/qemu/qemu_command.c | 4 +++- src/qemu/qemu_process.c | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9c9a0ed..03716d4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4429,6 +4429,8 @@ qemuBuildGraphicsCommandLine(struct qemud_driver *driver, qemuCapsPtr caps, virDomainGraphicsDefPtr graphics) { + int i; + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { virBuffer opt = VIR_BUFFER_INITIALIZER; @@ -4685,7 +4687,7 @@ qemuBuildGraphicsCommandLine(struct qemud_driver *driver, break; } - for (int i = 0 ; i < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST ; i++) { + for (i = 0 ; i < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST ; i++) { int mode = graphics->data.spice.channels[i]; switch (mode) { case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3d7a5a0..8743c60 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2078,8 +2078,9 @@ qemuProcessInitPasswords(virConnectPtr conn, { int ret = 0; qemuDomainObjPrivatePtr priv = vm->privateData; + int i; - for (int i = 0 ; i < vm->def->ngraphics; ++i) { + for (i = 0 ; i < vm->def->ngraphics; ++i) { virDomainGraphicsDefPtr graphics = vm->def->graphics[i]; if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { ret = qemuDomainChangeGraphicsPasswords(driver, vm, @@ -2098,8 +2099,6 @@ qemuProcessInitPasswords(virConnectPtr conn, goto cleanup; if (qemuCapsGet(priv->caps, QEMU_CAPS_DEVICE)) { - int i; - for (i = 0 ; i < vm->def->ndisks ; i++) { char *secret; size_t secretLen; -- 1.7.1

On Mon, Nov 26, 2012 at 03:25:04PM -0700, Eric Blake wrote:
Although we require various C99 features, we don't yet require a complete C99 compiler. On RHEL 5, compilation complained:
qemu/qemu_command.c: In function 'qemuBuildGraphicsCommandLine': qemu/qemu_command.c:4688: error: 'for' loop initial declaration used outside C99 mode
* src/qemu/qemu_command.c (qemuBuildGraphicsCommandLine): Declare variable sooner. * src/qemu/qemu_process.c (qemuProcessInitPasswords): Likewise.
find ./ -name '*.c' | xargs grep 'for *( *int ' reveals another file, see the patch below.
From 9f5f9112108c5ab42e56c1e4e9db185d7dfb6cf4 Mon Sep 17 00:00:00 2001 From: Hu Tao <hutao@cn.fujitsu.com> Date: Wed, 28 Nov 2012 11:31:26 +0800 Subject: [PATCH] build: more fix to avoid C99 for loop
see commit 7e5aa78d0f7f4cbf1c8 * src/interface/interface_backend_udev.c: Declare variable sooner. --- src/interface/interface_backend_udev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 5a27cc5..ed73d54 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -515,12 +515,14 @@ udevIfaceScanDirFilter(const struct dirent *entry) static void udevIfaceFreeIfaceDef(virInterfaceDef *ifacedef) { + int i; + if (!ifacedef) return; if (ifacedef->type == VIR_INTERFACE_TYPE_BRIDGE) { VIR_FREE(ifacedef->data.bridge.delay); - for (int i = 0; i < ifacedef->data.bridge.nbItf; i++) { + for (i = 0; i < ifacedef->data.bridge.nbItf; i++) { udevIfaceFreeIfaceDef(ifacedef->data.bridge.itf[i]); } VIR_FREE(ifacedef->data.bridge.itf); @@ -547,6 +549,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) char *vlan_parent_dev = NULL; struct dirent **member_list = NULL; int member_count = 0; + int i; /* Allocate our interface definition structure */ if (VIR_ALLOC(ifacedef) < 0) { @@ -679,7 +682,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) } ifacedef->data.bridge.nbItf = member_count; - for (int i= 0; i < member_count; i++) { + for (i= 0; i < member_count; i++) { ifacedef->data.bridge.itf[i] = udevIfaceGetIfaceDef(udev, member_list[i]->d_name); VIR_FREE(member_list[i]); @@ -698,7 +701,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) cleanup: udev_device_unref(dev); - for (int i = 0; i < member_count; i++) { + for (i = 0; i < member_count; i++) { VIR_FREE(member_list[i]); } VIR_FREE(member_list); -- 1.8.0.1.240.ge8a1f5a

On 11/28/2012 04:37 AM, Hu Tao wrote:
On Mon, Nov 26, 2012 at 03:25:04PM -0700, Eric Blake wrote:
Although we require various C99 features, we don't yet require a complete C99 compiler. On RHEL 5, compilation complained:
qemu/qemu_command.c: In function 'qemuBuildGraphicsCommandLine': qemu/qemu_command.c:4688: error: 'for' loop initial declaration used outside C99 mode
* src/qemu/qemu_command.c (qemuBuildGraphicsCommandLine): Declare variable sooner. * src/qemu/qemu_process.c (qemuProcessInitPasswords): Likewise.
find ./ -name '*.c' | xargs grep 'for *( *int '
reveals another file, see the patch below.
From 9f5f9112108c5ab42e56c1e4e9db185d7dfb6cf4 Mon Sep 17 00:00:00 2001 From: Hu Tao <hutao@cn.fujitsu.com> Date: Wed, 28 Nov 2012 11:31:26 +0800 Subject: [PATCH] build: more fix to avoid C99 for loop
see commit 7e5aa78d0f7f4cbf1c8
* src/interface/interface_backend_udev.c: Declare variable sooner. --- src/interface/interface_backend_udev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 5a27cc5..ed73d54 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -515,12 +515,14 @@ udevIfaceScanDirFilter(const struct dirent *entry) static void udevIfaceFreeIfaceDef(virInterfaceDef *ifacedef) { + int i; + if (!ifacedef) return;
if (ifacedef->type == VIR_INTERFACE_TYPE_BRIDGE) { VIR_FREE(ifacedef->data.bridge.delay); - for (int i = 0; i < ifacedef->data.bridge.nbItf; i++) { + for (i = 0; i < ifacedef->data.bridge.nbItf; i++) { udevIfaceFreeIfaceDef(ifacedef->data.bridge.itf[i]); } VIR_FREE(ifacedef->data.bridge.itf); @@ -547,6 +549,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) char *vlan_parent_dev = NULL; struct dirent **member_list = NULL; int member_count = 0; + int i;
/* Allocate our interface definition structure */ if (VIR_ALLOC(ifacedef) < 0) { @@ -679,7 +682,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) } ifacedef->data.bridge.nbItf = member_count;
- for (int i= 0; i < member_count; i++) { + for (i= 0; i < member_count; i++) {
Ewww, this could use a space: s/i=/i =/
ifacedef->data.bridge.itf[i] = udevIfaceGetIfaceDef(udev, member_list[i]->d_name); VIR_FREE(member_list[i]); @@ -698,7 +701,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name)
cleanup: udev_device_unref(dev); - for (int i = 0; i < member_count; i++) { + for (i = 0; i < member_count; i++) { VIR_FREE(member_list[i]); } VIR_FREE(member_list);
ACK with the space fixed (and the obvious: no '(Re:...' in the commit message), Martin

On Wed, Nov 28, 2012 at 10:41:34AM +0100, Martin Kletzander wrote:
On 11/28/2012 04:37 AM, Hu Tao wrote:
On Mon, Nov 26, 2012 at 03:25:04PM -0700, Eric Blake wrote:
Although we require various C99 features, we don't yet require a complete C99 compiler. On RHEL 5, compilation complained:
qemu/qemu_command.c: In function 'qemuBuildGraphicsCommandLine': qemu/qemu_command.c:4688: error: 'for' loop initial declaration used outside C99 mode
* src/qemu/qemu_command.c (qemuBuildGraphicsCommandLine): Declare variable sooner. * src/qemu/qemu_process.c (qemuProcessInitPasswords): Likewise.
find ./ -name '*.c' | xargs grep 'for *( *int '
reveals another file, see the patch below.
From 9f5f9112108c5ab42e56c1e4e9db185d7dfb6cf4 Mon Sep 17 00:00:00 2001 From: Hu Tao <hutao@cn.fujitsu.com> Date: Wed, 28 Nov 2012 11:31:26 +0800 Subject: [PATCH] build: more fix to avoid C99 for loop
see commit 7e5aa78d0f7f4cbf1c8
* src/interface/interface_backend_udev.c: Declare variable sooner. --- src/interface/interface_backend_udev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 5a27cc5..ed73d54 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -515,12 +515,14 @@ udevIfaceScanDirFilter(const struct dirent *entry) static void udevIfaceFreeIfaceDef(virInterfaceDef *ifacedef) { + int i; + if (!ifacedef) return;
if (ifacedef->type == VIR_INTERFACE_TYPE_BRIDGE) { VIR_FREE(ifacedef->data.bridge.delay); - for (int i = 0; i < ifacedef->data.bridge.nbItf; i++) { + for (i = 0; i < ifacedef->data.bridge.nbItf; i++) { udevIfaceFreeIfaceDef(ifacedef->data.bridge.itf[i]); } VIR_FREE(ifacedef->data.bridge.itf); @@ -547,6 +549,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) char *vlan_parent_dev = NULL; struct dirent **member_list = NULL; int member_count = 0; + int i;
/* Allocate our interface definition structure */ if (VIR_ALLOC(ifacedef) < 0) { @@ -679,7 +682,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) } ifacedef->data.bridge.nbItf = member_count;
- for (int i= 0; i < member_count; i++) { + for (i= 0; i < member_count; i++) {
Ewww, this could use a space: s/i=/i =/
Fixed. Thanks for review!
From 10e878a963aeb591121910f1d3b57af923acf5de Mon Sep 17 00:00:00 2001 From: Hu Tao <hutao@cn.fujitsu.com> Date: Wed, 28 Nov 2012 18:13:21 +0800 Subject: [PATCH v2] build: more fix to avoid C99 for loop
see commit 7e5aa78d0f7f4cbf1c8 * src/interface/interface_backend_udev.c: Declare variable sooner. --- v2: - i=0 --> i = 0 src/interface/interface_backend_udev.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 5a27cc5..9233e87 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -515,12 +515,14 @@ udevIfaceScanDirFilter(const struct dirent *entry) static void udevIfaceFreeIfaceDef(virInterfaceDef *ifacedef) { + int i; + if (!ifacedef) return; if (ifacedef->type == VIR_INTERFACE_TYPE_BRIDGE) { VIR_FREE(ifacedef->data.bridge.delay); - for (int i = 0; i < ifacedef->data.bridge.nbItf; i++) { + for (i = 0; i < ifacedef->data.bridge.nbItf; i++) { udevIfaceFreeIfaceDef(ifacedef->data.bridge.itf[i]); } VIR_FREE(ifacedef->data.bridge.itf); @@ -547,6 +549,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) char *vlan_parent_dev = NULL; struct dirent **member_list = NULL; int member_count = 0; + int i; /* Allocate our interface definition structure */ if (VIR_ALLOC(ifacedef) < 0) { @@ -679,7 +682,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) } ifacedef->data.bridge.nbItf = member_count; - for (int i= 0; i < member_count; i++) { + for (i = 0; i < member_count; i++) { ifacedef->data.bridge.itf[i] = udevIfaceGetIfaceDef(udev, member_list[i]->d_name); VIR_FREE(member_list[i]); @@ -698,7 +701,7 @@ udevIfaceGetIfaceDef(struct udev *udev, char *name) cleanup: udev_device_unref(dev); - for (int i = 0; i < member_count; i++) { + for (i = 0; i < member_count; i++) { VIR_FREE(member_list[i]); } VIR_FREE(member_list); -- 1.8.0.1.240.ge8a1f5a

Subject: [PATCH v2] build: more fix to avoid C99 for loop
see commit 7e5aa78d0f7f4cbf1c8
* src/interface/interface_backend_udev.c: Declare variable sooner. ---
v2:
- i=0 --> i = 0
ACK and pushed.
participants (3)
-
Eric Blake
-
Hu Tao
-
Martin Kletzander