summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-07 21:50:33 +0200
committerThomas Haller <thaller@redhat.com>2020-07-07 21:52:22 +0200
commit3b80c6c28f32f901d6fdad80487f231c30b634a1 (patch)
treeee8f06dcd0403dcf4be313d53ce796885d9ed4a5
parentf0deb24249af5edca6e216030ab1f4f17303c74a (diff)
downloadNetworkManager-3b80c6c28f32f901d6fdad80487f231c30b634a1.tar.gz
shared: make NM_BOOLEAN_EXPR() macro composable and use it for _G_BOOLEAN_EXPR()
We redefine _G_BOOLEAN_EXPR(), so let it use NM_BOOLEAN_EXPR(). Also, we use G_LIKELY() (and thus NM_BOOLEAN_EXPR()) inside nm_assert(), and we use nm_assert() in some macros. To be able to nest nm_assert() calls, we need to create unique variable names for NM_BOOLEAN_EXPR().
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h12
-rw-r--r--shared/nm-std-aux/nm-std-aux.h34
2 files changed, 20 insertions, 26 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 97a7f5bfdf..0e261807f9 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -1657,17 +1657,7 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro)
* Workaround that by re-defining _G_BOOLEAN_EXPR()
**/
#undef _G_BOOLEAN_EXPR
-#define __NM_G_BOOLEAN_EXPR_IMPL(v, expr) \
- ({ \
- int NM_UNIQ_T(V, v); \
- \
- if (expr) \
- NM_UNIQ_T(V, v) = 1; \
- else \
- NM_UNIQ_T(V, v) = 0; \
- NM_UNIQ_T(V, v); \
- })
-#define _G_BOOLEAN_EXPR(expr) __NM_G_BOOLEAN_EXPR_IMPL (NM_UNIQ, expr)
+#define _G_BOOLEAN_EXPR(expr) NM_BOOLEAN_EXPR (expr)
#endif
/*****************************************************************************/
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h
index 49f88725ba..aa72f241b2 100644
--- a/shared/nm-std-aux/nm-std-aux.h
+++ b/shared/nm-std-aux/nm-std-aux.h
@@ -54,17 +54,29 @@
/*****************************************************************************/
-#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
-#define NM_BOOLEAN_EXPR(expr) \
+#define NM_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
+#define NM_PASTE(identifier1,identifier2) NM_PASTE_ARGS (identifier1, identifier2)
+
+/* Taken from systemd's UNIQ_T and UNIQ macros. */
+
+#define NM_UNIQ_T(x, uniq) NM_PASTE(__unique_prefix_, NM_PASTE(x, uniq))
+#define NM_UNIQ __COUNTER__
+
+/*****************************************************************************/
+
+#define _NM_BOOLEAN_EXPR_IMPL(v, expr) \
({ \
- int _g_boolean_var_; \
+ int NM_UNIQ_T(V, v); \
\
if (expr) \
- _g_boolean_var_ = 1; \
- else \
- _g_boolean_var_ = 0; \
- _g_boolean_var_; \
+ NM_UNIQ_T(V, v) = 1; \
+ else \
+ NM_UNIQ_T(V, v) = 0; \
+ NM_UNIQ_T(V, v); \
})
+#define NM_BOOLEAN_EXPR(expr) _NM_BOOLEAN_EXPR_IMPL (NM_UNIQ, expr)
+
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define NM_LIKELY(expr) (__builtin_expect (NM_BOOLEAN_EXPR (expr), 1))
#define NM_UNLIKELY(expr) (__builtin_expect (NM_BOOLEAN_EXPR (expr), 0))
#else
@@ -112,14 +124,6 @@
#define NM_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
-#define NM_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
-#define NM_PASTE(identifier1,identifier2) NM_PASTE_ARGS (identifier1, identifier2)
-
-/* Taken from systemd's UNIQ_T and UNIQ macros. */
-
-#define NM_UNIQ_T(x, uniq) NM_PASTE(__unique_prefix_, NM_PASTE(x, uniq))
-#define NM_UNIQ __COUNTER__
-
/*****************************************************************************/
/* glib's MIN()/MAX() macros don't have function-like behavior, in that they evaluate