mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-30 21:35:41 +00:00
shared/trivial: prettify nm-glib.h compat implementation by grouping code
This commit is contained in:
parent
56ddc8904d
commit
62cd6afd98
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "gsystem-local-alloc.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifdef __clang__
|
||||
|
||||
#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
@ -39,6 +41,8 @@
|
|||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline void
|
||||
__g_type_ensure (GType type)
|
||||
{
|
||||
|
@ -53,6 +57,8 @@ __g_type_ensure (GType type)
|
|||
}
|
||||
#define g_type_ensure __g_type_ensure
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,34,0)
|
||||
|
||||
#define g_clear_pointer(pp, destroy) \
|
||||
|
@ -72,6 +78,12 @@ __g_type_ensure (GType type)
|
|||
} \
|
||||
} G_STMT_END
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,34,0)
|
||||
|
||||
/* These are used to clean up the output of test programs; we can just let
|
||||
* them no-op in older glib.
|
||||
*/
|
||||
|
@ -101,6 +113,7 @@ __g_type_ensure (GType type)
|
|||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 35, 0)
|
||||
/* For glib >= 2.36, g_type_init() is deprecated.
|
||||
|
@ -111,12 +124,15 @@ __g_type_ensure (GType type)
|
|||
#define nm_g_type_init() G_STMT_START { g_type_init (); } G_STMT_END
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* 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
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* g_assert_cmpmem() is only available since glib 2.46. */
|
||||
#if !GLIB_CHECK_VERSION (2, 45, 7)
|
||||
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
|
||||
|
@ -131,6 +147,8 @@ __g_type_ensure (GType type)
|
|||
} G_STMT_END
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Rumtime check for glib version. First do a compile time check which
|
||||
* (if satisfied) shortcuts the runtime check. */
|
||||
static inline gboolean
|
||||
|
@ -145,6 +163,8 @@ nm_glib_check_version (guint major, guint minor, guint micro)
|
|||
&& glib_micro_version < micro));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* g_test_skip() is only available since glib 2.38. Add a compatibility wrapper. */
|
||||
static inline void
|
||||
__nmtst_g_test_skip (const gchar *msg)
|
||||
|
@ -159,6 +179,7 @@ __nmtst_g_test_skip (const gchar *msg)
|
|||
}
|
||||
#define g_test_skip __nmtst_g_test_skip
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* g_test_add_data_func_full() is only available since glib 2.34. Add a compatibility wrapper. */
|
||||
static inline void
|
||||
|
@ -183,6 +204,7 @@ __g_test_add_data_func_full (const char *testpath,
|
|||
}
|
||||
#define g_test_add_data_func_full __g_test_add_data_func_full
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION (2, 34, 0)
|
||||
#define G_DEFINE_QUARK(QN, q_n) \
|
||||
|
@ -198,6 +220,7 @@ q_n##_quark (void) \
|
|||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline gboolean
|
||||
nm_g_hash_table_replace (GHashTable *hash, gpointer key, gpointer value)
|
||||
|
@ -244,6 +267,8 @@ nm_g_hash_table_add (GHashTable *hash, gpointer key)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined (NM_GLIB_COMPAT_H_TEST)
|
||||
static inline void
|
||||
_nm_g_ptr_array_insert (GPtrArray *array,
|
||||
|
@ -264,6 +289,7 @@ _nm_g_ptr_array_insert (GPtrArray *array,
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 40, 0)
|
||||
#define g_ptr_array_insert(array, index, data) G_STMT_START { _nm_g_ptr_array_insert (array, index, data); } G_STMT_END
|
||||
#else
|
||||
|
@ -275,6 +301,7 @@ _nm_g_ptr_array_insert (GPtrArray *array,
|
|||
} G_STMT_END
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION (2, 40, 0)
|
||||
static inline gboolean
|
||||
|
@ -312,6 +339,7 @@ _g_key_file_save_to_file (GKeyFile *key_file,
|
|||
})
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 36, 0)
|
||||
#define g_credentials_get_unix_pid(creds, error) \
|
||||
|
@ -331,6 +359,7 @@ _g_key_file_save_to_file (GKeyFile *key_file,
|
|||
})
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined (NM_GLIB_COMPAT_H_TEST)
|
||||
static inline gpointer *
|
||||
|
@ -371,6 +400,8 @@ _nm_g_hash_table_get_keys_as_array (GHashTable *hash_table,
|
|||
})
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef g_info
|
||||
/* g_info was only added with 2.39.2 */
|
||||
#define g_info(...) g_log (G_LOG_DOMAIN, \
|
||||
|
@ -378,6 +409,8 @@ _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)
|
||||
|
@ -396,6 +429,8 @@ g_steal_pointer (gpointer pp)
|
|||
(0 ? (*(pp)) : (g_steal_pointer) (pp))
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline gboolean
|
||||
_nm_g_strv_contains (const gchar * const *strv,
|
||||
const gchar *str)
|
||||
|
@ -418,6 +453,8 @@ _nm_g_strv_contains (const gchar * const *strv,
|
|||
}
|
||||
#define g_strv_contains _nm_g_strv_contains
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline GVariant *
|
||||
_nm_g_variant_new_take_string (gchar *string)
|
||||
{
|
||||
|
@ -450,6 +487,8 @@ _nm_g_variant_new_take_string (gchar *string)
|
|||
}
|
||||
#define g_variant_new_take_string _nm_g_variant_new_take_string
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 38, 0)
|
||||
_nm_printf (1, 2)
|
||||
static inline GVariant *
|
||||
|
@ -479,11 +518,15 @@ _nm_g_variant_new_printf (const char *format_string, ...)
|
|||
})
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !GLIB_CHECK_VERSION (2, 56, 0)
|
||||
#define g_object_ref(Obj) ((typeof(Obj)) g_object_ref (Obj))
|
||||
#define g_object_ref_sink(Obj) ((typeof(Obj)) g_object_ref_sink (Obj))
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef g_autofree
|
||||
/* we still don't rely on recent glib to provide g_autofree. Hence, we continue
|
||||
* to use our gs_* free macros that we took from libgsystem.
|
||||
|
@ -492,4 +535,6 @@ _nm_g_variant_new_printf (const char *format_string, ...)
|
|||
#define g_autofree gs_free
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_GLIB_H__ */
|
||||
|
|
Loading…
Reference in a new issue