| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
glib-compat.h
Go to the documentation of this file.
1
12#ifndef GLIB_COMPAT_H
13#define GLIB_COMPAT_H
14
15#include "ws_symbol_export.h"
16#include "ws_attributes.h"
17
18#include <glib.h>
19#include <string.h>
20
21#ifdef __cplusplus
22 extern "C" {
23#endif /* __cplusplus */
24
25#if !GLIB_CHECK_VERSION(2, 57, 1)
26
36 static inline gboolean
37g_hash_table_steal_extended (GHashTable *hash_table,
38 gconstpointer lookup_key,
39 gpointer *stolen_key,
40 gpointer *stolen_value)
41{
42 gpointer key, value;
43 if (g_hash_table_lookup_extended (hash_table, lookup_key, &key, &value))
44 {
45 stolen_key = &key;
46 stolen_value = &value;
47
48 g_hash_table_steal (hash_table, key);
49
50 return TRUE;
51 } else {
52 if (stolen_key != NULL)
53 *stolen_key = NULL;
54 if (stolen_value != NULL)
55 *stolen_value = NULL;
56 }
57
58 return FALSE;
59}
60
61#endif
62
63#if !GLIB_CHECK_VERSION(2, 60, 0)
64
65#define g_queue_clear_full queue_clear_full
66
76 static inline void
77queue_clear_full (GQueue * queue, GDestroyNotify free_func)
78{
79 gpointer data;
80
81 while ((data = g_queue_pop_head (queue)) != NULL)
82 free_func (data);
83}
84
85#endif
86
87#if !GLIB_CHECK_VERSION(2, 61, 2)
88
89 typedef volatile gint gatomicrefcount;
90
91 typedef struct _GRealArray GRealArray;
92 struct _GRealArray
93{
94 guint8 *data;
95 guint len;
96 guint alloc;
97 guint elt_size;
98 guint zero_terminated ;
99 guint clear;
100 gatomicrefcount ref_count;
101 GDestroyNotify clear_func;
102};
103
117 static inline gboolean
118g_array_binary_search (GArray *array,
119 const void * target,
120 GCompareFunc compare_func,
121 guint *out_match_index)
122{
123 gboolean result = FALSE;
124 GRealArray *_array = (GRealArray *) array;
125 guint left, middle, right;
126 gint val;
127
128 g_return_val_if_fail (_array != NULL, FALSE);
129 g_return_val_if_fail (compare_func != NULL, FALSE);
130
131 if (G_LIKELY(_array->len))
132 {
133 left = 0;
134 right = _array->len - 1;
135
136 while (left <= right)
137 {
138 middle = left + (right - left) / 2;
139
140 val = compare_func (_array->data + (_array->elt_size * middle), target);
141 if (val == 0)
142 {
143 result = TRUE;
144 break;
145 }
146 else if (val < 0)
147 left = middle + 1;
148 else if (/* val > 0 && */ middle > 0)
149 right = middle - 1;
150 else
151 break; /* element not found */
152 }
153 }
154
155 if (result && out_match_index != NULL)
156 *out_match_index = middle;
157
158 return result;
159}
160#endif
161
162#if !GLIB_CHECK_VERSION(2, 64, 0)
163 typedef struct _GRealPtrArray GRealPtrArray;
164
165 struct _GRealPtrArray
166{
167 gpointer *pdata;
168 guint len;
169 guint alloc;
170 gatomicrefcount ref_count;
171 guint8 null_terminated : 1; /* always either 0 or 1, so it can be added to array lengths */
172 GDestroyNotify element_free_func;
173};
174
186 static inline gpointer
187g_array_steal (GArray *array,
188 gsize *len)
189{
190 GRealArray *rarray;
191 gpointer segment;
192
193 g_return_val_if_fail (array != NULL, NULL);
194
195 rarray = (GRealArray *) array;
196 segment = (gpointer) rarray->data;
197
198 if (len != NULL)
199 *len = rarray->len;
200
201 rarray->data = NULL;
202 rarray->len = 0;
203 rarray->alloc = 0;
204 return segment;
205}
206
218 static inline gpointer *
219g_ptr_array_steal (GPtrArray *array,
220 gsize *len)
221{
222 GRealPtrArray *rarray;
223 gpointer *segment;
224
225 g_return_val_if_fail (array != NULL, NULL);
226
227 rarray = (GRealPtrArray *) array;
228 segment = (gpointer *) rarray->pdata;
229
230 if (len != NULL)
231 *len = rarray->len;
232
233 rarray->pdata = NULL;
234 rarray->len = 0;
235 rarray->alloc = 0;
236 return segment;
237}
238
249 static inline guint8 *g_byte_array_steal (GByteArray *array,
250 gsize *len)
251{
252 return (guint8 *) g_array_steal ((GArray *) array, len);
253}
254#endif
255
256#if !GLIB_CHECK_VERSION(2, 68, 0)
257
268 static inline void *
269g_memdup2(const void *mem, size_t byte_size)
270{
271 void * new_mem;
272
273 if (mem && byte_size != 0) {
274 new_mem = g_malloc(byte_size);
275 memcpy(new_mem, mem, byte_size);
276 }
277 else
278 new_mem = NULL;
279
280 return new_mem;
281}
282#endif
283
284#if !GLIB_CHECK_VERSION(2, 74, 0)
285#ifndef G_REGEX_DEFAULT
286#define G_REGEX_DEFAULT ((GRegexCompileFlags)0)
287#endif
288#endif
289
290#if !GLIB_CHECK_VERSION(2, 74, 0)
291#ifndef G_REGEX_MATCH_DEFAULT
292#define G_REGEX_MATCH_DEFAULT ((GRegexMatchFlags)0)
293#endif
294#endif
295
296#ifdef __cplusplus
297}
298#endif /* __cplusplus */
299
300#endif /* GLIB_COMPAT_H */
_GRealArray
Definition glib-compat.h:93
_GRealPtrArray
Definition glib-compat.h:166
segment
Definition tap-tcp-stream.h:43
compare_func
int(* compare_func)(const void *a, const void *b)
Function pointer type for comparing two values.
Definition wmem_tree-int.h:106