[gnome-builder] unsaved-files: make ide_unsaved_files_to_array transfer full



commit 524485ab5e2d377fa7bc3ae2400477db6d188420
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 9 15:30:25 2018 -0700

    unsaved-files: make ide_unsaved_files_to_array transfer full
    
    This makes things easier on language bindings.

 src/libide/buffers/ide-unsaved-files.c         | 10 +++++++---
 src/libide/buffers/ide-unsaved-files.h         |  2 +-
 src/libide/ide-context.c                       |  1 +
 src/plugins/clang/ide-clang-service.c          |  6 +++++-
 src/plugins/clang/ide-clang-translation-unit.c |  5 ++++-
 5 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/buffers/ide-unsaved-files.c b/src/libide/buffers/ide-unsaved-files.c
index 32c3baace..ac43f1938 100644
--- a/src/libide/buffers/ide-unsaved-files.c
+++ b/src/libide/buffers/ide-unsaved-files.c
@@ -35,8 +35,9 @@
 #include "buffers/ide-unsaved-file.h"
 #include "buffers/ide-unsaved-files.h"
 #include "projects/ide-project.h"
-#include "util/ide-line-reader.h"
 #include "threading/ide-task.h"
+#include "util/ide-glib.h"
+#include "util/ide-line-reader.h"
 
 typedef struct
 {
@@ -685,6 +686,7 @@ ide_unsaved_files_update (IdeUnsavedFiles *self,
 
 /**
  * ide_unsaved_files_to_array:
+ * @self: an #IdeUnsavedFiles
  *
  * This retrieves all of the unsaved file buffers known to the context.
  * These are handy if you need to pass modified state to parsers such as
@@ -695,7 +697,7 @@ ide_unsaved_files_update (IdeUnsavedFiles *self,
  * If you would like to hold onto an unsaved file instance, call
  * ide_unsaved_file_ref() to increment its reference count.
  *
- * Returns: (transfer container) (element-type Ide.UnsavedFile): a #GPtrArray
+ * Returns: (transfer full) (element-type Ide.UnsavedFile): a #GPtrArray
  *   containing #IdeUnsavedFile elements.
  */
 GPtrArray *
@@ -724,7 +726,7 @@ ide_unsaved_files_to_array (IdeUnsavedFiles *self)
 
   g_mutex_unlock (&self->mutex);
 
-  return g_steal_pointer (&ar);
+  return IDE_PTR_ARRAY_STEAL_FULL (&ar);
 }
 
 gboolean
@@ -853,6 +855,8 @@ ide_unsaved_files_clear (IdeUnsavedFiles *self)
 
   ar = ide_unsaved_files_to_array (self);
 
+  IDE_PTR_ARRAY_SET_FREE_FUNC (ar, ide_unsaved_file_unref);
+
   g_mutex_lock (&self->mutex);
 
   for (guint i = 0; i < ar->len; i++)
diff --git a/src/libide/buffers/ide-unsaved-files.h b/src/libide/buffers/ide-unsaved-files.h
index a8cde2194..d745f69fb 100644
--- a/src/libide/buffers/ide-unsaved-files.h
+++ b/src/libide/buffers/ide-unsaved-files.h
@@ -55,7 +55,7 @@ gboolean        ide_unsaved_files_restore_finish    (IdeUnsavedFiles      *files
                                                      GAsyncResult         *result,
                                                      GError              **error);
 IDE_AVAILABLE_IN_ALL
-GPtrArray      *ide_unsaved_files_to_array          (IdeUnsavedFiles      *files);
+GPtrArray      *ide_unsaved_files_to_array          (IdeUnsavedFiles      *self);
 IDE_AVAILABLE_IN_ALL
 gint64          ide_unsaved_files_get_sequence      (IdeUnsavedFiles      *files);
 IDE_AVAILABLE_IN_ALL
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index cf2d69ae8..b26b151cc 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -2236,6 +2236,7 @@ ide_context_restore_async (IdeContext          *self,
   self->restored = TRUE;
 
   ar = ide_unsaved_files_to_array (self->unsaved_files);
+  IDE_PTR_ARRAY_SET_FREE_FUNC (ar, ide_unsaved_file_unref);
 
   if (ar->len == 0)
     {
diff --git a/src/plugins/clang/ide-clang-service.c b/src/plugins/clang/ide-clang-service.c
index e80ea1c2e..672590cf4 100644
--- a/src/plugins/clang/ide-clang-service.c
+++ b/src/plugins/clang/ide-clang-service.c
@@ -537,6 +537,7 @@ ide_clang_service_get_translation_unit_worker (DzlTaskCache  *cache,
                                                gpointer       user_data)
 {
   g_autoptr(GTask) real_task = NULL;
+  g_autoptr(GPtrArray) files_ar = NULL;
   g_autofree gchar *path = NULL;
   IdeClangService *self = user_data;
   IdeUnsavedFiles *unsaved_files;
@@ -563,12 +564,15 @@ ide_clang_service_get_translation_unit_worker (DzlTaskCache  *cache,
       return;
     }
 
+  files_ar = ide_unsaved_files_to_array (unsaved_files);
+  IDE_PTR_ARRAY_SET_FREE_FUNC (files_ar, ide_unsaved_file_unref);
+
   request = g_slice_new0 (ParseRequest);
   request->file = ide_file_new (context, gfile);
   request->index = self->index;
   request->source_filename = g_steal_pointer (&path);
   request->command_line_args = NULL;
-  request->unsaved_files = ide_unsaved_files_to_array (unsaved_files);
+  request->unsaved_files = g_steal_pointer (&files_ar);
   request->sequence = ide_unsaved_files_get_sequence (unsaved_files);
   /*
    * NOTE:
diff --git a/src/plugins/clang/ide-clang-translation-unit.c b/src/plugins/clang/ide-clang-translation-unit.c
index 715773191..3ccd91c39 100644
--- a/src/plugins/clang/ide-clang-translation-unit.c
+++ b/src/plugins/clang/ide-clang-translation-unit.c
@@ -685,6 +685,7 @@ ide_clang_translation_unit_code_complete_async (IdeClangTranslationUnit *self,
                                                 gpointer                 user_data)
 {
   g_autoptr(IdeTask) task = NULL;
+  g_autoptr(GPtrArray) files_ar = NULL;
   CodeCompleteState *state;
   IdeContext *context;
   IdeUnsavedFiles *unsaved_files;
@@ -698,6 +699,8 @@ ide_clang_translation_unit_code_complete_async (IdeClangTranslationUnit *self,
 
   context = ide_object_get_context (IDE_OBJECT (self));
   unsaved_files = ide_context_get_unsaved_files (context);
+  files_ar = ide_unsaved_files_to_array (unsaved_files);
+  IDE_PTR_ARRAY_SET_FREE_FUNC (files_ar, ide_unsaved_file_unref);
 
   task = ide_task_new (self, cancellable, callback, user_data);
 
@@ -705,7 +708,7 @@ ide_clang_translation_unit_code_complete_async (IdeClangTranslationUnit *self,
   state->path = g_file_get_path (file);
   state->line = gtk_text_iter_get_line (location);
   state->line_offset = gtk_text_iter_get_line_offset (location);
-  state->unsaved_files = ide_unsaved_files_to_array (unsaved_files);
+  state->unsaved_files = g_steal_pointer (&files_ar);
 
   /*
    * TODO: Technically it is not safe for us to go run this in a thread. We need to ensure


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