diff options
Diffstat (limited to 'include/nm-glib-compat.h')
| -rw-r--r-- | include/nm-glib-compat.h | 109 |
1 files changed, 68 insertions, 41 deletions
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h index 63d9598d..cfaddb7d 100644 --- a/include/nm-glib-compat.h +++ b/include/nm-glib-compat.h @@ -27,60 +27,87 @@ #include <glib.h> #include <glib-object.h> -#if !GLIB_CHECK_VERSION(2,31,0) -#define g_value_set_schar g_value_set_char -#define g_value_get_schar g_value_get_char -#endif +#include "nm-gvaluearray-compat.h" -#if !GLIB_CHECK_VERSION(2,30,0) -#define G_VALUE_INIT { 0, { { 0 } } } -#endif +#if !GLIB_CHECK_VERSION(2,34,0) +static inline void +g_type_ensure (GType type) +{ + if (G_UNLIKELY (type == (GType)-1)) + g_error ("can't happen"); +} + +#define g_clear_pointer(pp, destroy) \ + G_STMT_START { \ + G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \ + /* Only one access, please */ \ + gpointer *_pp = (gpointer *) (pp); \ + gpointer _p; \ + /* This assignment is needed to avoid a gcc warning */ \ + GDestroyNotify _destroy = (GDestroyNotify) (destroy); \ + \ + (void) (0 ? (gpointer) *(pp) : 0); \ + do \ + _p = g_atomic_pointer_get (_pp); \ + while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \ + \ + if (_p) \ + _destroy (_p); \ + } G_STMT_END + +/* These are used to clean up the output of test programs; we can just let + * them no-op in older glib. + */ +#define g_test_expect_message(log_domain, log_level, pattern) +#define g_test_assert_expected_messages() -#if !GLIB_CHECK_VERSION(2,28,0) -#define g_simple_async_result_take_error(result, error) \ +#else + +/* We build with -DGLIB_MAX_ALLOWED_VERSION set to 2.32 to make sure we don't + * accidentally use new API that we shouldn't. But we don't want warnings for + * the APIs that we emulate above. + */ + +#define g_type_ensure(t) \ G_STMT_START { \ - GError *__error = error; \ - g_simple_async_result_set_from_error (result, __error); \ - g_error_free (__error); \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + g_type_ensure (t); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ } G_STMT_END -#define g_clear_object(object_ptr) \ +#define g_test_expect_message(domain, level, format...) \ G_STMT_START { \ - GObject **__obj_p = (gpointer) (object_ptr); \ - if (*__obj_p) { \ - g_object_unref (*__obj_p); \ - *__obj_p = NULL; \ - } \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + g_test_expect_message (domain, level, format); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ + } G_STMT_END + +#define g_test_assert_expected_messages_internal(domain, file, line, func) \ + G_STMT_START { \ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ + g_test_assert_expected_messages_internal (domain, file, line, func); \ + G_GNUC_END_IGNORE_DEPRECATIONS \ } G_STMT_END #endif -#ifndef G_DEFINE_BOXED_TYPE -#define G_DEFINE_BOXED_TYPE(t,p,d,f) \ -GType \ -p##_get_type (void) \ -{ \ - static volatile gsize g_define_type_id__volatile = 0; \ - \ - if (g_once_init_enter (&g_define_type_id__volatile)) { \ - GType g_define_type_id = \ - g_boxed_type_register_static( \ - g_intern_static_string(#t), \ - (GBoxedCopyFunc) d, \ - (GBoxedFreeFunc) f); \ - g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ - } \ - return g_define_type_id__volatile; \ -} +/* g_test_initialized() is only available since glib 2.36. */ +#if !GLIB_CHECK_VERSION (2, 36, 0) +#define g_test_initialized() (g_test_config_vars->test_initialized) #endif -#if !GLIB_CHECK_VERSION(2,34,0) -static inline void -g_type_ensure (GType type) +/* g_test_skip() is only available since glib 2.38. Add a compatibility wrapper. */ +inline static void +__nmtst_g_test_skip (const gchar *msg) { - if (G_UNLIKELY (type == (GType)-1)) - g_error ("can't happen"); -} +#if GLIB_CHECK_VERSION (2, 38, 0) + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + g_test_skip (msg); + G_GNUC_END_IGNORE_DEPRECATIONS +#else + g_debug ("%s", msg); #endif +} +#define g_test_skip __nmtst_g_test_skip #endif /* NM_GLIB_COMPAT_H */ |