[gnome-builder] clang: use autoptr for diagnostic
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] clang: use autoptr for diagnostic
- Date: Sat, 13 Jan 2018 12:40:54 +0000 (UTC)
commit a201d9bcd42acc1331d6658f9ac5f022bc01cd62
Author: Christian Hergert <chergert redhat com>
Date: Sat Jan 13 04:33:37 2018 -0800
clang: use autoptr for diagnostic
src/plugins/clang/ide-clang-private.h | 2 ++
src/plugins/clang/ide-clang-service.c | 7 +++++++
src/plugins/clang/ide-clang-translation-unit.c | 12 ++++--------
3 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/src/plugins/clang/ide-clang-private.h b/src/plugins/clang/ide-clang-private.h
index 319c84773..52e38f3b7 100644
--- a/src/plugins/clang/ide-clang-private.h
+++ b/src/plugins/clang/ide-clang-private.h
@@ -32,6 +32,7 @@ IdeClangTranslationUnit *_ide_clang_translation_unit_new (IdeContext
GFile *file,
IdeHighlightIndex *index,
gint64 serial);
+void _ide_clang_dispose_diagnostic (CXDiagnostic *diag);
void _ide_clang_dispose_string (CXString *str);
IdeSymbolNode *_ide_clang_symbol_node_new (IdeContext *context,
CXCursor cursor);
@@ -41,5 +42,6 @@ void _ide_clang_symbol_node_set_children (IdeClangSymbolNode
GArray *children);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (CXString, _ide_clang_dispose_string)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (CXDiagnostic, _ide_clang_dispose_diagnostic)
G_END_DECLS
diff --git a/src/plugins/clang/ide-clang-service.c b/src/plugins/clang/ide-clang-service.c
index ea1bbfbc6..9f03b93c5 100644
--- a/src/plugins/clang/ide-clang-service.c
+++ b/src/plugins/clang/ide-clang-service.c
@@ -822,3 +822,10 @@ _ide_clang_dispose_string (CXString *str)
if (str != NULL && str->data != NULL)
clang_disposeString (*str);
}
+
+void
+_ide_clang_dispose_diagnostic (CXDiagnostic *diag)
+{
+ if (diag != NULL)
+ clang_disposeDiagnostic (diag);
+}
diff --git a/src/plugins/clang/ide-clang-translation-unit.c b/src/plugins/clang/ide-clang-translation-unit.c
index 2b44c09b6..2c9772919 100644
--- a/src/plugins/clang/ide-clang-translation-unit.c
+++ b/src/plugins/clang/ide-clang-translation-unit.c
@@ -387,17 +387,15 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
count = clang_getNumDiagnostics (tu);
for (guint i = 0; i < count; i++)
{
- CXDiagnostic cxdiag;
- IdeDiagnostic *diag;
+ g_autoptr(CXDiagnostic) cxdiag = NULL;
+ g_autoptr(IdeDiagnostic) diag = NULL;
cxdiag = clang_getDiagnostic (tu, i);
diag = create_diagnostic (self, workpath, file, cxdiag);
if (diag != NULL)
{
- guint num_fixits;
-
- num_fixits = clang_getDiagnosticNumFixIts (cxdiag);
+ guint num_fixits = clang_getDiagnosticNumFixIts (cxdiag);
for (guint j = 0; j < num_fixits; j++)
{
@@ -414,10 +412,8 @@ ide_clang_translation_unit_get_diagnostics_for_file (IdeClangTranslationUnit *se
ide_diagnostic_take_fixit (diag, g_steal_pointer (&fixit));
}
- g_ptr_array_add (diags, diag);
+ g_ptr_array_add (diags, g_steal_pointer (&diag));
}
-
- clang_disposeDiagnostic (cxdiag);
}
g_hash_table_insert (self->diagnostics,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]