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
22extern "C" {
23#endif /* __cplusplus */
24
25#if !GLIB_CHECK_VERSION(2, 57, 1)
26
27static inline gboolean
28g_hash_table_steal_extended (GHashTable *hash_table,
29 gconstpointer lookup_key,
30 gpointer *stolen_key,
31 gpointer *stolen_value)
32{
33 gpointer key, value;
34 if (g_hash_table_lookup_extended (hash_table, lookup_key, &key, &value))
35 {
36 stolen_key = &key;
37 stolen_value = &value;
38
39 g_hash_table_steal (hash_table, key);
40
41 return TRUE;
42 } else {
43 if (stolen_key != NULL)
44 *stolen_key = NULL;
45 if (stolen_value != NULL)
46 *stolen_value = NULL;
47 }
48
49 return FALSE;
50}
51
52#endif
53
54#if !GLIB_CHECK_VERSION(2, 60, 0)
55
56#define g_queue_clear_full queue_clear_full
57static inline void
58queue_clear_full (GQueue * queue, GDestroyNotify free_func)
59{
60 gpointer data;
61
62 while ((data = g_queue_pop_head (queue)) != NULL)
63 free_func (data);
64}
65
66#endif
67
68#if !GLIB_CHECK_VERSION(2, 61, 2)
69
70typedef volatile gint gatomicrefcount;
71
72typedef struct _GRealArray GRealArray;
74{
75 guint8 *data;
76 guint len;
77 guint alloc;
78 guint elt_size;
79 guint zero_terminated ;
80 guint clear;
81 gatomicrefcount ref_count;
82 GDestroyNotify clear_func;
83};
84
85static inline gboolean
86g_array_binary_search (GArray *array,
87 const void * target,
88 GCompareFunc compare_func,
89 guint *out_match_index)
90{
91 gboolean result = FALSE;
92 GRealArray *_array = (GRealArray *) array;
93 guint left, middle, right;
94 gint val;
95
96 g_return_val_if_fail (_array != NULL, FALSE);
97 g_return_val_if_fail (compare_func != NULL, FALSE);
98
99 if (G_LIKELY(_array->len))
100 {
101 left = 0;
102 right = _array->len - 1;
103
104 while (left <= right)
105 {
106 middle = left + (right - left) / 2;
107
108 val = compare_func (_array->data + (_array->elt_size * middle), target);
109 if (val == 0)
110 {
111 result = TRUE;
112 break;
113 }
114 else if (val < 0)
115 left = middle + 1;
116 else if (/* val > 0 && */ middle > 0)
117 right = middle - 1;
118 else
119 break; /* element not found */
120 }
121 }
122
123 if (result && out_match_index != NULL)
124 *out_match_index = middle;
125
126 return result;
127}
128#endif
129
130#if !GLIB_CHECK_VERSION(2, 64, 0)
131typedef struct _GRealPtrArray GRealPtrArray;
132
134{
135 gpointer *pdata;
136 guint len;
137 guint alloc;
138 gatomicrefcount ref_count;
139 guint8 null_terminated : 1; /* always either 0 or 1, so it can be added to array lengths */
140 GDestroyNotify element_free_func;
141};
142
143static inline gpointer
144g_array_steal (GArray *array,
145 gsize *len)
146{
147 GRealArray *rarray;
148 gpointer segment;
149
150 g_return_val_if_fail (array != NULL, NULL);
151
152 rarray = (GRealArray *) array;
153 segment = (gpointer) rarray->data;
154
155 if (len != NULL)
156 *len = rarray->len;
157
158 rarray->data = NULL;
159 rarray->len = 0;
160 rarray->alloc = 0;
161 return segment;
162}
163
164static inline gpointer *
165g_ptr_array_steal (GPtrArray *array,
166 gsize *len)
167{
168 GRealPtrArray *rarray;
169 gpointer *segment;
170
171 g_return_val_if_fail (array != NULL, NULL);
172
173 rarray = (GRealPtrArray *) array;
174 segment = (gpointer *) rarray->pdata;
175
176 if (len != NULL)
177 *len = rarray->len;
178
179 rarray->pdata = NULL;
180 rarray->len = 0;
181 rarray->alloc = 0;
182 return segment;
183}
184
185static inline guint8 *
186g_byte_array_steal (GByteArray *array,
187 gsize *len)
188{
189 return (guint8 *) g_array_steal ((GArray *) array, len);
190}
191#endif
192
193#if !GLIB_CHECK_VERSION(2, 68, 0)
194static inline void *
195g_memdup2(const void *mem, size_t byte_size)
196{
197 void * new_mem;
198
199 if (mem && byte_size != 0) {
200 new_mem = g_malloc(byte_size);
201 memcpy(new_mem, mem, byte_size);
202 }
203 else
204 new_mem = NULL;
205
206 return new_mem;
207}
208#endif
209
210#if !GLIB_CHECK_VERSION(2, 74, 0)
211#ifndef G_REGEX_DEFAULT
212#define G_REGEX_DEFAULT ((GRegexCompileFlags)0)
213#endif
214#endif
215
216#if !GLIB_CHECK_VERSION(2, 74, 0)
217#ifndef G_REGEX_MATCH_DEFAULT
218#define G_REGEX_MATCH_DEFAULT ((GRegexMatchFlags)0)
219#endif
220#endif
221
222#ifdef __cplusplus
223}
224#endif /* __cplusplus */
225
226#endif /* GLIB_COMPAT_H */
Definition glib-compat.h:74
Definition glib-compat.h:134
Definition tap-tcp-stream.h:43
int(* compare_func)(const void *a, const void *b)
Function pointer type for comparing two values.
Definition wmem_tree-int.h:106