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, );
This commit is contained in:
Thomas Haller 2022-03-25 11:37:51 +01:00
parent 321b59e84b
commit 681926ad43
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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__)