[gnome-builder] core: add steal helper for ptrarray



commit 93fd62768cc6fb874a5c44bc92249d0be8421067
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 6 13:22:16 2019 -0800

    core: add steal helper for ptrarray
    
    This would be nice to have (in a better form) in GLib, but we can work
    around that for now.

 src/libide/core/ide-macros.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/src/libide/core/ide-macros.h b/src/libide/core/ide-macros.h
index b46d1e7d8..2224d12c6 100644
--- a/src/libide/core/ide-macros.h
+++ b/src/libide/core/ide-macros.h
@@ -55,6 +55,24 @@ G_BEGIN_DECLS
   ({ IDE_PTR_ARRAY_CLEAR_FREE_FUNC (*(arptr)); \
      g_steal_pointer ((arptr)); })
 
+static inline gpointer
+ide_ptr_array_steal_index (GPtrArray      *array,
+                           guint           index,
+                           GDestroyNotify  free_func)
+{
+  gpointer ret;
+
+  if (index >= array->len)
+    return NULL;
+
+  g_ptr_array_set_free_func (array, NULL);
+  ret = g_ptr_array_index (array, index);
+  g_ptr_array_remove_index (array, index);
+  g_ptr_array_set_free_func (array, free_func);
+
+  return ret;
+}
+
 static inline gboolean
 ide_error_ignore (const GError *error)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]