Fix: remove g_ptr_array_insert to keep glib 2.22 compat
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 14 Jul 2017 18:50:31 +0000 (14:50 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 18 Jul 2017 18:51:08 +0000 (14:51 -0400)
closes #1120

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/fs-src/fs.c

index 6f5517c07a168d3309cb0a8d548b51be8ae1b6fa..413198a79c659d25f6327373b66df20a15911b29 100644 (file)
@@ -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;
 
This page took 0.025311 seconds and 5 git commands to generate.