From 2b5f969e99dcfdd1f05035e136c8cf2fa8d5b109 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 14 Jul 2017 14:50:31 -0400 Subject: [PATCH] Fix: remove g_ptr_array_insert to keep glib 2.22 compat MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit closes #1120 Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs-src/fs.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 6f5517c0..413198a7 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -602,6 +602,26 @@ end: return ds_file_group; } +/* Replace by g_ptr_array_insert when we depend on glib >= 2.40. */ +static +void array_insert(GPtrArray *array, gpointer element, size_t pos) +{ + size_t original_array_len = array->len; + + /* Allocate an unused element at the end of the array. */ + g_ptr_array_add(array, NULL); + + /* If we are not inserting at the end, move the elements by one. */ + if (pos < original_array_len) { + memmove(&(array->pdata[pos + 1]), + &(array->pdata[pos]), + (original_array_len - pos) * sizeof(gpointer)); + } + + /* Insert the value and bump the array len */ + array->pdata[pos] = element; +} + static int ctf_fs_ds_file_group_add_ds_file_info( struct ctf_fs_ds_file_group *ds_file_group, @@ -629,12 +649,7 @@ int ctf_fs_ds_file_group_add_ds_file_info( } } - if (i == ds_file_group->ds_file_infos->len) { - /* Append instead */ - i = -1; - } - - g_ptr_array_insert(ds_file_group->ds_file_infos, i, ds_file_info); + array_insert(ds_file_group->ds_file_infos, ds_file_info, i); ds_file_info = NULL; goto end; -- 2.34.1