diff options
author | Thomas Haller <thaller@redhat.com> | 2022-03-25 11:37:51 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-28 18:27:35 +0200 |
commit | 681926ad433f41c546f88dcb9becc0d0b06cc20b (patch) | |
tree | c47b131616888055a8a4d38296b639ce982c5c27 | |
parent | 321b59e84bf74233c043bfa58e7e4f78c6308580 (diff) |
glib-aux: make nm_gobject_notify_together_full() macro more robust
If __VA_ARGS__ contains odd arguments, it's not clear that N_ARG() gives
the same as the array initialization. Add a static assert that the
numbers agree to catch wrong usage of the macro.
For example:
nm_gobject_notify_together(setting, a, b, );
-rw-r--r-- | src/libnm-glib-aux/nm-macros-internal.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 140104d350..7cc8ac9797 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -620,10 +620,16 @@ nm_str_realloc(char *str) /* invokes _notify() for all arguments (of type _PropertyEnums). Note, that if * there are more than one prop arguments, this will involve a freeze/thaw * of GObject property notifications. */ -#define nm_gobject_notify_together_full(suffix, obj, ...) \ - _nm_gobject_notify_together_impl##suffix(obj, \ - NM_NARG(__VA_ARGS__), \ - (const _PropertyEnums##suffix[]){__VA_ARGS__}) +#define nm_gobject_notify_together_full(suffix, obj, ...) \ + G_STMT_START \ + { \ + const _PropertyEnums##suffix _props[] = {__VA_ARGS__}; \ + \ + G_STATIC_ASSERT(G_N_ELEMENTS(_props) == NM_NARG(__VA_ARGS__)); \ + \ + _nm_gobject_notify_together_impl##suffix(obj, G_N_ELEMENTS(_props), _props); \ + } \ + G_STMT_END #define nm_gobject_notify_together(obj, ...) nm_gobject_notify_together_full(, obj, __VA_ARGS__) |