[gnome-builder] code-indexer: use const gchar * const * instead of gchar **
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] code-indexer: use const gchar * const * instead of gchar **
- Date: Sat, 11 Nov 2017 01:38:13 +0000 (UTC)
commit b0f62cf7a7241743b4f73921686a130208472a55
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 10 17:30:48 2017 -0800
code-indexer: use const gchar * const * instead of gchar **
We always want our string arrays to be const gchar * const * to make it
obvious the array is const and the array elements are const. It also
reduces the chances we accidentally mistake it for an our parameter like
I just did.
src/libide/symbols/ide-code-indexer.c | 20 ++++++++++----------
src/libide/symbols/ide-code-indexer.h | 4 ++--
src/plugins/clang/ide-clang-code-indexer.c | 15 +++++++--------
src/plugins/code-index/ide-code-index-builder.c | 5 ++++-
4 files changed, 23 insertions(+), 21 deletions(-)
---
diff --git a/src/libide/symbols/ide-code-indexer.c b/src/libide/symbols/ide-code-indexer.c
index 333749b..fc11e42 100644
--- a/src/libide/symbols/ide-code-indexer.c
+++ b/src/libide/symbols/ide-code-indexer.c
@@ -23,11 +23,11 @@
G_DEFINE_INTERFACE (IdeCodeIndexer, ide_code_indexer, IDE_TYPE_OBJECT)
static IdeCodeIndexEntries *
-ide_code_indexer_real_index_file (IdeCodeIndexer *self,
- GFile *file,
- gchar **build_flags,
- GCancellable *cancellable,
- GError **error)
+ide_code_indexer_real_index_file (IdeCodeIndexer *self,
+ GFile *file,
+ const gchar * const *build_flags,
+ GCancellable *cancellable,
+ GError **error)
{
g_set_error (error,
G_IO_ERROR,
@@ -89,11 +89,11 @@ ide_code_indexer_default_init (IdeCodeIndexerInterface *iface)
* Since: 3.26
*/
IdeCodeIndexEntries *
-ide_code_indexer_index_file (IdeCodeIndexer *self,
- GFile *file,
- gchar **build_flags,
- GCancellable *cancellable,
- GError **error)
+ide_code_indexer_index_file (IdeCodeIndexer *self,
+ GFile *file,
+ const gchar * const *build_flags,
+ GCancellable *cancellable,
+ GError **error)
{
IdeCodeIndexerInterface *iface;
diff --git a/src/libide/symbols/ide-code-indexer.h b/src/libide/symbols/ide-code-indexer.h
index 880ff67..0fe4b4e 100644
--- a/src/libide/symbols/ide-code-indexer.h
+++ b/src/libide/symbols/ide-code-indexer.h
@@ -35,7 +35,7 @@ struct _IdeCodeIndexerInterface
IdeCodeIndexEntries *(*index_file) (IdeCodeIndexer *self,
GFile *file,
- gchar **build_flags,
+ const gchar * const *build_flags,
GCancellable *cancellable,
GError **error);
void (*generate_key_async) (IdeCodeIndexer *self,
@@ -51,7 +51,7 @@ struct _IdeCodeIndexerInterface
IDE_AVAILABLE_IN_ALL
IdeCodeIndexEntries *ide_code_indexer_index_file (IdeCodeIndexer *self,
GFile *file,
- gchar **build_flags,
+ const gchar * const *build_flags,
GCancellable *cancellable,
GError **error);
IDE_AVAILABLE_IN_ALL
diff --git a/src/plugins/clang/ide-clang-code-indexer.c b/src/plugins/clang/ide-clang-code-indexer.c
index dec813a..0446115 100644
--- a/src/plugins/clang/ide-clang-code-indexer.c
+++ b/src/plugins/clang/ide-clang-code-indexer.c
@@ -76,11 +76,11 @@ ide_clang_code_indexer_get_default_build_flags (IdeClangCodeIndexer *self)
/* This will return a IdeCodeIndexEntries backed by translation unit of file. */
static IdeCodeIndexEntries *
-ide_clang_code_indexer_index_file (IdeCodeIndexer *indexer,
- GFile *file,
- gchar **args,
- GCancellable *cancellable,
- GError **error)
+ide_clang_code_indexer_index_file (IdeCodeIndexer *indexer,
+ GFile *file,
+ const gchar * const *args,
+ GCancellable *cancellable,
+ GError **error)
{
IdeClangCodeIndexer *self = (IdeClangCodeIndexer *)indexer;
g_autoptr(GTask) task = NULL;
@@ -102,8 +102,7 @@ ide_clang_code_indexer_index_file (IdeCodeIndexer *indexer,
{
if (self->build_flags == NULL)
self->build_flags = ide_clang_code_indexer_get_default_build_flags (self);
-
- args = self->build_flags;
+ args = (const gchar * const *)self->build_flags;
}
while (args [n_args] != NULL)
@@ -111,7 +110,7 @@ ide_clang_code_indexer_index_file (IdeCodeIndexer *indexer,
if (CXError_Success == clang_parseTranslationUnit2 (self->index,
filename,
- (const char * const *)args,
+ args,
n_args,
NULL,
0,
diff --git a/src/plugins/code-index/ide-code-index-builder.c b/src/plugins/code-index/ide-code-index-builder.c
index 8d381f8..e11568f 100644
--- a/src/plugins/code-index/ide-code-index-builder.c
+++ b/src/plugins/code-index/ide-code-index-builder.c
@@ -85,12 +85,15 @@ timeval_compare (GTimeVal a,
return ((a.tv_sec > b.tv_sec) || ((a.tv_sec == b.tv_sec) && (a.tv_usec > b.tv_usec)));
}
-static gchar **
+static const gchar * const *
ide_code_index_builder_get_build_flags (IdeCodeIndexBuilder *self,
GFile *file)
{
g_autoptr(IdeFile) ide_file = NULL;
+ g_assert (IDE_IS_CODE_INDEX_BUILDER (self));
+ g_assert (G_IS_FILE (file));
+
ide_file = ide_file_new (ide_object_get_context (IDE_OBJECT (self)), file);
return g_hash_table_lookup (self->build_flags, ide_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]