From 3940d63a7e6bff088bb3fb5e81c8cb2792b19b3a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 5 Sep 2016 16:55:07 +0200 Subject: [PATCH] core: use _NM_GET_PRIVATE() macros (cherry picked from commit cdf6ad40572f23be6f8b6971bd57b1002ffb9aaf) --- src/devices/nm-device-ethernet.c | 13 +----------- src/devices/nm-device-veth.c | 13 +----------- src/devices/nm-device.c | 31 ++++++++++------------------- src/devices/nm-device.h | 2 +- src/devices/wifi/nm-device-wifi.c | 13 +----------- src/devices/wifi/nm-wifi-ap.c | 13 +----------- src/dns-manager/nm-dns-manager.c | 13 +----------- src/nm-auth-subject.c | 13 +----------- src/nm-checkpoint.c | 15 ++------------ src/nm-ip4-config.c | 13 +----------- src/nm-ip6-config.c | 13 +----------- src/nm-manager.c | 15 ++------------ src/rdisc/nm-lndp-rdisc.c | 13 +----------- src/rdisc/nm-rdisc.c | 13 +----------- src/vpn-manager/nm-vpn-connection.c | 13 +----------- 15 files changed, 26 insertions(+), 180 deletions(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 90d472da3b..b213a0ccfc 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -127,18 +127,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceEthernet, G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE) -#define NM_DEVICE_ETHERNET_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMDeviceEthernet *_self2 = (_self); \ - \ - nm_assert (NM_IS_DEVICE_ETHERNET (_self)); \ - _self->_priv; \ - }) +#define NM_DEVICE_ETHERNET_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDeviceEthernet, NM_IS_DEVICE_ETHERNET) /*****************************************************************************/ diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c index cca86fbe90..56923315c6 100644 --- a/src/devices/nm-device-veth.c +++ b/src/devices/nm-device-veth.c @@ -62,18 +62,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVeth, G_DEFINE_TYPE (NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) -#define NM_DEVICE_VETH_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMDeviceVeth *_self2 = (_self); \ - \ - nm_assert (NM_IS_DEVICE_VETH (_self)); \ - &_self->_priv; \ - }) +#define NM_DEVICE_VETH_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceVeth, NM_IS_DEVICE_VETH) /*****************************************************************************/ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 37ab0f26c9..079b15926b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -75,18 +75,7 @@ _LOG_DECLARE_SELF (NMDevice); G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) -#define NM_DEVICE_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMDevice *_self2 = (_self); \ - \ - nm_assert (NM_IS_DEVICE (_self)); \ - _self->priv; \ - }) +#define NM_DEVICE_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMDevice, NM_IS_DEVICE) enum { STATE_CHANGED, @@ -2029,7 +2018,7 @@ link_type_compatible (NMDevice *self, return FALSE; } - device_type = self->priv->link_type; + device_type = self->_priv->link_type; if (device_type > NM_LINK_TYPE_UNKNOWN && device_type != link_type) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, "Needed link type 0x%x does not match the platform link type 0x%X", @@ -10064,7 +10053,7 @@ nm_device_set_unmanaged_by_user_udev (NMDevice *self) int ifindex; gboolean platform_unmanaged = FALSE; - ifindex = self->priv->ifindex; + ifindex = self->_priv->ifindex; if ( ifindex <= 0 || !nm_platform_link_get_unmanaged (NM_PLATFORM_GET, ifindex, &platform_unmanaged)) @@ -10151,7 +10140,7 @@ nm_device_reapply_settings_immediately (NMDevice *self) if (g_strcmp0 ((zone = nm_setting_connection_get_zone (s_con_settings)), nm_setting_connection_get_zone (s_con_applied)) != 0) { - version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request); + version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->_priv->act_request); _LOGD (LOGD_DEVICE, "reapply setting: zone = %s%s%s (version-id %llu)", NM_PRINT_FMT_QUOTE_STRING (zone), (long long unsigned) version_id); g_object_set (G_OBJECT (s_con_applied), @@ -10163,7 +10152,7 @@ nm_device_reapply_settings_immediately (NMDevice *self) if ((metered = nm_setting_connection_get_metered (s_con_settings)) != nm_setting_connection_get_metered (s_con_applied)) { - version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request); + version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->_priv->act_request); _LOGD (LOGD_DEVICE, "reapply setting: metered = %d (version-id %llu)", (int) metered, (long long unsigned) version_id); g_object_set (G_OBJECT (s_con_applied), @@ -10342,22 +10331,22 @@ nm_device_check_connection_available (NMDevice *self, static gboolean available_connections_del_all (NMDevice *self) { - if (g_hash_table_size (self->priv->available_connections) == 0) + if (g_hash_table_size (self->_priv->available_connections) == 0) return FALSE; - g_hash_table_remove_all (self->priv->available_connections); + g_hash_table_remove_all (self->_priv->available_connections); return TRUE; } static gboolean available_connections_add (NMDevice *self, NMConnection *connection) { - return nm_g_hash_table_add (self->priv->available_connections, g_object_ref (connection)); + return nm_g_hash_table_add (self->_priv->available_connections, g_object_ref (connection)); } static gboolean available_connections_del (NMDevice *self, NMConnection *connection) { - return g_hash_table_remove (self->priv->available_connections, connection); + return g_hash_table_remove (self->_priv->available_connections, connection); } static gboolean @@ -12103,7 +12092,7 @@ nm_device_init (NMDevice *self) priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE, NMDevicePrivate); - self->priv = priv; + self->_priv = priv; priv->type = NM_DEVICE_TYPE_UNKNOWN; priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED; diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 34d31cadbf..be12ce7cb2 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -125,7 +125,7 @@ struct _NMDevice { NMExportedObject parent; /* private */ - struct _NMDevicePrivate *priv; + struct _NMDevicePrivate *_priv; }; /* The flags have an relaxing meaning, that means, specifying more flags, can make diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 49c380afb2..f97e668935 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -138,18 +138,7 @@ struct _NMDeviceWifiClass G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE) -#define NM_DEVICE_WIFI_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMDeviceWifi *_self2 = (_self); \ - \ - nm_assert (NM_IS_DEVICE_WIFI (_self)); \ - &_self->_priv; \ - }) +#define NM_DEVICE_WIFI_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceWifi, NM_IS_DEVICE_WIFI) /*****************************************************************************/ diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index e1beb85b09..2232f826c3 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -68,18 +68,7 @@ struct _NMAccessPointClass{ NMExportedObjectClass parent; }; -#define NM_AP_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMAccessPoint *_self2 = (_self); \ - \ - nm_assert (NM_IS_AP (_self)); \ - &_self->_priv; \ - }) +#define NM_AP_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAccessPoint, NM_IS_AP) G_DEFINE_TYPE (NMAccessPoint, nm_ap, NM_TYPE_EXPORTED_OBJECT) diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 3efd5ac1a8..ce8f4d931c 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -151,18 +151,7 @@ G_DEFINE_TYPE (NMDnsManager, nm_dns_manager, G_TYPE_OBJECT) NM_DEFINE_SINGLETON_INSTANCE (NMDnsManager); -#define NM_DNS_MANAGER_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMDnsManager *_self2 = (_self); \ - \ - nm_assert (NM_IS_DNS_MANAGER (_self)); \ - &_self->_priv; \ - }) +#define NM_DNS_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDnsManager, NM_IS_DNS_MANAGER) /*****************************************************************************/ diff --git a/src/nm-auth-subject.c b/src/nm-auth-subject.c index eb496b28cb..54d359598e 100644 --- a/src/nm-auth-subject.c +++ b/src/nm-auth-subject.c @@ -68,18 +68,7 @@ struct _NMAuthSubjectClass { G_DEFINE_TYPE (NMAuthSubject, nm_auth_subject, G_TYPE_OBJECT) -#define NM_AUTH_SUBJECT_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMAuthSubject *_self2 = (_self); \ - \ - nm_assert (NM_IS_AUTH_SUBJECT (_self)); \ - &_self->_priv; \ - }) +#define NM_AUTH_SUBJECT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMAuthSubject, NM_IS_AUTH_SUBJECT) /**************************************************************/ diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index cb1adc3973..605e0700be 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -70,7 +70,7 @@ typedef struct { struct _NMCheckpoint { NMExportedObject parent; - NMCheckpointPrivate priv; + NMCheckpointPrivate _priv; }; typedef struct { @@ -79,18 +79,7 @@ typedef struct { G_DEFINE_TYPE (NMCheckpoint, nm_checkpoint, NM_TYPE_EXPORTED_OBJECT) -#define NM_CHECKPOINT_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMCheckpoint *_self2 = (_self); \ - \ - nm_assert (NM_IS_CHECKPOINT (_self)); \ - &_self->priv; \ - }) +#define NM_CHECKPOINT_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMCheckpoint, NM_IS_CHECKPOINT) NM_GOBJECT_PROPERTIES_DEFINE_BASE ( PROP_DEVICES, diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 22d1d0775c..a4d4361248 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -68,18 +68,7 @@ struct _NMIP4ConfigClass { G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT) -#define NM_IP4_CONFIG_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMIP4Config *_self2 = (_self); \ - \ - nm_assert (NM_IS_IP4_CONFIG (_self)); \ - &_self->_priv; \ - }) +#define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) /* internal guint32 are assigned to gobject properties of type uint. Ensure, that uint is large enough */ G_STATIC_ASSERT (sizeof (uint) >= sizeof (guint32)); diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index ac9e6cd130..8002d61a0a 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -61,18 +61,7 @@ struct _NMIP6ConfigClass { G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT) -#define NM_IP6_CONFIG_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMIP6Config *_self2 = (_self); \ - \ - nm_assert (NM_IS_IP6_CONFIG (_self)); \ - &_self->_priv; \ - }) +#define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG) NM_GOBJECT_PROPERTIES_DEFINE (NMIP6Config, PROP_IFINDEX, diff --git a/src/nm-manager.c b/src/nm-manager.c index 5794bb9ab9..9ad6517dfc 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -158,21 +158,10 @@ typedef struct { NMExportedObjectClass parent; } NMManagerClass; -#define NM_MANAGER_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMManager *_self2 = (_self); \ - \ - nm_assert (NM_IS_MANAGER (_self)); \ - &_self->_priv; \ - }) - G_DEFINE_TYPE (NMManager, nm_manager, NM_TYPE_EXPORTED_OBJECT) +#define NM_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMManager, NM_IS_MANAGER) + enum { DEVICE_ADDED, INTERNAL_DEVICE_ADDED, diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c index 12c2e30d94..db2965b155 100644 --- a/src/rdisc/nm-lndp-rdisc.c +++ b/src/rdisc/nm-lndp-rdisc.c @@ -60,18 +60,7 @@ struct _NMLndpRDiscClass { G_DEFINE_TYPE (NMLndpRDisc, nm_lndp_rdisc, NM_TYPE_RDISC) -#define NM_LNDP_RDISC_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMLndpRDisc *_self2 = (_self); \ - \ - nm_assert (NM_IS_LNDP_RDISC (_self)); \ - &_self->_priv; \ - }) +#define NM_LNDP_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMLndpRDisc, NM_IS_LNDP_RDISC) /*****************************************************************************/ diff --git a/src/rdisc/nm-rdisc.c b/src/rdisc/nm-rdisc.c index cf993bc311..3bc697504a 100644 --- a/src/rdisc/nm-rdisc.c +++ b/src/rdisc/nm-rdisc.c @@ -87,18 +87,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (NMRDisc, nm_rdisc, G_TYPE_OBJECT) -#define NM_RDISC_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMRDisc *_self2 = (_self); \ - \ - nm_assert (NM_IS_RDISC (_self)); \ - _self->_priv; \ - }) +#define NM_RDISC_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMRDisc, NM_IS_RDISC) /*****************************************************************************/ diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c index 92c5bd8fa3..69b45dcc66 100644 --- a/src/vpn-manager/nm-vpn-connection.c +++ b/src/vpn-manager/nm-vpn-connection.c @@ -168,18 +168,7 @@ struct _NMVpnConnectionClass { G_DEFINE_TYPE (NMVpnConnection, nm_vpn_connection, NM_TYPE_ACTIVE_CONNECTION) -#define NM_VPN_CONNECTION_GET_PRIVATE(self) \ - ({ \ - /* preserve the const-ness of self. Unfortunately, that - * way, @self cannot be a void pointer */ \ - typeof (self) _self = (self); \ - \ - /* Get compiler error if variable is of wrong type */ \ - _nm_unused const NMVpnConnection *_self2 = (_self); \ - \ - nm_assert (NM_IS_VPN_CONNECTION (_self)); \ - &_self->_priv; \ - }) +#define NM_VPN_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMVpnConnection, NM_IS_VPN_CONNECTION) /*****************************************************************************/