mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-11-05 19:03:31 +00:00
shared: add NM_UNCONST_PTR() and NM_UNCONST_PPTR()
Add macros that cast away the constness of a pointer, but ensure that the type of the pointer is as expected. Unfortunately, there is no way (AFAIK) to remove the constness of a variable, without explicitly passing @type to the macro.
This commit is contained in:
parent
3d41812945
commit
7a956644d4
1 changed files with 22 additions and 0 deletions
|
@ -389,6 +389,28 @@ NM_G_ERROR_MSG (GError *error)
|
|||
#define NM_CONSTCAST(type, obj, ...) \
|
||||
NM_CONSTCAST_FULL(type, (obj), (obj), ##__VA_ARGS__)
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
#define NM_UNCONST_PTR(type, arg) \
|
||||
_Generic ((arg), \
|
||||
const type *: ((type *) (arg)), \
|
||||
type *: ((type *) (arg)))
|
||||
#else
|
||||
#define NM_UNCONST_PTR(type, arg) \
|
||||
((type *) (arg))
|
||||
#endif
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
#define NM_UNCONST_PPTR(type, arg) \
|
||||
_Generic ((arg), \
|
||||
const type * *: ((type **) (arg)), \
|
||||
type * *: ((type **) (arg)), \
|
||||
const type *const*: ((type **) (arg)), \
|
||||
type *const*: ((type **) (arg)))
|
||||
#else
|
||||
#define NM_UNCONST_PPTR(type, arg) \
|
||||
((type **) (arg))
|
||||
#endif
|
||||
|
||||
#define NM_GOBJECT_CAST(type, obj, is_check, ...) \
|
||||
({ \
|
||||
const void *_obj = (obj); \
|
||||
|
|
Loading…
Reference in a new issue