+/**
+ * g_array_remove_range:
+ * @array: a @GArray
+ * @index_: the index of the first element to remove
+ * @length: the number of elements to remove
+ *
+ * Removes the given number of elements starting at the given index
+ * from a #GArray. The following elements are moved to close the gap.
+ *
+ * Returns: the #GArray
+ *
+ * Since: 2.4
+ */
+GArray*
+g_array_remove_range (GArray *farray,
+ guint index_,
+ guint length)
+{
+ GRealArray *array = (GRealArray*) farray;
+
+ g_return_val_if_fail (array, NULL);
+ g_return_val_if_fail (index_ < array->len, NULL);
+ g_return_val_if_fail (index_ + length <= array->len, NULL);
+
+ if (array->clear_func != NULL)
+ {
+ guint i;
+
+ for (i = 0; i < length; i++)
+ array->clear_func (g_array_elt_pos (array, index_ + i));
+ }
+
+ if (index_ + length != array->len)
+ memmove (g_array_elt_pos (array, index_),
+ g_array_elt_pos (array, index_ + length),
+ (array->len - (index_ + length)) * array->elt_size);
+
+ array->len -= length;
+ if (G_UNLIKELY (g_mem_gc_friendly))
+ g_array_elt_zero (array, array->len, length);
+ else
+ g_array_zero_terminate (array);
+
+ return farray;
+}
+
+/**
+ * g_array_sort:
+ * @array: a #GArray
+ * @compare_func: comparison function
+ *
+ * Sorts a #GArray using @compare_func which should be a qsort()-style
+ * comparison function (returns less than zero for first arg is less
+ * than second arg, zero for equal, greater zero if first arg is
+ * greater than second arg).
+ *
+ * This is guaranteed to be a stable sort since version 2.32.
+ */
+void
+g_array_sort (GArray *farray,
+ GCompareFunc compare_func)
+{
+ GRealArray *array = (GRealArray*) farray;
+
+ g_return_if_fail (array != NULL);
+
+ /* Don't use qsort as we want a guaranteed stable sort */
+ g_qsort_with_data (array->data,
+ array->len,
+ array->elt_size,
+ (GCompareDataFunc)compare_func,
+ NULL);
+}
+
+/**
+ * g_array_sort_with_data:
+ * @array: a #GArray
+ * @compare_func: comparison function
+ * @user_data: data to pass to @compare_func
+ *
+ * Like g_array_sort(), but the comparison function receives an extra
+ * user data argument.
+ *
+ * This is guaranteed to be a stable sort since version 2.32.
+ *
+ * There used to be a comment here about making the sort stable by
+ * using the addresses of the elements in the comparison function.
+ * This did not actually work, so any such code should be removed.
+ */
+void
+g_array_sort_with_data (GArray *farray,
+ GCompareDataFunc compare_func,
+ gpointer user_data)
+{
+ GRealArray *array = (GRealArray*) farray;
+
+ g_return_if_fail (array != NULL);
+
+ g_qsort_with_data (array->data,
+ array->len,
+ array->elt_size,
+ compare_func,
+ user_data);
+}
+
+/* Returns the smallest power of 2 greater than n, or n if
+ * such power does not fit in a guint
+ */
+static guint