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