[libvirt] [PATCH] make all struct typedefs comply with proposed coding conventions

Laine Stump laine at laine.org
Mon Mar 6 17:53:23 UTC 2017


Proposed formal coding conventions encourage defining typedefs for
vir[Blah] and vir[Blah]Ptr separately from the associated struct named
_vir[Blah]:

    typedef struct _virBlah virBlah;
    typedef virBlah *virBlahPtr;
    struct _virBlah {
    ...
    };

At some point in the past, I had submitted several patches using a
more compact style that I prefer, and they were accepted:

    typedef struct _virBlah {
        ...
    } virBlah, *virBlahPtr;

Since these are by far a minority among all struct definitions, this
patch changes all those definitions to reflect the style prefered by
the proposal so that there is 100% consistency.
---

https://www.redhat.com/archives/libvir-list/2017-March/msg00215.html

Now that we're talking about formalizing the format of struct
definitions, since it was me who tried to make this catch on, it
should be me who takes the time to fix them when they don't catch on
:-P


 src/conf/device_conf.h      | 60 ++++++++++++++++++++++++++++++---------------
 src/conf/network_conf.h     |  6 +++--
 src/conf/node_device_conf.h |  6 +++--
 src/util/virnetdev.h        |  6 +++--
 src/util/virnetdevip.h      | 18 +++++++++-----
 5 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f435fb5..a20de85 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -51,46 +51,58 @@ typedef enum {
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
 } virDomainDeviceAddressType;
 
-typedef struct _virDomainDeviceDriveAddress {
+typedef struct _virDomainDeviceDriveAddress virDomainDeviceDriveAddress;
+typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr;
+struct _virDomainDeviceDriveAddress {
     unsigned int controller;
     unsigned int bus;
     unsigned int target;
     unsigned int unit;
-} virDomainDeviceDriveAddress, *virDomainDeviceDriveAddressPtr;
+};
 
-typedef struct _virDomainDeviceVirtioSerialAddress {
+typedef struct _virDomainDeviceVirtioSerialAddress virDomainDeviceVirtioSerialAddress;
+typedef virDomainDeviceVirtioSerialAddress *virDomainDeviceVirtioSerialAddressPtr;
+struct _virDomainDeviceVirtioSerialAddress {
     unsigned int controller;
     unsigned int bus;
     unsigned int port;
-} virDomainDeviceVirtioSerialAddress, *virDomainDeviceVirtioSerialAddressPtr;
+};
 
 # define VIR_DOMAIN_DEVICE_CCW_MAX_CSSID    254
 # define VIR_DOMAIN_DEVICE_CCW_MAX_SSID       3
 # define VIR_DOMAIN_DEVICE_CCW_MAX_DEVNO  65535
 
-typedef struct _virDomainDeviceCCWAddress {
+typedef struct _virDomainDeviceCCWAddress virDomainDeviceCCWAddress;
+typedef virDomainDeviceCCWAddress *virDomainDeviceCCWAddressPtr;
+struct _virDomainDeviceCCWAddress {
     unsigned int cssid;
     unsigned int ssid;
     unsigned int devno;
     bool         assigned;
-} virDomainDeviceCCWAddress, *virDomainDeviceCCWAddressPtr;
+};
 
-typedef struct _virDomainDeviceCcidAddress {
+typedef struct _virDomainDeviceCcidAddress virDomainDeviceCcidAddress;
+typedef virDomainDeviceCcidAddress *virDomainDeviceCcidAddressPtr;
+struct _virDomainDeviceCcidAddress {
     unsigned int controller;
     unsigned int slot;
-} virDomainDeviceCcidAddress, *virDomainDeviceCcidAddressPtr;
+};
 
 # define VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH 4
 
-typedef struct _virDomainDeviceUSBAddress {
+typedef struct _virDomainDeviceUSBAddress virDomainDeviceUSBAddress;
+typedef virDomainDeviceUSBAddress *virDomainDeviceUSBAddressPtr;
+struct _virDomainDeviceUSBAddress {
     unsigned int bus;
     unsigned int port[VIR_DOMAIN_DEVICE_USB_MAX_PORT_DEPTH];
-} virDomainDeviceUSBAddress, *virDomainDeviceUSBAddressPtr;
+};
 
-typedef struct _virDomainDeviceSpaprVioAddress {
+typedef struct _virDomainDeviceSpaprVioAddress virDomainDeviceSpaprVioAddress;
+typedef virDomainDeviceSpaprVioAddress *virDomainDeviceSpaprVioAddressPtr;
+struct _virDomainDeviceSpaprVioAddress {
     unsigned long long reg;
     bool has_reg;
-} virDomainDeviceSpaprVioAddress, *virDomainDeviceSpaprVioAddressPtr;
+};
 
 typedef enum {
     VIR_DOMAIN_CONTROLLER_MASTER_NONE,
@@ -99,21 +111,29 @@ typedef enum {
     VIR_DOMAIN_CONTROLLER_MASTER_LAST
 } virDomainControllerMaster;
 
-typedef struct _virDomainDeviceUSBMaster {
+typedef struct _virDomainDeviceUSBMaster virDomainDeviceUSBMaster;
+typedef virDomainDeviceUSBMaster *virDomainDeviceUSBMasterPtr;
+struct _virDomainDeviceUSBMaster {
     unsigned int startport;
-} virDomainDeviceUSBMaster, *virDomainDeviceUSBMasterPtr;
+};
 
-typedef struct _virDomainDeviceISAAddress {
+typedef struct _virDomainDeviceISAAddress virDomainDeviceISAAddress;
+typedef virDomainDeviceISAAddress *virDomainDeviceISAAddressPtr;
+struct _virDomainDeviceISAAddress {
     unsigned int iobase;
     unsigned int irq;
-} virDomainDeviceISAAddress, *virDomainDeviceISAAddressPtr;
+};
 
-typedef struct _virDomainDeviceDimmAddress {
+typedef struct _virDomainDeviceDimmAddress virDomainDeviceDimmAddress;
+typedef virDomainDeviceDimmAddress *virDomainDeviceDimmAddressPtr;
+struct _virDomainDeviceDimmAddress {
     unsigned int slot;
     unsigned long long base;
-} virDomainDeviceDimmAddress, *virDomainDeviceDimmAddressPtr;
+};
 
-typedef struct _virDomainDeviceInfo {
+typedef struct _virDomainDeviceInfo virDomainDeviceInfo;
+typedef virDomainDeviceInfo *virDomainDeviceInfoPtr;
+struct _virDomainDeviceInfo {
     /* If adding to this struct, ensure that
      * virDomainDeviceInfoIsSet() is updated
      * to consider the new fields
@@ -147,7 +167,7 @@ typedef struct _virDomainDeviceInfo {
      * assignment, never saved and never reported.
      */
     int pciConnectFlags; /* enum virDomainPCIConnectFlags */
-} virDomainDeviceInfo, *virDomainDeviceInfoPtr;
+};
 
 
 int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 9e4ae71..dec809e 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -127,10 +127,12 @@ struct _virNetworkDNSHostDef {
 };
 
 
-typedef struct _virNetworkDNSForwarder {
+typedef struct _virNetworkDNSForwarder virNetworkDNSForwarder;
+typedef virNetworkDNSForwarder *virNetworkDNSForwarderPtr;
+struct _virNetworkDNSForwarder {
     virSocketAddr addr;
     char *domain;
-} virNetworkDNSForwarder, *virNetworkDNSForwarderPtr;
+};
 
 typedef struct _virNetworkDNSDef virNetworkDNSDef;
 typedef virNetworkDNSDef *virNetworkDNSDefPtr;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 7aed1f4..cf51c69 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -243,7 +243,9 @@ struct _virNodeDevCapDRM {
     virNodeDevDRMType type;
 };
 
-typedef struct _virNodeDevCapData {
+typedef struct _virNodeDevCapData virNodeDevCapData;
+typedef virNodeDevCapData *virNodeDevCapDataPtr;
+struct _virNodeDevCapData {
     virNodeDevCapType type;
     union {
         virNodeDevCapSystem system;
@@ -258,7 +260,7 @@ typedef struct _virNodeDevCapData {
         virNodeDevCapSCSIGeneric sg;
         virNodeDevCapDRM drm;
     };
-} virNodeDevCapData, *virNodeDevCapDataPtr;
+};
 
 typedef struct _virNodeDevCapsDef virNodeDevCapsDef;
 typedef virNodeDevCapsDef *virNodeDevCapsDefPtr;
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index c3e8ffc..236cf83 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -86,10 +86,12 @@ typedef enum {
 
 VIR_ENUM_DECL(virNetDevIfState)
 
-typedef struct {
+typedef struct _virNetDevIfLink virNetDevIfLink;
+typedef virNetDevIfLink *virNetDevIfLinkPtr;
+struct _virNetDevIfLink {
     virNetDevIfState state; /* link state */
     unsigned int speed;      /* link speed in Mbits per second */
-} virNetDevIfLink, *virNetDevIfLinkPtr;
+};
 
 typedef enum {
     VIR_NET_DEV_FEAT_GRXCSUM,
diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
index 8277654..b7abdf9 100644
--- a/src/util/virnetdevip.h
+++ b/src/util/virnetdevip.h
@@ -25,13 +25,17 @@
 
 # include "virsocketaddr.h"
 
-typedef struct {
+typedef struct _virNetDevIPAddr virNetDevIPAddr;
+typedef virNetDevIPAddr *virNetDevIPAddrPtr;
+struct _virNetDevIPAddr {
     virSocketAddr address; /* ipv4 or ipv6 address */
     virSocketAddr peer;    /* ipv4 or ipv6 address of peer */
     unsigned int prefix;   /* number of 1 bits in the netmask */
-} virNetDevIPAddr, *virNetDevIPAddrPtr;
+};
 
-typedef struct {
+typedef struct _virNetDevIPRoute virNetDevIPRoute;
+typedef virNetDevIPRoute *virNetDevIPRoutePtr;
+struct _virNetDevIPRoute {
     char *family;               /* ipv4 or ipv6 - default is ipv4 */
     virSocketAddr address;      /* Routed Network IP address */
 
@@ -46,15 +50,17 @@ typedef struct {
     unsigned int metric;        /* value for metric (defaults to 1) */
     bool has_metric;            /* metric= was specified */
     virSocketAddr gateway;      /* gateway IP address for ip-route */
-} virNetDevIPRoute, *virNetDevIPRoutePtr;
+};
 
 /* A full set of all IP config info for a network device */
-typedef struct {
+typedef struct _virNetDevIPInfo virNetDevIPInfo;
+typedef virNetDevIPInfo *virNetDevIPInfoPtr;
+ struct _virNetDevIPInfo {
     size_t nips;
     virNetDevIPAddrPtr *ips;
     size_t nroutes;
     virNetDevIPRoutePtr *routes;
-} virNetDevIPInfo, *virNetDevIPInfoPtr;
+};
 
 /* manipulating/querying the netdev */
 int virNetDevIPAddrAdd(const char *ifname,
-- 
2.9.3




More information about the libvir-list mailing list