[gnome-logs] Pass GPtrArray to gl_journal_set_matches()



commit ce9263e17eba6db4da80b61efe58bc986fd27978
Author: Pranav Ganorkar <pranavg189 gmail com>
Date:   Thu Jul 14 23:16:12 2016 +0530

    Pass GPtrArray to gl_journal_set_matches()
    
    The function argument is changed from const gchar * const *
    to GPtrArray.

 src/gl-journal-model.c |    5 +----
 src/gl-journal.c       |   32 ++++++++++++++++++--------------
 src/gl-journal.h       |    2 +-
 3 files changed, 20 insertions(+), 19 deletions(-)
---
diff --git a/src/gl-journal-model.c b/src/gl-journal-model.c
index a533335..a80e98a 100644
--- a/src/gl-journal-model.c
+++ b/src/gl-journal-model.c
@@ -287,9 +287,6 @@ gl_query_get_exact_matches (GlQuery *query)
 
     g_ptr_array_foreach (query->queryitems, (GFunc) get_exact_match_string, matches);
 
-    /* Add NULL terminator to determine end of pointer array */
-    g_ptr_array_add (matches, NULL);
-
     return matches;
 }
 
@@ -302,7 +299,7 @@ gl_journal_model_process_query (GlJournalModel *model)
     /* Set the exact matches first */
     category_matches = gl_query_get_exact_matches (model->query);
 
-    gl_journal_set_matches (model->journal, (const gchar * const *) category_matches->pdata);
+    gl_journal_set_matches (model->journal, category_matches);
 
     /* Start re-population of the journal */
     gl_journal_model_fetch_more_entries (model, FALSE);
diff --git a/src/gl-journal.c b/src/gl-journal.c
index 93ac93c..cc67542 100644
--- a/src/gl-journal.c
+++ b/src/gl-journal.c
@@ -565,8 +565,8 @@ create_boot_id_match_string (void)
  * beginning.
  */
 void
-gl_journal_set_matches (GlJournal           *journal,
-                        const gchar * const *matches)
+gl_journal_set_matches (GlJournal *journal,
+                        GPtrArray *matches)
 {
     GlJournalPrivate *priv = gl_journal_get_instance_private (journal);
     GPtrArray *mandatory_fields;
@@ -582,25 +582,29 @@ gl_journal_set_matches (GlJournal           *journal,
     sd_journal_flush_matches (priv->journal);
 
     mandatory_fields = g_ptr_array_new ();
-    for (i = 0; matches[i]; i++)
+    for (i = 0; i < matches->len; i++)
     {
         /* matches without a value should only check for existence.
          * systemd doesn't support that, so let's remember them to
          * filter out later.
          */
-        if (strchr (matches[i], '=') == NULL)
+        const gchar *match;
+
+        match = g_ptr_array_index (matches, i);
+
+        if (strchr (match, '=') == NULL)
         {
-            g_ptr_array_add (mandatory_fields, g_strdup (matches[i]));
+            g_ptr_array_add (mandatory_fields, g_strdup (match));
             continue;
         }
 
-        if (g_str_has_prefix (matches[i], "_BOOT_ID="))
+        if (g_str_has_prefix (match, "_BOOT_ID="))
           has_boot_id = TRUE;
 
-        r = sd_journal_add_match (priv->journal, matches[i], 0);
+        r = sd_journal_add_match (priv->journal, match, 0);
         if (r < 0)
         {
-            g_critical ("Failed to add match '%s': %s", matches[i], g_strerror (-r));
+            g_critical ("Failed to add match '%s': %s", match, g_strerror (-r));
             break;
         }
     }
@@ -611,16 +615,16 @@ gl_journal_set_matches (GlJournal           *journal,
     /* take events from this boot only, unless _BOOT_ID was in @matches */
     if (!has_boot_id)
     {
-        gchar *match;
+        gchar *boot_match;
 
-        match = create_boot_id_match_string ();
-        if (match)
+        boot_match = create_boot_id_match_string ();
+        if (boot_match)
         {
-            r = sd_journal_add_match (priv->journal, match, 0);
+            r = sd_journal_add_match (priv->journal, boot_match, 0);
             if (r < 0)
-                g_warning ("Failed to add match '%s': %s", matches[i], g_strerror (-r));
+                g_warning ("Failed to add match '%s': %s", boot_match, g_strerror (-r));
 
-            g_free (match);
+            g_free (boot_match);
         }
     }
 
diff --git a/src/gl-journal.h b/src/gl-journal.h
index 1e73480..08c8021 100644
--- a/src/gl-journal.h
+++ b/src/gl-journal.h
@@ -71,7 +71,7 @@ typedef struct
 
 GType gl_journal_result_get_type (void);
 GType gl_journal_get_type (void);
-void gl_journal_set_matches (GlJournal *journal, const gchar * const *matches);
+void gl_journal_set_matches (GlJournal *journal, GPtrArray *matches);
 GArray * gl_journal_get_boot_ids (GlJournal *journal);
 GlJournalEntry * gl_journal_previous (GlJournal *journal);
 GlJournal * gl_journal_new (void);


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