diff options
author | AndersBroman <anders.broman@ericsson.com> | 2017-11-23 10:51:53 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-11-23 11:41:37 +0000 |
commit | db811a699d3238425a22f6b8b129c259e97262cf (patch) | |
tree | 02303b2b0b1b21337a4429cfcd8f5afdc5799e36 /wsutil | |
parent | fe76be0b5bcbb465d4b510135922ea3302c8c705 (diff) |
[glib-compat] Add g_ptr_array_new_full().
Change-Id: Ic0e054cbb28106cc02f229ad4f2476b39e544378
Reviewed-on: https://code.wireshark.org/review/24544
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/glib-compat.c | 35 | ||||
-rw-r--r-- | wsutil/glib-compat.h | 6 |
2 files changed, 39 insertions, 2 deletions
diff --git a/wsutil/glib-compat.c b/wsutil/glib-compat.c index 8acc520b49..4691a5576f 100644 --- a/wsutil/glib-compat.c +++ b/wsutil/glib-compat.c @@ -76,7 +76,40 @@ gint64 g_get_monotonic_time (void) return result.tv_sec*1000000 + result.tv_usec; } -#endif +#endif /* GLIB_CHECK_VERSION(2, 28, 0)*/ + +#if !GLIB_CHECK_VERSION(2, 30, 0) +/** +* g_ptr_array_new_full: +* @reserved_size: number of pointers preallocated +* @element_free_func: (allow-none): A function to free elements with +* destroy @array or %NULL +* +* Creates a new #GPtrArray with @reserved_size pointers preallocated +* and a reference count of 1. This avoids frequent reallocation, if +* you are going to add many pointers to the array. Note however that +* the size of the array is still 0. It also set @element_free_func +* for freeing each element when the array is destroyed either via +* g_ptr_array_unref(), when g_ptr_array_free() is called with +* @free_segment set to %TRUE or when removing elements. +* +* Returns: A new #GPtrArray +* +* Since: 2.30 +*/ +GPtrArray* +g_ptr_array_new_full(guint reserved_size, + GDestroyNotify element_free_func) +{ + GPtrArray *array; + + array = g_ptr_array_sized_new(reserved_size); + g_ptr_array_set_free_func(array, element_free_func); + + return array; +} +#endif /* GLIB_CHECK_VERSION(2, 30, 0)*/ + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h index adaa630f8e..54632e8ab3 100644 --- a/wsutil/glib-compat.h +++ b/wsutil/glib-compat.h @@ -28,6 +28,10 @@ WS_DLL_PUBLIC void g_slist_free_full(GSList *list, GDestroyNotify free_func); WS_DLL_PUBLIC void g_list_free_full(GList *list, GDestroyNotify free_func); WS_DLL_PUBLIC gint64 g_get_monotonic_time (void); -#endif +#endif /* !GLIB_CHECK_VERSION(2, 28, 0) */ + +#if !GLIB_CHECK_VERSION(2, 30, 0) +WS_DLL_PUBLIC GPtrArray* g_ptr_array_new_full(guint reserved_size, GDestroyNotify element_free_func); +#endif /* !GLIB_CHECK_VERSION(2, 30, 0) */ #endif /* GLIB_COMPAT_H */ |