| Wireshark 4.7.3 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;
95 struct _GRealArray {
96 guint8 *data;
97 guint len;
98 guint alloc;
99 guint elt_size;
100 guint zero_terminated;
101 guint clear;
102 gatomicrefcount ref_count;
103 GDestroyNotify clear_func;
104};
105
119 static inline gboolean
120g_array_binary_search (GArray *array,
121 const void * target,
122 GCompareFunc compare_func,
123 guint *out_match_index)
124{
125 gboolean result = FALSE;
126 GRealArray *_array = (GRealArray *) array;
127 guint left, middle, right;
128 gint val;
129
130 g_return_val_if_fail (_array != NULL, FALSE);
131 g_return_val_if_fail (compare_func != NULL, FALSE);
132
133 if (G_LIKELY(_array->len))
134 {
135 left = 0;
136 right = _array->len - 1;
137
138 while (left <= right)
139 {
140 middle = left + (right - left) / 2;
141
142 val = compare_func (_array->data + (_array->elt_size * middle), target);
143 if (val == 0)
144 {
145 result = TRUE;
146 break;
147 }
148 else if (val < 0)
149 left = middle + 1;
150 else if (/* val > 0 && */ middle > 0)
151 right = middle - 1;
152 else
153 break; /* element not found */
154 }
155 }
156
157 if (result && out_match_index != NULL)
158 *out_match_index = middle;
159
160 return result;
161}
162#endif
163
164#if !GLIB_CHECK_VERSION(2, 64, 0)
165 typedef struct _GRealPtrArray GRealPtrArray;
166
167
171 struct _GRealPtrArray {
172 gpointer *pdata;
173 guint len;
174 guint alloc;
175 gatomicrefcount ref_count;
176 guint8 null_terminated:1;
177 GDestroyNotify element_free_func;
178};
179
191 static inline gpointer
192g_array_steal (GArray *array,
193 gsize *len)
194{
195 GRealArray *rarray;
196 gpointer segment;
197
198 g_return_val_if_fail (array != NULL, NULL);
199
200 rarray = (GRealArray *) array;
201 segment = (gpointer) rarray->data;
202
203 if (len != NULL)
204 *len = rarray->len;
205
206 rarray->data = NULL;
207 rarray->len = 0;
208 rarray->alloc = 0;
209 return segment;
210}
211
223 static inline gpointer *
224g_ptr_array_steal (GPtrArray *array,
225 gsize *len)
226{
227 GRealPtrArray *rarray;
228 gpointer *segment;
229
230 g_return_val_if_fail (array != NULL, NULL);
231
232 rarray = (GRealPtrArray *) array;
233 segment = (gpointer *) rarray->pdata;
234
235 if (len != NULL)
236 *len = rarray->len;
237
238 rarray->pdata = NULL;
239 rarray->len = 0;
240 rarray->alloc = 0;
241 return segment;
242}
243
254 static inline guint8 *g_byte_array_steal (GByteArray *array,
255 gsize *len)
256{
257 return (guint8 *) g_array_steal ((GArray *) array, len);
258}
259#endif
260
261#if !GLIB_CHECK_VERSION(2, 68, 0)
262
273 static inline void *
274g_memdup2(const void *mem, size_t byte_size)
275{
276 void * new_mem;
277
278 if (mem && byte_size != 0) {
279 new_mem = g_malloc(byte_size);
280 memcpy(new_mem, mem, byte_size);
281 }
282 else
283 new_mem = NULL;
284
285 return new_mem;
286}
287#endif
288
289#if !GLIB_CHECK_VERSION(2, 74, 0)
290#ifndef G_REGEX_DEFAULT
291#define G_REGEX_DEFAULT ((GRegexCompileFlags)0)
292#endif
293#endif
294
295#if !GLIB_CHECK_VERSION(2, 74, 0)
296#ifndef G_REGEX_MATCH_DEFAULT
297#define G_REGEX_MATCH_DEFAULT ((GRegexMatchFlags)0)
298#endif
299#endif
300
301#if !GLIB_CHECK_VERSION(2, 88, 0)
302#ifndef G_NSEC_PER_SEC
303#define G_NSEC_PER_SEC 1000000000
304#endif
305#endif
306
307#ifdef __cplusplus
308}
309#endif /* __cplusplus */
310
311#endif /* GLIB_COMPAT_H */
_GRealArray
Internal implementation of GArray, holding the backing buffer and allocation metadata.
Definition glib-compat.h:95
_GRealArray::len
guint len
Definition glib-compat.h:97
_GRealArray::elt_size
guint elt_size
Definition glib-compat.h:99
_GRealArray::clear_func
GDestroyNotify clear_func
Definition glib-compat.h:103
_GRealArray::alloc
guint alloc
Definition glib-compat.h:98
_GRealArray::zero_terminated
guint zero_terminated
Definition glib-compat.h:100
_GRealArray::ref_count
gatomicrefcount ref_count
Definition glib-compat.h:102
_GRealArray::data
guint8 * data
Definition glib-compat.h:96
_GRealArray::clear
guint clear
Definition glib-compat.h:101
_GRealPtrArray
Internal implementation of GPtrArray, holding the backing pointer buffer and allocation metadata.
Definition glib-compat.h:171
_GRealPtrArray::len
guint len
Definition glib-compat.h:173
_GRealPtrArray::element_free_func
GDestroyNotify element_free_func
Definition glib-compat.h:177
_GRealPtrArray::alloc
guint alloc
Definition glib-compat.h:174
_GRealPtrArray::ref_count
gatomicrefcount ref_count
Definition glib-compat.h:175
_GRealPtrArray::pdata
gpointer * pdata
Definition glib-compat.h:172
_GRealPtrArray::null_terminated
guint8 null_terminated
Definition glib-compat.h:176
segment
Represents a single decoded TCP segment extracted from a captured frame for graph analysis.
Definition tap-tcp-stream.h:56
compare_func
int(* compare_func)(const void *a, const void *b)
Function pointer type for comparing two values.
Definition wmem_tree-int.h:106