mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 06:00:08 +01:00
shared: make NM_CONSTCAST() macro variadic
We need to pass more alias-types. Instead of having numbered
versions, use variadic number of macro arguments.
Also, fix build failure with old compiler:
In file included from src/nm-ip6-config.c:24:
./src/nm-ip6-config.h:44:29: error: controlling expression type 'typeof (ipconf_iter->current->obj)' (aka 'const void *const') not compatible with any generic association type
*out_address = has_next ? NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj) : NULL;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixes: b1810d7a68
(cherry picked from commit b339a2742a)
This commit is contained in:
parent
fda3458201
commit
dd02e4bfce
4 changed files with 86 additions and 57 deletions
|
|
@ -270,63 +270,94 @@ NM_G_ERROR_MSG (GError *error)
|
|||
#endif
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
#define _NM_CONSTCAST_FULL(type, obj_expr, obj) \
|
||||
#define _NM_CONSTCAST_FULL_1(type, obj_expr, obj) \
|
||||
(_Generic ((obj_expr), \
|
||||
const void * : ((const type *) (obj)), \
|
||||
void * : (( type *) (obj)), \
|
||||
const type * : ((const type *) (obj)), \
|
||||
type * : (( type *) (obj))))
|
||||
#define _NM_CONSTCAST2_FULL(type, obj_expr, obj, alias_type2) \
|
||||
const void *const: ((const type *) (obj)), \
|
||||
const void * : ((const type *) (obj)), \
|
||||
void *const: (( type *) (obj)), \
|
||||
void * : (( type *) (obj)), \
|
||||
const type *const: ((const type *) (obj)), \
|
||||
const type * : ((const type *) (obj)), \
|
||||
type *const: (( type *) (obj)), \
|
||||
type * : (( type *) (obj))))
|
||||
#define _NM_CONSTCAST_FULL_2(type, obj_expr, obj, alias_type2) \
|
||||
(_Generic ((obj_expr), \
|
||||
const void *: ((const type *) (obj)), \
|
||||
void *: (( type *) (obj)), \
|
||||
const alias_type2 *: ((const type *) (obj)), \
|
||||
alias_type2 *: (( type *) (obj)), \
|
||||
const type *: ((const type *) (obj)), \
|
||||
type *: (( type *) (obj))))
|
||||
#define _NM_CONSTCAST3_FULL(type, obj_expr, obj, alias_type2, alias_type3) \
|
||||
const void *const: ((const type *) (obj)), \
|
||||
const void * : ((const type *) (obj)), \
|
||||
void *const: (( type *) (obj)), \
|
||||
void * : (( type *) (obj)), \
|
||||
const alias_type2 *const: ((const type *) (obj)), \
|
||||
const alias_type2 * : ((const type *) (obj)), \
|
||||
alias_type2 *const: (( type *) (obj)), \
|
||||
alias_type2 * : (( type *) (obj)), \
|
||||
const type *const: ((const type *) (obj)), \
|
||||
const type * : ((const type *) (obj)), \
|
||||
type *const: (( type *) (obj)), \
|
||||
type * : (( type *) (obj))))
|
||||
#define _NM_CONSTCAST_FULL_3(type, obj_expr, obj, alias_type2, alias_type3) \
|
||||
(_Generic ((obj_expr), \
|
||||
const void *: ((const type *) (obj)), \
|
||||
void *: (( type *) (obj)), \
|
||||
const alias_type2 *: ((const type *) (obj)), \
|
||||
alias_type2 *: (( type *) (obj)), \
|
||||
const alias_type3 *: ((const type *) (obj)), \
|
||||
alias_type3 *: (( type *) (obj)), \
|
||||
const type *: ((const type *) (obj)), \
|
||||
type *: (( type *) (obj))))
|
||||
const void *const: ((const type *) (obj)), \
|
||||
const void * : ((const type *) (obj)), \
|
||||
void *const: (( type *) (obj)), \
|
||||
void * : (( type *) (obj)), \
|
||||
const alias_type2 *const: ((const type *) (obj)), \
|
||||
const alias_type2 * : ((const type *) (obj)), \
|
||||
alias_type2 *const: (( type *) (obj)), \
|
||||
alias_type2 * : (( type *) (obj)), \
|
||||
const alias_type3 *const: ((const type *) (obj)), \
|
||||
const alias_type3 * : ((const type *) (obj)), \
|
||||
alias_type3 *const: (( type *) (obj)), \
|
||||
alias_type3 * : (( type *) (obj)), \
|
||||
const type *const: ((const type *) (obj)), \
|
||||
const type * : ((const type *) (obj)), \
|
||||
type *const: (( type *) (obj)), \
|
||||
type * : (( type *) (obj))))
|
||||
#define _NM_CONSTCAST_FULL_4(type, obj_expr, obj, alias_type2, alias_type3, alias_type4) \
|
||||
(_Generic ((obj_expr), \
|
||||
const void *const: ((const type *) (obj)), \
|
||||
const void * : ((const type *) (obj)), \
|
||||
void *const: (( type *) (obj)), \
|
||||
void * : (( type *) (obj)), \
|
||||
const alias_type2 *const: ((const type *) (obj)), \
|
||||
const alias_type2 * : ((const type *) (obj)), \
|
||||
alias_type2 *const: (( type *) (obj)), \
|
||||
alias_type2 * : (( type *) (obj)), \
|
||||
const alias_type3 *const: ((const type *) (obj)), \
|
||||
const alias_type3 * : ((const type *) (obj)), \
|
||||
alias_type3 *const: (( type *) (obj)), \
|
||||
alias_type3 * : (( type *) (obj)), \
|
||||
const alias_type4 *const: ((const type *) (obj)), \
|
||||
const alias_type4 * : ((const type *) (obj)), \
|
||||
alias_type4 *const: (( type *) (obj)), \
|
||||
alias_type4 * : (( type *) (obj)), \
|
||||
const type *const: ((const type *) (obj)), \
|
||||
const type * : ((const type *) (obj)), \
|
||||
type *const: (( type *) (obj)), \
|
||||
type * : (( type *) (obj))))
|
||||
#define _NM_CONSTCAST_FULL_x(type, obj_expr, obj, n, ...) (_NM_CONSTCAST_FULL_##n (type, obj_expr, obj, ##__VA_ARGS__))
|
||||
#define _NM_CONSTCAST_FULL_y(type, obj_expr, obj, n, ...) (_NM_CONSTCAST_FULL_x (type, obj_expr, obj, n, ##__VA_ARGS__))
|
||||
#define NM_CONSTCAST_FULL( type, obj_expr, obj, ...) (_NM_CONSTCAST_FULL_y (type, obj_expr, obj, NM_NARG (dummy, ##__VA_ARGS__), ##__VA_ARGS__))
|
||||
#else
|
||||
/* _NM_CONSTCAST() is there to preserve constness of a pointer.
|
||||
* It uses C11's _Generic(). If that is not supported, we fall back
|
||||
* to casting away constness. So, with _Generic, we get some additional
|
||||
* static type checking by preserving constness, without, we cast it
|
||||
* to a non-const pointer. */
|
||||
#define _NM_CONSTCAST_FULL(type, obj_expr, obj) \
|
||||
((type *) (obj))
|
||||
#define _NM_CONSTCAST2_FULL(type, obj_expr, obj, alias_type2) \
|
||||
((type *) (obj))
|
||||
#define _NM_CONSTCAST3_FULL(type, obj_expr, obj, alias_type2, alias_type2) \
|
||||
((type *) (obj))
|
||||
#define NM_CONSTCAST_FULL( type, obj_expr, obj, ...) ((type *) (obj))
|
||||
#endif
|
||||
|
||||
#define _NM_CONSTCAST(type, obj) \
|
||||
_NM_CONSTCAST_FULL(type, (obj), (obj))
|
||||
#define NM_CONSTCAST(type, obj, ...) \
|
||||
NM_CONSTCAST_FULL(type, (obj), (obj), ##__VA_ARGS__)
|
||||
|
||||
#define _NM_CONSTCAST2(type, obj, alias_type2) \
|
||||
_NM_CONSTCAST2_FULL(type, (obj), (obj), alias_type2)
|
||||
|
||||
#define _NM_GOBJECT_CAST(type, obj, is_check) \
|
||||
#define NM_GOBJECT_CAST(type, obj, is_check, ...) \
|
||||
({ \
|
||||
const void *_obj = (obj); \
|
||||
\
|
||||
nm_assert (is_check (_obj)); \
|
||||
_NM_CONSTCAST2_FULL (type, (obj), _obj, GObject); \
|
||||
nm_assert (_obj || (is_check (_obj))); \
|
||||
NM_CONSTCAST_FULL (type, (obj), _obj, GObject, ##__VA_ARGS__); \
|
||||
})
|
||||
#define _NM_GOBJECT_CAST2(type, obj, is_check, alias_type2) \
|
||||
|
||||
#define NM_GOBJECT_CAST_NON_NULL(type, obj, is_check, ...) \
|
||||
({ \
|
||||
const void *_obj = (obj); \
|
||||
\
|
||||
nm_assert (is_check (_obj)); \
|
||||
_NM_CONSTCAST3_FULL (type, (obj), _obj, GObject, alias_type2); \
|
||||
NM_CONSTCAST_FULL (type, (obj), _obj, GObject, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
|
|
@ -620,10 +651,8 @@ _notify (obj_type *obj, _PropertyEnums prop) \
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _NM_GET_PRIVATE( self, type, is_check) (&(_NM_GOBJECT_CAST (type, (self), is_check )->_priv))
|
||||
#define _NM_GET_PRIVATE_PTR( self, type, is_check) ( (_NM_GOBJECT_CAST (type, (self), is_check )->_priv))
|
||||
#define _NM_GET_PRIVATE2( self, type, is_check, alias_type2) (&(_NM_GOBJECT_CAST2 (type, (self), is_check, alias_type2)->_priv))
|
||||
#define _NM_GET_PRIVATE2_PTR(self, type, is_check, alias_type2) ( (_NM_GOBJECT_CAST2 (type, (self), is_check, alias_type2)->_priv))
|
||||
#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))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ struct _NMDeviceVlanClass {
|
|||
|
||||
G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
|
||||
|
||||
#define NM_DEVICE_VLAN_GET_PRIVATE(self) _NM_GET_PRIVATE2 (self, NMDeviceVlan, NM_IS_DEVICE_VLAN, NMDevice)
|
||||
#define NM_DEVICE_VLAN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceVlan, NM_IS_DEVICE_VLAN, NMDevice)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -2867,7 +2867,7 @@ struct _NMLinuxPlatformClass {
|
|||
|
||||
G_DEFINE_TYPE (NMLinuxPlatform, nm_linux_platform, NM_TYPE_PLATFORM)
|
||||
|
||||
#define NM_LINUX_PLATFORM_GET_PRIVATE(self) _NM_GET_PRIVATE2(self, NMLinuxPlatform, NM_IS_LINUX_PLATFORM, NMPlatform)
|
||||
#define NM_LINUX_PLATFORM_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMLinuxPlatform, NM_IS_LINUX_PLATFORM, NMPlatform)
|
||||
|
||||
NMPlatform *
|
||||
nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support)
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_LINK); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->link : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->link : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP_ADDRESS(obj) \
|
||||
|
|
@ -349,7 +349,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip_address : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip_address : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IPX_ADDRESS(obj) \
|
||||
|
|
@ -357,7 +357,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ipx_address : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ipx_address : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP4_ADDRESS(obj) \
|
||||
|
|
@ -365,7 +365,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP4_ADDRESS); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip4_address : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip4_address : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP6_ADDRESS(obj) \
|
||||
|
|
@ -373,7 +373,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP6_ADDRESS); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip6_address : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip6_address : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IPX_ROUTE(obj) \
|
||||
|
|
@ -381,7 +381,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ipx_route : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ipx_route : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP_ROUTE(obj) \
|
||||
|
|
@ -389,7 +389,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip_route : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip_route : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP4_ROUTE(obj) \
|
||||
|
|
@ -397,7 +397,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP4_ROUTE); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip4_route : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip4_route : NULL; \
|
||||
})
|
||||
|
||||
#define NMP_OBJECT_CAST_IP6_ROUTE(obj) \
|
||||
|
|
@ -405,7 +405,7 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|||
typeof (obj) _obj = (obj); \
|
||||
\
|
||||
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP6_ROUTE); \
|
||||
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip6_route : NULL; \
|
||||
_obj ? &NM_CONSTCAST (NMPObject, _obj)->ip6_route : NULL; \
|
||||
})
|
||||
|
||||
const NMPClass *nmp_class_from_type (NMPObjectType obj_type);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue