[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2] build: more fix to avoid C99 for loop (Re: [PATCH] build: more fix to avoid C99 for loop (Re: [PATCH] build: avoid C99 for loop))



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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]