summaryrefslogtreecommitdiff
path: root/shared/nm-glib-aux/nm-macros-internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/nm-glib-aux/nm-macros-internal.h')
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h79
1 files changed, 61 insertions, 18 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 52591040e2..758a4ec9aa 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -757,6 +757,17 @@ NM_G_ERROR_MSG (GError *error)
/*****************************************************************************/
+#define NM_SWAP(a, b) \
+ G_STMT_START { \
+ typeof (a) _tmp; \
+ \
+ _tmp = (a); \
+ (a) = (b); \
+ (b) = _tmp; \
+ } G_STMT_END
+
+/*****************************************************************************/
+
static inline gboolean
_NM_IN_STRSET_streq (const char *x, const char *s)
{
@@ -1023,19 +1034,37 @@ nm_str_realloc (char *str)
#define nm_assert_not_reached() G_STMT_START { ; } G_STMT_END
#endif
+/* Usage:
+ *
+ * if (NM_MORE_ASSERT_ONCE (5)) { extra_check (); }
+ *
+ * This will only run the check once, and only if NM_MORE_ASSERT is >= than
+ * more_assert_level.
+ */
+#define NM_MORE_ASSERT_ONCE(more_assert_level) \
+ ( (NM_MORE_ASSERTS >= (more_assert_level)) \
+ && ({ \
+ static volatile int _assert_once = 0; \
+ \
+ G_STATIC_ASSERT_EXPR ((more_assert_level) >= 0); \
+ \
+ G_UNLIKELY ( _assert_once == 0 \
+ && g_atomic_int_compare_and_exchange (&_assert_once, 0, 1)); \
+ }))
+
/*****************************************************************************/
-#define NM_GOBJECT_PROPERTIES_DEFINE_BASE(...) \
+#define NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL(suffix, ...) \
typedef enum { \
- PROP_0, \
+ PROP_0##suffix, \
__VA_ARGS__ \
- _PROPERTY_ENUMS_LAST, \
-} _PropertyEnums; \
-static GParamSpec *obj_properties[_PROPERTY_ENUMS_LAST] = { NULL, }
+ _PROPERTY_ENUMS_LAST##suffix, \
+} _PropertyEnums##suffix; \
+static GParamSpec *obj_properties##suffix[_PROPERTY_ENUMS_LAST##suffix] = { NULL, }
-#define NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY(obj_type, obj_properties, property_enums_type, prop_0) \
+#define NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY(suffix, obj_type) \
static inline void \
-_nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_type *props) \
+_nm_gobject_notify_together_impl##suffix (obj_type *obj, guint n, const _PropertyEnums##suffix *props) \
{ \
const gboolean freeze_thaw = (n > 1); \
\
@@ -1045,12 +1074,12 @@ _nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_t
if (freeze_thaw) \
g_object_freeze_notify ((GObject *) obj); \
while (n-- > 0) { \
- const property_enums_type prop = *props++; \
+ const _PropertyEnums##suffix prop = *props++; \
\
- if (prop != prop_0) { \
- nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties)); \
- nm_assert (obj_properties[prop]); \
- g_object_notify_by_pspec ((GObject *) obj, obj_properties[prop]); \
+ if (prop != PROP_0##suffix) { \
+ nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties##suffix)); \
+ nm_assert (obj_properties##suffix[prop]); \
+ g_object_notify_by_pspec ((GObject *) obj, obj_properties##suffix[prop]); \
} \
} \
if (freeze_thaw) \
@@ -1058,20 +1087,29 @@ _nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_t
} \
\
_nm_unused static inline void \
-_notify (obj_type *obj, property_enums_type prop) \
+_notify##suffix (obj_type *obj, _PropertyEnums##suffix prop) \
{ \
- _nm_gobject_notify_together_impl (obj, 1, &prop); \
+ _nm_gobject_notify_together_impl##suffix (obj, 1, &prop); \
} \
+#define NM_GOBJECT_PROPERTIES_DEFINE_BASE(...) \
+ NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL (, __VA_ARGS__); \
+
+#define NM_GOBJECT_PROPERTIES_DEFINE_FULL(suffix, obj_type, ...) \
+ NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL (suffix, __VA_ARGS__); \
+ NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY (suffix, obj_type)
+
#define NM_GOBJECT_PROPERTIES_DEFINE(obj_type, ...) \
-NM_GOBJECT_PROPERTIES_DEFINE_BASE (__VA_ARGS__); \
-NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY (obj_type, obj_properties, _PropertyEnums, PROP_0)
+ NM_GOBJECT_PROPERTIES_DEFINE_FULL (, obj_type, __VA_ARGS__)
/* 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(obj, ...) \
- _nm_gobject_notify_together_impl (obj, NM_NARG (__VA_ARGS__), (const _PropertyEnums[]) { __VA_ARGS__ })
+ nm_gobject_notify_together_full (, obj, __VA_ARGS__)
/*****************************************************************************/
@@ -1452,7 +1490,12 @@ _NM_BACKPORT_SYMBOL_IMPL(version, return_type, func, _##func##_##version, args_t
/*****************************************************************************/
/* mirrors g_ascii_isspace() and what we consider spaces in general. */
-#define NM_ASCII_SPACES "\t\n\f\r "
+#define NM_ASCII_SPACES " \n\t\r\f"
+
+/* Like NM_ASCII_SPACES, but without "\f" (0x0c, Formfeed Page Break).
+ * This is what for example systemd calls WHITESPACE and what it uses to tokenize
+ * the kernel command line. */
+#define NM_ASCII_WHITESPACES " \n\t\r"
#define nm_str_skip_leading_spaces(str) \
({ \