glib-aux: only evaluate arguments to NM_FLAGS_ALL() macro once

In many cases, macros should aim to be function-like. That is,
to evaluate all arguments and evaluate them exactly once.

Fix NM_FLAGS_ALL() to evaluate the "check" argument only once.

One downside of this change is that the result is no longer a compile
time constance and cannot be used to initialize static variables. But
that isn't used much anyway.
This commit is contained in:
Thomas Haller 2021-04-07 14:31:16 +02:00
parent af360238be
commit 3ce2dd4959
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1275,8 +1275,14 @@ default: \
(G_STATIC_ASSERT_EXPR((check) > 0 && ((check) & ((check) -1)) == 0), \
NM_FLAGS_ANY((flags), (check)))
#define NM_FLAGS_ANY(flags, check) ((((flags) & (check)) != 0) ? TRUE : FALSE)
#define NM_FLAGS_ALL(flags, check) ((((flags) & (check)) == (check)) ? TRUE : FALSE)
#define NM_FLAGS_ANY(flags, check) (((flags) & (check)) != 0)
#define NM_FLAGS_ALL(flags, check) \
({ \
const typeof(check) _check = (check); \
\
(((flags) & (_check)) == (_check)); \
})
#define NM_FLAGS_SET(flags, val) \
({ \