[gnome-builder] clang: be explicit about ownership transfer



commit 12c06c22e88ad6d8a23eadd62940311e2b445ff2
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 3 01:58:52 2018 -0800

    clang: be explicit about ownership transfer

 src/libide/diagnostics/ide-fixit.h             |    2 ++
 src/plugins/clang/ide-clang-translation-unit.c |   14 ++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/diagnostics/ide-fixit.h b/src/libide/diagnostics/ide-fixit.h
index 8ef5fba..90fdaf0 100644
--- a/src/libide/diagnostics/ide-fixit.h
+++ b/src/libide/diagnostics/ide-fixit.h
@@ -33,4 +33,6 @@ void            ide_fixit_apply     (IdeFixit       *self);
 const gchar    *ide_fixit_get_text  (IdeFixit       *self);
 IdeSourceRange *ide_fixit_get_range (IdeFixit       *self);
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeFixit, ide_fixit_unref)
+
 G_END_DECLS
diff --git a/src/plugins/clang/ide-clang-translation-unit.c b/src/plugins/clang/ide-clang-translation-unit.c
index 5251b99..c447e25 100644
--- a/src/plugins/clang/ide-clang-translation-unit.c
+++ b/src/plugins/clang/ide-clang-translation-unit.c
@@ -392,12 +392,12 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
   if (!g_hash_table_contains (self->diagnostics, file))
     {
       CXTranslationUnit tu = ide_ref_ptr_get (self->native);
+      g_autofree gchar *workpath = NULL;
+      g_autoptr(GPtrArray) diags = NULL;
       IdeContext *context;
       IdeProject *project;
-      IdeVcs *vcs;
-      g_autofree gchar *workpath = NULL;
       GFile *workdir;
-      GPtrArray *diags;
+      IdeVcs *vcs;
       guint count;
 
       diags = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref);
@@ -434,8 +434,8 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
 
               for (guint j = 0; j < num_fixits; j++)
                 {
-                  IdeFixit *fixit = NULL;
                   IdeSourceRange *range;
+                  g_autoptr(IdeFixit) fixit = NULL;
                   CXSourceRange cxrange;
                   CXString cxstr;
 
@@ -445,7 +445,7 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
                   clang_disposeString (cxstr);
 
                   if (fixit != NULL)
-                    ide_diagnostic_take_fixit (diag, fixit);
+                    ide_diagnostic_take_fixit (diag, g_steal_pointer (&fixit));
                 }
 
               g_ptr_array_add (diags, diag);
@@ -456,7 +456,9 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
 
       ide_project_reader_unlock (project);
 
-      g_hash_table_insert (self->diagnostics, g_object_ref (file), ide_diagnostics_new (diags));
+      g_hash_table_insert (self->diagnostics,
+                           g_object_ref (file),
+                           ide_diagnostics_new (g_steal_pointer (&diags)));
     }
 
   return g_hash_table_lookup (self->diagnostics, file);


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