diff options
author | Thomas Haller <thaller@redhat.com> | 2018-01-28 09:08:20 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-02-12 13:29:03 +0100 |
commit | 7a956644d4971a523cd9eead52516966360fc309 (patch) | |
tree | 197e5f569b74ca5b0fb798cdbfc9ae5a1e8772c9 | |
parent | 3d4181294508d4493355afd06d4f56ea47bba9d9 (diff) | |
download | NetworkManager-7a956644d4971a523cd9eead52516966360fc309.tar.gz |
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.
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 5837a47bc7..f4b25b34e8 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -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); \ |