GCC Code Coverage Report


Directory: ./
File: tests/network/nm-utils/nm-glib.h
Date: 2024-05-03 09:46:52
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 * Copyright 2008 - 2018 Red Hat, Inc.
18 */
19
20 #ifndef __NM_GLIB_H__
21 #define __NM_GLIB_H__
22
23
24 #include <gio/gio.h>
25 #include <string.h>
26
27 #include "gsystem-local-alloc.h"
28
29 #ifdef __clang__
30
31 #undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
32 #undef G_GNUC_END_IGNORE_DEPRECATIONS
33
34 #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
35 _Pragma("clang diagnostic push") \
36 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
37
38 #define G_GNUC_END_IGNORE_DEPRECATIONS \
39 _Pragma("clang diagnostic pop")
40
41 #endif
42
43 /* g_assert_cmpmem() is only available since glib 2.46. */
44 #if !GLIB_CHECK_VERSION (2, 45, 7)
45 #define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
46 gconstpointer __m1 = m1, __m2 = m2; \
47 int __l1 = l1, __l2 = l2; \
48 if (__l1 != __l2) \
49 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
50 #l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", __l1, "==", __l2, 'i'); \
51 else if (memcmp (__m1, __m2, __l1) != 0) \
52 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
53 "assertion failed (" #m1 " == " #m2 ")"); \
54 } G_STMT_END
55 #endif
56
57 /* Rumtime check for glib version. First do a compile time check which
58 * (if satisfied) shortcuts the runtime check. */
59 static inline gboolean
60 nm_glib_check_version (guint major, guint minor, guint micro)
61 {
62 return GLIB_CHECK_VERSION (major, minor, micro)
63 || ( ( glib_major_version > major)
64 || ( glib_major_version == major
65 && glib_minor_version > minor)
66 || ( glib_major_version == major
67 && glib_minor_version == minor
68 && glib_micro_version < micro));
69 }
70
71 #if !GLIB_CHECK_VERSION(2, 44, 0)
72 static inline gpointer
73 g_steal_pointer (gpointer pp)
74 {
75 gpointer *ptr = (gpointer *) pp;
76 gpointer ref;
77
78 ref = *ptr;
79 *ptr = NULL;
80
81 return ref;
82 }
83
84 /* type safety */
85 #define g_steal_pointer(pp) \
86 (0 ? (*(pp)) : (g_steal_pointer) (pp))
87 #endif
88
89
90 static inline gboolean
91 31 _nm_g_strv_contains (const gchar * const *strv,
92 const gchar *str)
93 {
94 #if !GLIB_CHECK_VERSION(2, 44, 0)
95 g_return_val_if_fail (strv != NULL, FALSE);
96 g_return_val_if_fail (str != NULL, FALSE);
97
98 for (; *strv != NULL; strv++) {
99 if (g_str_equal (str, *strv))
100 return TRUE;
101 }
102
103 return FALSE;
104 #else
105 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
106 31 return g_strv_contains (strv, str);
107 G_GNUC_END_IGNORE_DEPRECATIONS
108 #endif
109 }
110 #define g_strv_contains _nm_g_strv_contains
111
112 #if !GLIB_CHECK_VERSION (2, 56, 0)
113 #define g_object_ref(Obj) ((typeof(Obj)) g_object_ref (Obj))
114 #define g_object_ref_sink(Obj) ((typeof(Obj)) g_object_ref_sink (Obj))
115 #endif
116
117 #ifndef g_autofree
118 /* we still don't rely on recent glib to provide g_autofree. Hence, we continue
119 * to use our gs_* free macros that we took from libgsystem.
120 *
121 * To ease migration towards g_auto*, add a compat define for g_autofree. */
122 #define g_autofree gs_free
123 #endif
124
125 #endif /* __NM_GLIB_H__ */
126