From: Michael Jeanson Date: Fri, 14 Jul 2017 18:50:31 +0000 (-0400) Subject: Fix: remove g_ptr_array_insert to keep glib 2.22 compat X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=8bf7105ec22b5152f015ef8a3c4d619c5ff43edc;p=deliverable%2Fbabeltrace.git Fix: remove g_ptr_array_insert to keep glib 2.22 compat closes #1120 Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 6f5517c07..413198a79 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;