[libvirt] [PATCH] Avoid GCC extensions

# HG changeset patch # User john.levon@sun.com # Date 1229367890 28800 # Node ID 6a8e82d7d2e166880fed8d7ad860a3e2e93d62be # Parent c324c231c6a50be9f970f0f6c6d1629a7c09ab3b Avoid GCC extensions Anonymous unions are not portable, nor are zero-sizes structures. Signed-off-by: John Levon <john.levon@sun.com> diff --git a/src/domain_conf.c b/src/domain_conf.c --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -1437,7 +1437,7 @@ virDomainHostdevSubsysUsbDefParseXML(vir if (vendor) { if (virStrToLong_ui(vendor, NULL, 0, - &def->source.subsys.usb.vendor) < 0) { + &def->source.subsys.u.usb.vendor) < 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, _("cannot parse vendor id %s"), vendor); VIR_FREE(vendor); @@ -1454,7 +1454,7 @@ virDomainHostdevSubsysUsbDefParseXML(vir if (product) { if (virStrToLong_ui(product, NULL, 0, - &def->source.subsys.usb.product) < 0) { + &def->source.subsys.u.usb.product) < 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, _("cannot parse product %s"), product); VIR_FREE(product); @@ -1472,7 +1472,7 @@ virDomainHostdevSubsysUsbDefParseXML(vir bus = virXMLPropString(cur, "bus"); if (bus) { if (virStrToLong_ui(bus, NULL, 0, - &def->source.subsys.usb.bus) < 0) { + &def->source.subsys.u.usb.bus) < 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, _("cannot parse bus %s"), bus); VIR_FREE(bus); @@ -1488,7 +1488,7 @@ virDomainHostdevSubsysUsbDefParseXML(vir device = virXMLPropString(cur, "device"); if (device) { if (virStrToLong_ui(device, NULL, 0, - &def->source.subsys.usb.device) < 0) { + &def->source.subsys.u.usb.device) < 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, _("cannot parse device %s"), device); @@ -1510,14 +1510,14 @@ virDomainHostdevSubsysUsbDefParseXML(vir cur = cur->next; } - if (def->source.subsys.usb.vendor == 0 && - def->source.subsys.usb.product != 0) { + if (def->source.subsys.u.usb.vendor == 0 && + def->source.subsys.u.usb.product != 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("missing vendor")); goto out; } - if (def->source.subsys.usb.vendor != 0 && - def->source.subsys.usb.product == 0) { + if (def->source.subsys.u.usb.vendor != 0 && + def->source.subsys.u.usb.product == 0) { virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("missing product")); goto out; @@ -2951,15 +2951,15 @@ virDomainHostdevDefFormat(virConnectPtr virBufferVSprintf(buf, " <hostdev mode='%s' type='%s'>\n", mode, type); virBufferAddLit(buf, " <source>\n"); - if (def->source.subsys.usb.vendor) { + if (def->source.subsys.u.usb.vendor) { virBufferVSprintf(buf, " <vendor id='0x%.4x'/>\n", - def->source.subsys.usb.vendor); + def->source.subsys.u.usb.vendor); virBufferVSprintf(buf, " <product id='0x%.4x'/>\n", - def->source.subsys.usb.product); + def->source.subsys.u.usb.product); } else { virBufferVSprintf(buf, " <address bus='%d' device='%d'/>\n", - def->source.subsys.usb.bus, - def->source.subsys.usb.device); + def->source.subsys.u.usb.bus, + def->source.subsys.u.usb.device); } virBufferAddLit(buf, " </source>\n"); diff --git a/src/domain_conf.h b/src/domain_conf.h --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -307,12 +307,13 @@ struct _virDomainHostdevDef { unsigned slot; unsigned function; } pci; - }; + } u; } subsys; struct { /* TBD: struct capabilities see: * https://www.redhat.com/archives/libvir-list/2008-July/msg00429.html */ + int dummy; } caps; } source; char* target; diff --git a/src/qemu_conf.c b/src/qemu_conf.c --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -1264,15 +1264,15 @@ int qemudBuildCommandLine(virConnectPtr if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { - if(hostdev->source.subsys.usb.vendor) { + if(hostdev->source.subsys.u.usb.vendor) { ret = asprintf(&usbdev, "host:%.4x:%.4x", - hostdev->source.subsys.usb.vendor, - hostdev->source.subsys.usb.product); + hostdev->source.subsys.u.usb.vendor, + hostdev->source.subsys.u.usb.product); } else { ret = asprintf(&usbdev, "host:%.3d.%.3d", - hostdev->source.subsys.usb.bus, - hostdev->source.subsys.usb.device); + hostdev->source.subsys.u.usb.bus, + hostdev->source.subsys.u.usb.device); } if (ret < 0) { usbdev = NULL; diff --git a/src/qemu_driver.c b/src/qemu_driver.c --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -2790,14 +2790,14 @@ static int qemudDomainAttachHostDevice(v return -1; } - if (dev->data.hostdev->source.subsys.usb.vendor) { + if (dev->data.hostdev->source.subsys.u.usb.vendor) { ret = asprintf(&cmd, "usb_add host:%.4x:%.4x", - dev->data.hostdev->source.subsys.usb.vendor, - dev->data.hostdev->source.subsys.usb.product); + dev->data.hostdev->source.subsys.u.usb.vendor, + dev->data.hostdev->source.subsys.u.usb.product); } else { ret = asprintf(&cmd, "usb_add host:%.3d.%.3d", - dev->data.hostdev->source.subsys.usb.bus, - dev->data.hostdev->source.subsys.usb.device); + dev->data.hostdev->source.subsys.u.usb.bus, + dev->data.hostdev->source.subsys.u.usb.device); } if (ret == -1) { qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL); diff --git a/src/remote_internal.c b/src/remote_internal.c --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -649,7 +649,7 @@ doRemoteOpen (virConnectPtr conn, if (username) nr_args += 2; /* For -l username */ if (no_tty) nr_args += 5; /* For -T -o BatchMode=yes -e none */ - command = command ? : strdup ("ssh"); + command = command ? command : strdup ("ssh"); if (command == NULL) goto out_of_memory;

On Mon, Dec 15, 2008 at 11:58:06AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1229367890 28800 # Node ID 6a8e82d7d2e166880fed8d7ad860a3e2e93d62be # Parent c324c231c6a50be9f970f0f6c6d1629a7c09ab3b Avoid GCC extensions
Anonymous unions are not portable, nor are zero-sizes structures.
ACK. Shame there's no GCC flag to warn about this non-portability. At least I couldn't find one so far... Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Mon, Dec 15, 2008 at 09:38:52PM +0000, Daniel P. Berrange wrote:
On Mon, Dec 15, 2008 at 11:58:06AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1229367890 28800 # Node ID 6a8e82d7d2e166880fed8d7ad860a3e2e93d62be # Parent c324c231c6a50be9f970f0f6c6d1629a7c09ab3b Avoid GCC extensions
Anonymous unions are not portable, nor are zero-sizes structures.
ACK. Shame there's no GCC flag to warn about this non-portability. At least I couldn't find one so far...
Isn't this what -pedantic does? Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/

On Mon, Jan 12, 2009 at 06:32:45PM +0000, Richard W.M. Jones wrote:
On Mon, Dec 15, 2008 at 09:38:52PM +0000, Daniel P. Berrange wrote:
On Mon, Dec 15, 2008 at 11:58:06AM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1229367890 28800 # Node ID 6a8e82d7d2e166880fed8d7ad860a3e2e93d62be # Parent c324c231c6a50be9f970f0f6c6d1629a7c09ab3b Avoid GCC extensions
Anonymous unions are not portable, nor are zero-sizes structures.
ACK. Shame there's no GCC flag to warn about this non-portability. At least I couldn't find one so far...
Isn't this what -pedantic does?
Possibly, but -pedantic is utterly f*ing useless because of all the line noise it generates about use of 'long long', trailing commas in enums, use of variadic macros, and countless other important modern C features Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

diff --git a/src/domain_conf.h b/src/domain_conf.h --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -307,12 +307,13 @@ struct _virDomainHostdevDef { unsigned slot; unsigned function; } pci; - }; + } u; } subsys; AFAIK we're currently not using the pci part of this union since PCI
On Mon, Dec 15, 2008 at 11:58:06AM -0800, john.levon@sun.com wrote: passthrough isn't implemented yet. So I wonder if should drop this altogether for the moment?
struct { /* TBD: struct capabilities see: * https://www.redhat.com/archives/libvir-list/2008-July/msg00429.html */ + int dummy; } caps;
Basically the same here. We can easily add it back when somebody is working on it. Cheers, -- Guido
} source;
participants (4)
-
Daniel P. Berrange
-
Guido Günther
-
john.levon@sun.com
-
Richard W.M. Jones