aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/glib-compat.c
diff options
context:
space:
mode:
authorAndersBroman <anders.broman@ericsson.com>2017-11-23 10:51:53 +0100
committerAnders Broman <a.broman58@gmail.com>2017-11-23 11:41:37 +0000
commitdb811a699d3238425a22f6b8b129c259e97262cf (patch)
tree02303b2b0b1b21337a4429cfcd8f5afdc5799e36 /wsutil/glib-compat.c
parentfe76be0b5bcbb465d4b510135922ea3302c8c705 (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/glib-compat.c')
-rw-r--r--wsutil/glib-compat.c35
1 files changed, 34 insertions, 1 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
*