diff options
author | Thomas Haller <thaller@redhat.com> | 2021-04-15 21:00:09 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-04-20 17:25:20 +0200 |
commit | 4efc6f030a786bcfd47aee31979d87859158bec0 (patch) | |
tree | c51c4a273ff671686446210b5f4bb2a9fcb64e56 | |
parent | 457be83839eaa57047ec20a588520ad037d80e6c (diff) | |
download | NetworkManager-4efc6f030a786bcfd47aee31979d87859158bec0.tar.gz |
glib-aux: add NM_CAST_PPTR() macro
-rw-r--r-- | src/libnm-glib-aux/nm-macros-internal.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index cc3b19c3a1..aaf5cff61a 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -683,6 +683,21 @@ NM_G_ERROR_MSG(GError *error) #define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) G_STRUCT_OFFSET(container, field) #endif +/* Casts (arg) to (type**), but also having a compile time check that + * the arg is some sort of pointer to a pointer. + * + * The only purpose of this macro is some additional compile time safety, + * that the argument is a pointer to pointer. But then it will C cast any kind + * of such argument. */ +#define NM_CAST_PPTR(type, arg) \ + ({ \ + typeof(*(arg)) *const _arg = (arg); \ + typeof(*_arg) _arg2 = _arg ? *_arg : NULL; \ + _nm_unused const void *const _arg3 = _arg2; \ + \ + (type **) _arg; \ + }) + #if _NM_CC_SUPPORT_GENERIC /* these macros cast (value) to * - "const char **" (for "MC", mutable-const) |