[gnome-builder] diagnostics: make creation parameter transfer full



commit ea7b5589f3301c282269e4137ff97e1d43856062
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 9 16:02:04 2018 -0700

    diagnostics: make creation parameter transfer full
    
    This makes things easier on language bindings.

 src/libide/diagnostics/ide-diagnostics.c                        | 9 ++++++---
 src/libide/langserv/ide-langserv-client.c                       | 3 ++-
 src/plugins/clang/ide-clang-translation-unit.c                  | 2 +-
 src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c | 9 ++++-----
 src/plugins/xml-pack/ide-xml-parser.c                           | 2 +-
 src/plugins/xml-pack/ide-xml-validator.c                        | 2 +-
 6 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/src/libide/diagnostics/ide-diagnostics.c b/src/libide/diagnostics/ide-diagnostics.c
index 250423519..1c58f4e27 100644
--- a/src/libide/diagnostics/ide-diagnostics.c
+++ b/src/libide/diagnostics/ide-diagnostics.c
@@ -20,10 +20,11 @@
 
 #include "config.h"
 
-#include "dazzle.h"
+#include <dazzle.h>
 
 #include "diagnostics/ide-diagnostic.h"
 #include "diagnostics/ide-diagnostics.h"
+#include "util/ide-glib.h"
 
 G_DEFINE_BOXED_TYPE (IdeDiagnostics, ide_diagnostics, ide_diagnostics_ref, ide_diagnostics_unref)
 
@@ -37,7 +38,7 @@ struct _IdeDiagnostics
 
 /**
  * ide_diagnostics_new:
- * @ar: (transfer container) (element-type Ide.Diagnostic) (allow-none): an array of #IdeDiagnostic.
+ * @ar: (transfer full) (element-type Ide.Diagnostic) (nullable): an array of #IdeDiagnostic.
  *
  * Creates a new #IdeDiagnostics container structure for @ar.
  * Ownership of @ar is transfered to the resulting structure.
@@ -50,7 +51,9 @@ ide_diagnostics_new (GPtrArray *ar)
   IdeDiagnostics *ret;
 
   if (ar == NULL)
-    ar = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref);
+    ar = g_ptr_array_new ();
+
+  IDE_PTR_ARRAY_SET_FREE_FUNC (ar, ide_diagnostic_unref);
 
   ret = g_slice_new0 (IdeDiagnostics);
   ret->ref_count = 1;
diff --git a/src/libide/langserv/ide-langserv-client.c b/src/libide/langserv/ide-langserv-client.c
index 4402bfbbf..d8468f1c5 100644
--- a/src/libide/langserv/ide-langserv-client.c
+++ b/src/libide/langserv/ide-langserv-client.c
@@ -40,6 +40,7 @@
 #include "projects/ide-project.h"
 #include "vcs/ide-vcs.h"
 #include "threading/ide-task.h"
+#include "util/ide-glib.h"
 
 typedef struct
 {
@@ -573,7 +574,7 @@ ide_langserv_client_translate_diagnostics (IdeLangservClient *self,
       g_ptr_array_add (ar, g_steal_pointer (&diag));
     }
 
-  return ide_diagnostics_new (g_steal_pointer (&ar));
+  return ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&ar));
 }
 
 static void
diff --git a/src/plugins/clang/ide-clang-translation-unit.c b/src/plugins/clang/ide-clang-translation-unit.c
index 3ccd91c39..45fb02ca4 100644
--- a/src/plugins/clang/ide-clang-translation-unit.c
+++ b/src/plugins/clang/ide-clang-translation-unit.c
@@ -418,7 +418,7 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
 
       g_hash_table_insert (self->diagnostics,
                            g_object_ref (file),
-                           ide_diagnostics_new (g_steal_pointer (&diags)));
+                           ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&diags)));
     }
 
   return g_hash_table_lookup (self->diagnostics, file);
diff --git a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c 
b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
index 552156e7d..c49e1dde2 100644
--- a/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
+++ b/src/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
@@ -94,7 +94,7 @@ variant_to_diagnostics (DiagnoseState *state,
                         GVariant *variant)
 {
 
-  GPtrArray *ar;
+  g_autoptr(GPtrArray) ar = NULL;
   GVariantIter iter;
   GVariantIter *b;
   GVariantIter *c;
@@ -105,8 +105,7 @@ variant_to_diagnostics (DiagnoseState *state,
 
   g_assert (variant);
 
-  ar = g_ptr_array_new ();
-  g_ptr_array_set_free_func (ar, (GDestroyNotify)ide_diagnostic_unref);
+  ar = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref);
 
   g_variant_iter_init (&iter, variant);
 
@@ -167,10 +166,10 @@ variant_to_diagnostics (DiagnoseState *state,
           ide_source_location_unref (end);
         }
 
-      g_ptr_array_add (ar, diag);
+      g_ptr_array_add (ar, g_steal_pointer (&diag));
     }
 
-  return ide_diagnostics_new (ar);
+  return ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&ar));
 }
 
 static void
diff --git a/src/plugins/xml-pack/ide-xml-parser.c b/src/plugins/xml-pack/ide-xml-parser.c
index 8de919f7a..94280a546 100644
--- a/src/plugins/xml-pack/ide-xml-parser.c
+++ b/src/plugins/xml-pack/ide-xml-parser.c
@@ -583,7 +583,7 @@ ide_xml_parser_get_analysis_worker (IdeTask      *task,
       return;
     }
 
-  diagnostics = ide_diagnostics_new (g_steal_pointer (&state->diagnostics_array));
+  diagnostics = ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&state->diagnostics_array));
   ide_xml_analysis_set_diagnostics (analysis, diagnostics);
 
   if (state->file_is_ui)
diff --git a/src/plugins/xml-pack/ide-xml-validator.c b/src/plugins/xml-pack/ide-xml-validator.c
index 57c4da7b0..a0a19664c 100644
--- a/src/plugins/xml-pack/ide-xml-validator.c
+++ b/src/plugins/xml-pack/ide-xml-validator.c
@@ -201,7 +201,7 @@ ide_xml_validator_validate (IdeXmlValidator   *self,
 
 end:
   if (diagnostics != NULL)
-    *diagnostics = ide_diagnostics_new (self->diagnostics_array);
+    *diagnostics = ide_diagnostics_new (IDE_PTR_ARRAY_STEAL_FULL (&self->diagnostics_array));
   else
     g_clear_pointer (&self->diagnostics_array, g_ptr_array_unref);
 


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