mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 16:40:16 +01:00
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:
parent
af360238be
commit
3ce2dd4959
1 changed files with 8 additions and 2 deletions
|
|
@ -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) \
|
||||
({ \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue