about summary refs log tree commit diff
path: root/shared
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-12-06 21:57:59 +0100
committerMichael Biebl <biebl@debian.org>2020-12-06 21:57:59 +0100
commit65f86e8f56267192d42f2b629fc6b0c99fb9cd0c (patch)
tree180827692f002e5f1dad6a0fa8ca489e6bb6438f /shared
parentf2ddac4cbc895837ddcc55015fae112f9859cd0a (diff)
New upstream version 1.28.0 upstream/1.28.0
Diffstat (limited to 'shared')
-rw-r--r--shared/c-rbtree/src/c-rbtree.h13
-rw-r--r--shared/nm-default.h3
-rw-r--r--shared/nm-glib-aux/nm-glib.h70
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.c8
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h6
-rw-r--r--shared/nm-test-utils-impl.c6
-rw-r--r--shared/nm-utils/nm-test-utils.h83
-rw-r--r--shared/nm-version-macros.h4
8 files changed, 141 insertions, 52 deletions
diff --git a/shared/c-rbtree/src/c-rbtree.h b/shared/c-rbtree/src/c-rbtree.h
index a9bbce52..d4d0fe45 100644
--- a/shared/c-rbtree/src/c-rbtree.h
+++ b/shared/c-rbtree/src/c-rbtree.h
@@ -27,6 +27,7 @@ extern "C" {
 #endif
 
 #include <assert.h>
+#include <stdalign.h>
 #include <stddef.h>
 
 typedef struct CRBNode CRBNode;
@@ -58,7 +59,11 @@ typedef struct CRBTree CRBTree;
  * C_RBNODE_INIT.
  */
 struct CRBNode {
-        unsigned long __parent_and_flags;
+        union {
+                unsigned long __parent_and_flags;
+                /* enforce >=4-byte alignment for @__parent_and_flags */
+                alignas(4) unsigned char __align_dummy;
+        };
         CRBNode *left;
         CRBNode *right;
 };
@@ -88,7 +93,11 @@ void c_rbnode_unlink_stale(CRBNode *n);
  * To initialize an RB-Tree, set it to NULL / all zero.
  */
 struct CRBTree {
-        CRBNode *root;
+        union {
+                CRBNode *root;
+                /* enforce >=4-byte alignment for @root */
+                alignas(4) unsigned char __align_dummy;
+        };
 };
 
 #define C_RBTREE_INIT {}
diff --git a/shared/nm-default.h b/shared/nm-default.h
index 6338c8b8..b322f1d3 100644
--- a/shared/nm-default.h
+++ b/shared/nm-default.h
@@ -73,9 +73,6 @@
     #else
         #error Need to define G_LOG_DOMAIN
     #endif
-#elif defined(NETWORKMANAGER_COMPILATION_TEST) \
-    || (NETWORKMANAGER_COMPILATION & NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON)
-    #error Do not define G_LOG_DOMAIN with NM_NETWORKMANAGER_COMPILATION_WITH_DAEMON
 #endif
 
 /*****************************************************************************/
diff --git a/shared/nm-glib-aux/nm-glib.h b/shared/nm-glib-aux/nm-glib.h
index 5125617d..9794e1fb 100644
--- a/shared/nm-glib-aux/nm-glib.h
+++ b/shared/nm-glib-aux/nm-glib.h
@@ -586,6 +586,49 @@ _nm_g_value_unset(GValue *value)
 
 /*****************************************************************************/
 
+/* g_atomic_pointer_get() is implemented as a macro, and it is also used for
+ * (gsize *) arguments. However, that leads to compiler warnings in certain
+ * configurations. Work around it, by redefining the macro. */
+static inline gpointer
+_g_atomic_pointer_get(void **atomic)
+{
+    return g_atomic_pointer_get(atomic);
+}
+#undef g_atomic_pointer_get
+#define g_atomic_pointer_get(atomic)                                           \
+    ({                                                                         \
+        typeof(*atomic) *const _atomic = (atomic);                             \
+                                                                               \
+        /* g_atomic_pointer_get() is used by glib also for (gsize *) pointers,
+         * not only pointers to pointers. We thus don't enforce that (*atomic)
+         * is a pointer, but of suitable size/alignment. */ \
+                                                                               \
+        G_STATIC_ASSERT(sizeof(*_atomic) == sizeof(gpointer));                 \
+        G_STATIC_ASSERT(_nm_alignof(*_atomic) == _nm_alignof(gpointer));       \
+        (void) (0 ? (gpointer) * (_atomic) : NULL);                            \
+                                                                               \
+        (typeof(*_atomic)) _g_atomic_pointer_get((void **) _atomic);           \
+    })
+
+/* Reimplement g_atomic_pointer_set() macro too. Our variant does more type
+ * checks. */
+static inline void
+_g_atomic_pointer_set(void **atomic, void *newval)
+{
+    return g_atomic_pointer_set(atomic, newval);
+}
+#undef g_atomic_pointer_set
+#define g_atomic_pointer_set(atomic, newval)                        \
+    ({                                                              \
+        typeof(*atomic) *const _atomic                 = (atomic);  \
+        typeof(*_atomic) const _newval                 = (newval);  \
+        _nm_unused gconstpointer const _val_type_check = _newval;   \
+                                                                    \
+        (void) (0 ? (gpointer) * (_atomic) : NULL);                 \
+                                                                    \
+        _g_atomic_pointer_set((void **) _atomic, (void *) _newval); \
+    })
+
 /* Glib implements g_atomic_pointer_compare_and_exchange() as a macro.
  * For one, to inline the atomic operation and also to perform some type checks
  * on the arguments.
@@ -594,22 +637,23 @@ _nm_g_value_unset(GValue *value)
  * pointers there. Reimplement the macro to get that right, but with stronger
  * type checks (as we use typeof()). Had one job. */
 static inline gboolean
-_g_atomic_pointer_compare_and_exchange(volatile void *atomic,
-                                       gconstpointer  oldval,
-                                       gconstpointer  newval)
+_g_atomic_pointer_compare_and_exchange(void **atomic, void *oldval, void *newval)
 {
-    return g_atomic_pointer_compare_and_exchange((void **) atomic,
-                                                 (void *) oldval,
-                                                 (void *) newval);
+    return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
 }
 #undef g_atomic_pointer_compare_and_exchange
-#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval)      \
-    ({                                                                     \
-        typeof(atomic) const _atomic   = (atomic);                         \
-        typeof(*_atomic) const _oldval = (oldval);                         \
-        typeof(*_atomic) const _newval = (newval);                         \
-                                                                           \
-        _g_atomic_pointer_compare_and_exchange(_atomic, _oldval, _newval); \
+#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
+    ({                                                                \
+        typeof(*atomic) *const _atomic                 = (atomic);    \
+        typeof(*_atomic) const _oldval                 = (oldval);    \
+        typeof(*_atomic) const _newval                 = (newval);    \
+        _nm_unused gconstpointer const _val_type_check = _oldval;     \
+                                                                      \
+        (void) (0 ? (gpointer) * (_atomic) : NULL);                   \
+                                                                      \
+        _g_atomic_pointer_compare_and_exchange((void **) _atomic,     \
+                                               (void *) _oldval,      \
+                                               (void *) _newval);     \
     })
 
 /*****************************************************************************/
diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c
index b0e02381..7f766871 100644
--- a/shared/nm-glib-aux/nm-shared-utils.c
+++ b/shared/nm-glib-aux/nm-shared-utils.c
@@ -4115,7 +4115,7 @@ nm_utils_g_slist_strlist_join(const GSList *a, const char *separator)
 
 /*****************************************************************************/
 
-gpointer
+NMUtilsUserData *
 _nm_utils_user_data_pack(int nargs, gconstpointer *args)
 {
     int       i;
@@ -4127,13 +4127,13 @@ _nm_utils_user_data_pack(int nargs, gconstpointer *args)
     data = g_slice_alloc(((gsize) nargs) * sizeof(gconstpointer));
     for (i = 0; i < nargs; i++)
         data[i] = (gpointer) args[i];
-    return data;
+    return (NMUtilsUserData *) data;
 }
 
 void
-_nm_utils_user_data_unpack(gpointer user_data, int nargs, ...)
+_nm_utils_user_data_unpack(NMUtilsUserData *user_data, int nargs, ...)
 {
-    gpointer *data = user_data;
+    gpointer *data = (gpointer *) user_data;
     va_list   ap;
     int       i;
 
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index 83e1c284..23884a37 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -1737,12 +1737,14 @@ nm_utils_process_state_is_dead(char pstate)
 
 /*****************************************************************************/
 
-gpointer _nm_utils_user_data_pack(int nargs, gconstpointer *args);
+typedef struct _NMUtilsUserData NMUtilsUserData;
+
+NMUtilsUserData *_nm_utils_user_data_pack(int nargs, gconstpointer *args);
 
 #define nm_utils_user_data_pack(...) \
     _nm_utils_user_data_pack(NM_NARG(__VA_ARGS__), (gconstpointer[]){__VA_ARGS__})
 
-void _nm_utils_user_data_unpack(gpointer user_data, int nargs, ...);
+void _nm_utils_user_data_unpack(NMUtilsUserData *user_data, int nargs, ...);
 
 #define nm_utils_user_data_unpack(user_data, ...) \
     _nm_utils_user_data_unpack(user_data, NM_NARG(__VA_ARGS__), __VA_ARGS__)
diff --git a/shared/nm-test-utils-impl.c b/shared/nm-test-utils-impl.c
index 7b71484e..57f30ea9 100644
--- a/shared/nm-test-utils-impl.c
+++ b/shared/nm-test-utils-impl.c
@@ -213,7 +213,11 @@ again_wait:
         g_assert(ret == info->pid);
     }
 
-    g_assert(!name_exists(info->bus, "org.freedesktop.NetworkManager"));
+    nmtst_main_context_iterate_until_assert_full(
+        NULL,
+        1000,
+        80,
+        (!name_exists(info->bus, "org.freedesktop.NetworkManager")));
 
     g_clear_object(&info->bus);
 
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 9d484882..62d608c6 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -1131,6 +1131,13 @@ nmtst_g_source_assert_not_called(gpointer user_data)
 }
 
 static inline gboolean
+nmtst_g_source_nop(gpointer user_data)
+{
+    g_assert(!user_data);
+    return G_SOURCE_CONTINUE;
+}
+
+static inline gboolean
 nmtst_g_source_set_boolean_true(gpointer user_data)
 {
     gboolean *ptr = user_data;
@@ -1186,35 +1193,61 @@ _nmtst_main_loop_quit_on_notify(GObject *object, GParamSpec *pspec, gpointer use
 }
 #define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify)
 
-#define nmtst_main_context_iterate_until(context, timeout_msec, condition)                    \
-    ({                                                                                        \
-        nm_auto_destroy_and_unref_gsource GSource *_source      = NULL;                       \
-        GMainContext *                             _context     = (context);                  \
-        gboolean                                   _had_timeout = FALSE;                      \
-                                                                                              \
-        _source = g_timeout_source_new(timeout_msec);                                         \
-        g_source_set_callback(_source, nmtst_g_source_set_boolean_true, &_had_timeout, NULL); \
-        g_source_attach(_source, _context);                                                   \
-                                                                                              \
-        while (TRUE) {                                                                        \
-            if (condition)                                                                    \
-                break;                                                                        \
-            g_main_context_iteration(_context, TRUE);                                         \
-            if (_had_timeout)                                                                 \
-                break;                                                                        \
-        }                                                                                     \
-                                                                                              \
-        !_had_timeout;                                                                        \
+#define nmtst_main_context_iterate_until_full(context, timeout_msec, poll_msec, condition)      \
+    ({                                                                                          \
+        nm_auto_destroy_and_unref_gsource GSource *_source_timeout = NULL;                      \
+        nm_auto_destroy_and_unref_gsource GSource *_source_poll    = NULL;                      \
+        GMainContext *                             _context        = (context);                 \
+        gboolean                                   _had_timeout    = FALSE;                     \
+        typeof(timeout_msec) _timeout_msec0                        = (timeout_msec);            \
+        typeof(poll_msec) _poll_msec0                              = (poll_msec);               \
+        gint64 _timeout_msec                                       = _timeout_msec0;            \
+        guint  _poll_msec                                          = _poll_msec0;               \
+                                                                                                \
+        g_assert_cmpint(_timeout_msec0, ==, _timeout_msec);                                     \
+        g_assert_cmpint(_poll_msec0, ==, _poll_msec);                                           \
+                                                                                                \
+        _source_timeout = g_timeout_source_new(NM_CLAMP(_timeout_msec, 0, (gint64) G_MAXUINT)); \
+        g_source_set_callback(_source_timeout,                                                  \
+                              nmtst_g_source_set_boolean_true,                                  \
+                              &_had_timeout,                                                    \
+                              NULL);                                                            \
+        g_source_attach(_source_timeout, _context);                                             \
+                                                                                                \
+        if (_poll_msec > 0) {                                                                   \
+            _source_poll = g_timeout_source_new(_poll_msec);                                    \
+            g_source_set_callback(_source_poll, nmtst_g_source_nop, NULL, NULL);                \
+            g_source_attach(_source_poll, _context);                                            \
+        }                                                                                       \
+                                                                                                \
+        while (TRUE) {                                                                          \
+            if (condition)                                                                      \
+                break;                                                                          \
+            g_main_context_iteration(_context, TRUE);                                           \
+            if (_had_timeout)                                                                   \
+                break;                                                                          \
+        }                                                                                       \
+                                                                                                \
+        !_had_timeout;                                                                          \
     })
 
-#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \
-    G_STMT_START                                                                  \
-    {                                                                             \
-        if (!nmtst_main_context_iterate_until(context, timeout_msec, condition))  \
-            g_assert(FALSE &&#condition);                                         \
-    }                                                                             \
+#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \
+    nmtst_main_context_iterate_until_full((context), (timeout_msec), 0, condition)
+
+#define nmtst_main_context_iterate_until_assert_full(context, timeout_msec, poll_msec, condition) \
+    G_STMT_START                                                                                  \
+    {                                                                                             \
+        if (!nmtst_main_context_iterate_until_full((context),                                     \
+                                                   (timeout_msec),                                \
+                                                   (poll_msec),                                   \
+                                                   condition))                                    \
+            g_assert(FALSE &&#condition);                                                         \
+    }                                                                                             \
     G_STMT_END
 
+#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \
+    nmtst_main_context_iterate_until_assert_full((context), (timeout_msec), 0, condition)
+
 /*****************************************************************************/
 
 static inline void
diff --git a/shared/nm-version-macros.h b/shared/nm-version-macros.h
index adadb4c0..bbe82a7d 100644
--- a/shared/nm-version-macros.h
+++ b/shared/nm-version-macros.h
@@ -22,7 +22,7 @@
  * Evaluates to the minor version number of NetworkManager which this source
  * is compiled against.
  */
-#define NM_MINOR_VERSION (27)
+#define NM_MINOR_VERSION (28)
 
 /**
  * NM_MICRO_VERSION:
@@ -30,7 +30,7 @@
  * Evaluates to the micro version number of NetworkManager which this source
  * compiled against.
  */
-#define NM_MICRO_VERSION (91)
+#define NM_MICRO_VERSION (0)
 
 /**
  * NM_CHECK_VERSION: