[network-manager-openvpn] shared: update shared files



commit aac74ca81a4abb36d49da69ca3000221024fd8ed
Author: Thomas Haller <thaller redhat com>
Date:   Tue May 17 18:48:00 2016 +0200

    shared: update shared files
    
    Most importantly, allow for NM_MORE_ASSERTS to be undefined, so that
    we can drop --with-more-asserts from configure.

 properties/import-export.c           |    2 +-
 shared/nm-utils/nm-glib.h            |   18 +++
 shared/nm-utils/nm-macros-internal.h |   31 +++--
 shared/nm-utils/nm-test-utils.h      |  274 +---------------------------------
 4 files changed, 41 insertions(+), 284 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index ee8c104..885f940 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1927,7 +1927,7 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
        args_write_line (f, NMV_OVPN_TAG_USER, NM_OPENVPN_USER);
        args_write_line (f, NMV_OVPN_TAG_GROUP, NM_OPENVPN_GROUP);
 
-       return nm_unauto (&f);
+       return g_steal_pointer (&f);
 }
 
 gboolean
diff --git a/shared/nm-utils/nm-glib.h b/shared/nm-utils/nm-glib.h
index c92d6f0..5f8ebc7 100644
--- a/shared/nm-utils/nm-glib.h
+++ b/shared/nm-utils/nm-glib.h
@@ -374,4 +374,22 @@ _nm_g_hash_table_get_keys_as_array (GHashTable *hash_table,
                                __VA_ARGS__)
 #endif
 
+#if !GLIB_CHECK_VERSION(2, 44, 0)
+static inline gpointer
+g_steal_pointer (gpointer pp)
+{
+       gpointer *ptr = (gpointer *) pp;
+       gpointer ref;
+
+       ref = *ptr;
+       *ptr = NULL;
+
+       return ref;
+}
+
+/* type safety */
+#define g_steal_pointer(pp) \
+  (0 ? (*(pp)) : (g_steal_pointer) (pp))
+#endif
+
 #endif  /* __NM_GLIB_H__ */
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 384bca6..7a5c90f 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -27,6 +27,9 @@
 /********************************************************/
 
 #define _nm_packed __attribute__ ((packed))
+#define _nm_unused __attribute__ ((unused))
+#define _nm_pure   __attribute__ ((pure))
+#define _nm_const  __attribute__ ((const))
 
 #define nm_auto(fcn) __attribute__ ((cleanup(fcn)))
 
@@ -296,6 +299,22 @@ _NM_IN_STRSET_streq (const char *x, const char *s)
 
 /*****************************************************************************/
 
+/* glib/C provides the following kind of assertions:
+ *   - assert() -- disable with NDEBUG
+ *   - g_return_if_fail() -- disable with G_DISABLE_CHECKS
+ *   - g_assert() -- disable with G_DISABLE_ASSERT
+ * but they are all enabled by default and usually even production builds have
+ * these kind of assertions enabled. It also means, that disabling assertions
+ * is an untested configuration, and might have bugs.
+ *
+ * Add our own assertion macro nm_assert(), which is disabled by default and must
+ * be explicitly enabled. They are useful for more expensive checks or checks that
+ * depend less on runtime conditions (that is, are generally expected to be true). */
+
+#ifndef NM_MORE_ASSERTS
+#define NM_MORE_ASSERTS 0
+#endif
+
 #if NM_MORE_ASSERTS
 #define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END
 #define nm_assert_not_reached() G_STMT_START { g_assert_not_reached (); } G_STMT_END
@@ -326,18 +345,6 @@ _notify (obj_type *obj, _PropertyEnums prop) \
 
 /*****************************************************************************/
 
-#define nm_unauto(pp)                                               \
-    ({                                                              \
-        G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));        \
-        gpointer *_pp = (gpointer *) (pp);                          \
-        gpointer _p = *_pp;                                         \
-                                                                    \
-        *_pp = NULL;                                                \
-        _p;                                                         \
-    })
-
-/*****************************************************************************/
-
 static inline gpointer
 nm_g_object_ref (gpointer obj)
 {
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 0875518..ad3cad6 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -101,13 +101,6 @@
 
 #include "nm-utils.h"
 
-#ifdef __NETWORKMANAGER_LOGGING_H__
-/* We are running tests under src/. Let's include some files by default.
- * They are useful, and affect how nm-test-utils.h itself behaves. */
-#include "NetworkManagerUtils.h"
-#include "nm-keyfile-internal.h"
-#endif
-
 /*******************************************************************************/
 
 /* general purpose functions that have no dependency on other nmtst functions */
@@ -510,7 +503,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
 
        if (!__nmtst_internal.assert_logging) {
                gboolean success = TRUE;
-#ifdef __NETWORKMANAGER_LOGGING_H__
+#ifdef _NMTST_INSIDE_CORE
                success = nm_logging_setup (log_level, log_domains, NULL, NULL);
                *out_set_logging = TRUE;
 #endif
@@ -527,7 +520,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
                 * This transforms g_test_expect_message() into a NOP, but we also have to relax
                 * g_log_set_always_fatal(), which was set by g_test_init(). */
                g_log_set_always_fatal (G_LOG_FATAL_MASK);
-#ifdef __NETWORKMANAGER_LOGGING_H__
+#ifdef _NMTST_INSIDE_CORE
                if (c_log_domains || c_log_level) {
                        /* Normally, tests with assert_logging do not overwrite the logging level/domains 
because
                         * the logging statements are part of the assertions. But if the test is run with
@@ -588,27 +581,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
 #endif
 }
 
-#ifdef __NETWORKMANAGER_LOGGING_H__
-inline static void
-nmtst_init_with_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
-{
-       __nmtst_init (argc, argv, FALSE, log_level, log_domains, NULL);
-}
-inline static void
-nmtst_init_assert_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
-{
-       gboolean set_logging;
-
-       __nmtst_init (argc, argv, TRUE, NULL, NULL, &set_logging);
-
-       if (!set_logging) {
-               gboolean success;
-
-               success = nm_logging_setup (log_level, log_domains, NULL, NULL);
-               g_assert (success);
-       }
-}
-#else
+#ifndef _NMTST_INSIDE_CORE
 inline static void
 nmtst_init (int *argc, char ***argv, gboolean assert_logging)
 {
@@ -1175,247 +1148,6 @@ _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, cons
 
 /*******************************************************************************/
 
-#ifdef __NETWORKMANAGER_PLATFORM_H__
-
-inline static NMPlatformIP4Address *
-nmtst_platform_ip4_address (const char *address, const char *peer_address, guint plen)
-{
-       static NMPlatformIP4Address addr;
-
-       g_assert (plen <= 32);
-
-       memset (&addr, 0, sizeof (addr));
-       addr.address = nmtst_inet4_from_string (address);
-       if (peer_address)
-               addr.peer_address = nmtst_inet4_from_string (peer_address);
-       else
-               addr.peer_address = addr.address;
-       addr.plen = plen;
-
-       return &addr;
-}
-
-inline static NMPlatformIP4Address *
-nmtst_platform_ip4_address_full (const char *address, const char *peer_address, guint plen,
-                                 int ifindex, NMIPConfigSource source, guint32 timestamp,
-                                 guint32 lifetime, guint32 preferred, guint32 flags,
-                                 const char *label)
-{
-       NMPlatformIP4Address *addr = nmtst_platform_ip4_address (address, peer_address, plen);
-
-       G_STATIC_ASSERT (IFNAMSIZ == sizeof (addr->label));
-       g_assert (!label || strlen (label) < IFNAMSIZ);
-
-       addr->ifindex = ifindex;
-       addr->addr_source = source;
-       addr->timestamp = timestamp;
-       addr->lifetime = lifetime;
-       addr->preferred = preferred;
-       addr->n_ifa_flags = flags;
-       if (label)
-               g_strlcpy (addr->label, label, sizeof (addr->label));
-
-       return addr;
-}
-
-inline static NMPlatformIP6Address *
-nmtst_platform_ip6_address (const char *address, const char *peer_address, guint plen)
-{
-       static NMPlatformIP6Address addr;
-
-       g_assert (plen <= 128);
-
-       memset (&addr, 0, sizeof (addr));
-       addr.address = *nmtst_inet6_from_string (address);
-       addr.peer_address = *nmtst_inet6_from_string (peer_address);
-       addr.plen = plen;
-
-       return &addr;
-}
-
-inline static NMPlatformIP6Address *
-nmtst_platform_ip6_address_full (const char *address, const char *peer_address, guint plen,
-                                 int ifindex, NMIPConfigSource source, guint32 timestamp,
-                                 guint32 lifetime, guint32 preferred, guint32 flags)
-{
-       NMPlatformIP6Address *addr = nmtst_platform_ip6_address (address, peer_address, plen);
-
-       addr->ifindex = ifindex;
-       addr->addr_source = source;
-       addr->timestamp = timestamp;
-       addr->lifetime = lifetime;
-       addr->preferred = preferred;
-       addr->n_ifa_flags = flags;
-
-       return addr;
-}
-
-inline static NMPlatformIP4Route *
-nmtst_platform_ip4_route (const char *network, guint plen, const char *gateway)
-{
-       static NMPlatformIP4Route route;
-
-       g_assert (plen <= 32);
-
-       memset (&route, 0, sizeof (route));
-       route.network = nmtst_inet4_from_string (network);
-       route.plen = plen;
-       route.gateway = nmtst_inet4_from_string (gateway);
-
-       return &route;
-}
-
-inline static NMPlatformIP4Route *
-nmtst_platform_ip4_route_full (const char *network, guint plen, const char *gateway,
-                               int ifindex, NMIPConfigSource source,
-                               guint metric, guint mss,
-                               guint8 scope,
-                               const char *pref_src)
-{
-       NMPlatformIP4Route *route = nmtst_platform_ip4_route (network, plen, gateway);
-
-       route->ifindex = ifindex;
-       route->rt_source = source;
-       route->metric = metric;
-       route->mss = mss;
-       route->scope_inv = nm_platform_route_scope_inv (scope);
-       route->pref_src = nmtst_inet4_from_string (pref_src);
-
-       return route;
-}
-
-inline static NMPlatformIP6Route *
-nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway)
-{
-       static NMPlatformIP6Route route;
-
-       nm_assert (plen <= 128);
-
-       memset (&route, 0, sizeof (route));
-       route.network = *nmtst_inet6_from_string (network);
-       route.plen = plen;
-       route.gateway = *nmtst_inet6_from_string (gateway);
-
-       return &route;
-}
-
-inline static NMPlatformIP6Route *
-nmtst_platform_ip6_route_full (const char *network, guint plen, const char *gateway,
-                               int ifindex, NMIPConfigSource source,
-                               guint metric, guint mss)
-{
-       NMPlatformIP6Route *route = nmtst_platform_ip6_route (network, plen, gateway);
-
-       route->ifindex = ifindex;
-       route->rt_source = source;
-       route->metric = metric;
-       route->mss = mss;
-
-       return route;
-}
-
-inline static int
-_nmtst_platform_ip4_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
-{
-       return nm_platform_ip4_route_cmp ((const NMPlatformIP4Route *) a, (const NMPlatformIP4Route *) b);
-}
-
-inline static void
-nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gsize len, 
gboolean ignore_order)
-{
-       gsize i;
-       gs_free const NMPlatformIP4Route *c_a = NULL, *c_b = NULL;
-
-       g_assert (a);
-       g_assert (b);
-
-       if (ignore_order) {
-               a = c_a = g_memdup (a, sizeof (NMPlatformIP4Route) * len);
-               b = c_b = g_memdup (b, sizeof (NMPlatformIP4Route) * len);
-               g_qsort_with_data (c_a, len, sizeof (NMPlatformIP4Route), 
_nmtst_platform_ip4_routes_equal_sort, NULL);
-               g_qsort_with_data (c_b, len, sizeof (NMPlatformIP4Route), 
_nmtst_platform_ip4_routes_equal_sort, NULL);
-       }
-
-       for (i = 0; i < len; i++) {
-               if (nm_platform_ip4_route_cmp (&a[i], &b[i]) != 0) {
-                       char buf[sizeof (_nm_utils_to_string_buffer)];
-
-                       g_error ("Error comparing IPv4 route[%lu]: %s vs %s", (long unsigned) i,
-                                nm_platform_ip4_route_to_string (&a[i], NULL, 0),
-                                nm_platform_ip4_route_to_string (&b[i], buf, sizeof (buf)));
-                       g_assert_not_reached ();
-               }
-       }
-}
-
-inline static int
-_nmtst_platform_ip6_routes_equal_sort (gconstpointer a, gconstpointer b, gpointer user_data)
-{
-       return nm_platform_ip6_route_cmp ((const NMPlatformIP6Route *) a, (const NMPlatformIP6Route *) b);
-}
-
-inline static void
-nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gsize len, 
gboolean ignore_order)
-{
-       gsize i;
-       gs_free const NMPlatformIP6Route *c_a = NULL, *c_b = NULL;
-
-       g_assert (a);
-       g_assert (b);
-
-       if (ignore_order) {
-               a = c_a = g_memdup (a, sizeof (NMPlatformIP6Route) * len);
-               b = c_b = g_memdup (b, sizeof (NMPlatformIP6Route) * len);
-               g_qsort_with_data (c_a, len, sizeof (NMPlatformIP6Route), 
_nmtst_platform_ip6_routes_equal_sort, NULL);
-               g_qsort_with_data (c_b, len, sizeof (NMPlatformIP6Route), 
_nmtst_platform_ip6_routes_equal_sort, NULL);
-       }
-
-       for (i = 0; i < len; i++) {
-               if (nm_platform_ip6_route_cmp (&a[i], &b[i]) != 0) {
-                       char buf[sizeof (_nm_utils_to_string_buffer)];
-
-                       g_error ("Error comparing IPv6 route[%lu]: %s vs %s", (long unsigned) i,
-                                nm_platform_ip6_route_to_string (&a[i], NULL, 0),
-                                nm_platform_ip6_route_to_string (&b[i], buf, sizeof (buf)));
-                       g_assert_not_reached ();
-               }
-       }
-}
-
-#endif
-
-
-#ifdef __NETWORKMANAGER_IP4_CONFIG_H__
-
-inline static NMIP4Config *
-nmtst_ip4_config_clone (NMIP4Config *config)
-{
-       NMIP4Config *copy = nm_ip4_config_new (-1);
-
-       g_assert (copy);
-       g_assert (config);
-       nm_ip4_config_replace (copy, config, NULL);
-       return copy;
-}
-
-#endif
-
-
-#ifdef __NETWORKMANAGER_IP6_CONFIG_H__
-
-inline static NMIP6Config *
-nmtst_ip6_config_clone (NMIP6Config *config)
-{
-       NMIP6Config *copy = nm_ip6_config_new (-1);
-
-       g_assert (copy);
-       g_assert (config);
-       nm_ip6_config_replace (copy, config, NULL);
-       return copy;
-}
-
-#endif
-
 #ifdef NM_SETTING_IP_CONFIG_H
 inline static void
 nmtst_setting_ip_config_add_address (NMSettingIPConfig *s_ip,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]