diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:26 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:26 +0000 |
commit | c4e8a3222648fcf22ca207f1815ebbf7cd144eeb (patch) | |
tree | 93d5c6aa93d9987680dd1adad5685e2ad698f223 /wsutil/glib-compat.h | |
parent | Adding upstream version 4.2.6. (diff) | |
download | wireshark-upstream.tar.xz wireshark-upstream.zip |
Adding upstream version 4.4.0.upstream/4.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wsutil/glib-compat.h')
-rw-r--r-- | wsutil/glib-compat.h | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h index 08c87009..ed7511cf 100644 --- a/wsutil/glib-compat.h +++ b/wsutil/glib-compat.h @@ -22,9 +22,71 @@ extern "C" { #endif /* __cplusplus */ +#if !GLIB_CHECK_VERSION(2, 61, 2) + +typedef volatile gint gatomicrefcount; + +typedef struct _GRealArray GRealArray; +struct _GRealArray +{ + guint8 *data; + guint len; + guint alloc; + guint elt_size; + guint zero_terminated ; + guint clear; + gatomicrefcount ref_count; + GDestroyNotify clear_func; +}; + +static inline gboolean +g_array_binary_search (GArray *array, + const void * target, + GCompareFunc compare_func, + guint *out_match_index) +{ + gboolean result = FALSE; + GRealArray *_array = (GRealArray *) array; + guint left, middle, right; + gint val; + + g_return_val_if_fail (_array != NULL, FALSE); + g_return_val_if_fail (compare_func != NULL, FALSE); + + if (G_LIKELY(_array->len)) + { + left = 0; + right = _array->len - 1; + + while (left <= right) + { + middle = left + (right - left) / 2; + + val = compare_func (_array->data + (_array->elt_size * middle), target); + if (val == 0) + { + result = TRUE; + break; + } + else if (val < 0) + left = middle + 1; + else if (/* val > 0 && */ middle > 0) + right = middle - 1; + else + break; /* element not found */ + } + } + + if (result && out_match_index != NULL) + *out_match_index = middle; + + return result; +} +#endif + #if !GLIB_CHECK_VERSION(2, 68, 0) static inline void * -g_memdup2(gconstpointer mem, size_t byte_size) +g_memdup2(const void *mem, size_t byte_size) { void * new_mem; |