diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-10 09:32:14 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-13 11:35:44 +0100 |
commit | bdfdabea51bb19f9bf9a95a57e80ab98d4b3122f (patch) | |
tree | 88521e4c93e9bf5016d90ca6e1702838a8ec239c | |
parent | 03efc9e2c94e47383f019a972010057535303fa0 (diff) | |
download | NetworkManager-bdfdabea51bb19f9bf9a95a57e80ab98d4b3122f.tar.gz |
shared: propagate constness in _NM_GET_PRIVATE_PTR()
The _NM_GET_PRIVATE() macro already preserved and propagated
the constness of @self to the resulting private pointer.
_NM_GET_PRIVATE_PTR() didn't do that. Extend the macro,
to make that possible.
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 30 | ||||
-rw-r--r-- | src/devices/nm-device.c | 4 | ||||
-rw-r--r-- | src/devices/nm-device.h | 2 |
3 files changed, 31 insertions, 5 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 515e8b5c3e..49bc79e582 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -263,6 +263,13 @@ NM_G_ERROR_MSG (GError *error) /*****************************************************************************/ +#if (defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9 ))) +#define _NM_CC_SUPPORT_AUTO_TYPE 1 +#define _nm_auto_type __auto_type +#else +#define _NM_CC_SUPPORT_AUTO_TYPE 0 +#endif + #if (defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9 ))) || (defined (__clang__)) #define _NM_CC_SUPPORT_GENERIC 1 #else @@ -372,6 +379,16 @@ NM_G_ERROR_MSG (GError *error) #define _NM_ENSURE_TYPE(type, value) (value) #endif +#if _NM_CC_SUPPORT_GENERIC +#define NM_PROPAGATE_CONST(test_expr, ptr) \ + (_Generic ((test_expr), \ + const typeof (*(test_expr)) *: ((const typeof (*(ptr)) *) (ptr)), \ + default: (_Generic ((test_expr), \ + typeof (*(test_expr)) *: (ptr))))) +#else +#define NM_PROPAGATE_CONST(test_expr, ptr) (ptr) +#endif + /*****************************************************************************/ #define _NM_IN_SET_EVAL_1( op, _x, y) (_x == (y)) @@ -651,8 +668,17 @@ _notify (obj_type *obj, _PropertyEnums prop) \ /*****************************************************************************/ -#define _NM_GET_PRIVATE( self, type, is_check, ...) (&(NM_GOBJECT_CAST_NON_NULL (type, (self), is_check, ##__VA_ARGS__)->_priv)) -#define _NM_GET_PRIVATE_PTR( self, type, is_check, ...) ( (NM_GOBJECT_CAST_NON_NULL (type, (self), is_check, ##__VA_ARGS__)->_priv)) +#define _NM_GET_PRIVATE(self, type, is_check, ...) (&(NM_GOBJECT_CAST_NON_NULL (type, (self), is_check, ##__VA_ARGS__)->_priv)) +#if _NM_CC_SUPPORT_AUTO_TYPE +#define _NM_GET_PRIVATE_PTR(self, type, is_check, ...) \ + ({ \ + _nm_auto_type _self = NM_GOBJECT_CAST_NON_NULL (type, (self), is_check, ##__VA_ARGS__); \ + \ + NM_PROPAGATE_CONST (_self, _self->_priv); \ + }) +#else +#define _NM_GET_PRIVATE_PTR(self, type, is_check, ...) (NM_GOBJECT_CAST_NON_NULL (type, (self), is_check, ##__VA_ARGS__)->_priv) +#endif /*****************************************************************************/ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 010172dc06..1fe6f064da 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1164,9 +1164,9 @@ nm_device_get_ip_iface (NMDevice *self) } int -nm_device_get_ip_ifindex (NMDevice *self) +nm_device_get_ip_ifindex (const NMDevice *self) { - NMDevicePrivate *priv; + const NMDevicePrivate *priv; g_return_val_if_fail (self != NULL, 0); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index bd8104b4bf..b0d299e4ea 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -438,7 +438,7 @@ int nm_device_get_ifindex (NMDevice *dev); gboolean nm_device_is_software (NMDevice *dev); gboolean nm_device_is_real (NMDevice *dev); const char * nm_device_get_ip_iface (NMDevice *dev); -int nm_device_get_ip_ifindex (NMDevice *dev); +int nm_device_get_ip_ifindex (const NMDevice *dev); const char * nm_device_get_driver (NMDevice *dev); const char * nm_device_get_driver_version (NMDevice *dev); const char * nm_device_get_type_desc (NMDevice *dev); |