[bijiben] src: Various const-correctness fixes



commit e971a0b914ec407d644cce8bde213b2f91277ea3
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sun Apr 23 18:37:42 2017 +0800

    src: Various const-correctness fixes
    
    This makes it clearer about which bits of code have ownership of which
    bits of memory, and also shut up compiler warnings about discarding
    const modifiers from variables.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762648

 src/bjb-color-button.c                         |   14 +++++-----
 src/bjb-empty-results-box.c                    |    3 +-
 src/bjb-import-dialog.c                        |    6 ++--
 src/bjb-main-view.c                            |    4 +-
 src/bjb-note-view.c                            |    3 +-
 src/bjb-share.c                                |   32 ++++++++++++------------
 src/libbiji/biji-date-time.c                   |    8 +++---
 src/libbiji/biji-date-time.h                   |    8 +++---
 src/libbiji/biji-error.c                       |    2 +-
 src/libbiji/biji-error.h                       |    2 +-
 src/libbiji/biji-note-obj.c                    |    2 +-
 src/libbiji/biji-note-obj.h                    |    2 +-
 src/libbiji/biji-string.c                      |   10 ++++---
 src/libbiji/biji-string.h                      |    8 +++---
 src/libbiji/biji-zeitgeist.c                   |    2 +-
 src/libbiji/biji-zeitgeist.h                   |    8 +++---
 src/libbiji/provider/biji-import-provider.c    |    2 +-
 src/libbiji/provider/biji-local-provider.c     |    4 +-
 src/libbiji/provider/biji-own-cloud-provider.c |    2 +-
 src/libbiji/serializer/biji-lazy-serializer.c  |    4 ++-
 20 files changed, 66 insertions(+), 60 deletions(-)
---
diff --git a/src/bjb-color-button.c b/src/bjb-color-button.c
index 87cdc68..8ae5eff 100644
--- a/src/bjb-color-button.c
+++ b/src/bjb-color-button.c
@@ -1,16 +1,16 @@
 /* bjb-color-button.c
  * Copyright (C) Pierre-Yves Luyten 2012 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * anjuta is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -27,7 +27,7 @@
 // Bijiben probably wants something like 6 light colors
 #define BJB_NUM_COLORS 4
 
-static gchar *palette_str[BJB_NUM_COLORS] = {
+static const gchar *palette_str[BJB_NUM_COLORS] = {
   "rgb(239, 242, 209)", // eff2d1 from the mockup
   "rgb(210, 219, 230)", // d2dbe6 from the mockup
   "rgb(229, 230, 210)", //
@@ -110,7 +110,7 @@ bjb_color_button_clicked (GtkButton *b)
       for (i=0 ; i< BJB_NUM_COLORS ; i++)
       {
         GdkRGBA color;
-  
+
         if (gdk_rgba_parse (&color, palette_str[i]))
           priv->palette [i] = color;
       }
@@ -161,9 +161,9 @@ bjb_color_button_finalize (GObject *object)
 static void
 bjb_color_button_class_init (BjbColorButtonClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass); 
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
-    
+
   g_type_class_add_private (klass, sizeof (BjbColorButtonPrivate));
 
   object_class->constructed = bjb_color_button_constructed;
diff --git a/src/bjb-empty-results-box.c b/src/bjb-empty-results-box.c
index 200c446..decbf32 100644
--- a/src/bjb-empty-results-box.c
+++ b/src/bjb-empty-results-box.c
@@ -49,7 +49,8 @@ bjb_empty_results_box_constructed (GObject *object)
   BjbEmptyResultsBoxPrivate *priv;
   GtkStyleContext *context;
   GtkWidget *labels_grid;
-  gchar *label, *markup;
+  const gchar *label;
+  gchar *markup;
   GFile *note_icon_file;
   GIcon *icon;
 
diff --git a/src/bjb-import-dialog.c b/src/bjb-import-dialog.c
index 4b89780..22881be 100644
--- a/src/bjb-import-dialog.c
+++ b/src/bjb-import-dialog.c
@@ -112,7 +112,7 @@ import_dialog_child_free (ImportDialogChild *child)
  * might use app_info here */
 
 static GdkPixbuf *
-get_app_icon (gchar *app_name)
+get_app_icon (const gchar *app_name)
 {
   gint i;
   GdkPixbuf *retval= NULL;
@@ -333,8 +333,8 @@ add_custom (BjbImportDialog *self)
 
 
 static ImportDialogChild *
-add_application (gchar *app,
-                 gchar *visible_label,
+add_application (const gchar *app,
+                 const gchar *visible_label,
                  gchar *location)
 {
   GtkWidget *box, *w;
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index b04d92e..13165ef 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -388,7 +388,7 @@ on_item_activated (GdMainView        * gd,
   return FALSE ;
 }
 
-static GtkTargetEntry target_list[] = {
+static const GtkTargetEntry target_list[] = {
   { "text/plain", 0, 2}
 };
 
@@ -556,7 +556,7 @@ render_date     (GtkTreeViewColumn *tree_column,
                  gpointer data)
 {
   BijiItem *item;
-  gchar *str;
+  const gchar *str;
   BjbMainView *self;
 
   self = data;
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index 22bec85..930d476 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -173,7 +173,8 @@ on_note_trashed (BijiNoteObj *note, BjbNoteView *view)
 static void
 on_note_color_changed_cb (BijiNoteObj *note, BjbNoteView *self)
 {
-  gchar *font_color, *span, *text;
+  const gchar *font_color;
+  gchar *span, *text;
   BjbNoteViewPrivate *priv = self->priv;
   GdkRGBA color;
 
diff --git a/src/bjb-share.c b/src/bjb-share.c
index b01e26d..38bf6f3 100644
--- a/src/bjb-share.c
+++ b/src/bjb-share.c
@@ -1,16 +1,16 @@
 /* biji-share.c
  * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -30,29 +30,29 @@ mail_str (const gchar * string )
 gboolean
 on_email_note_callback(GtkWidget *widget, BijiNoteObj *note)
 {
-  GError *error;    
-  error = NULL;
+  GError *error = NULL;
   gchar *title_mail, *text_mail;
+  const gchar *execute[7];
 
   title_mail = mail_str ((gchar*) biji_item_get_title (BIJI_ITEM (note)));
   text_mail = mail_str (biji_note_obj_get_raw_text (note));
 
-  gchar *execute[7] = { "xdg-email",
-                        "--utf8",
-                        "--subject",
-                        title_mail,
-                        "--body",
-                        text_mail,
-                        NULL } ;
-                        
-  g_spawn_async ( NULL, 
-                  execute,
+  execute[0] = "xdg-email";
+  execute[1] = "--utf8";
+  execute[2] = "--subject";
+  execute[3] = title_mail;
+  execute[4] = "--body";
+  execute[5] = text_mail;
+  execute[6] = NULL;
+
+  g_spawn_async ( NULL,
+                  (gchar **) execute,
                   NULL,
                   G_SPAWN_SEARCH_PATH,
                   NULL,
                   NULL,
                   NULL,
-                  &error); 
+                  &error);
   if ( error != NULL )
     g_message("error :%s",error->message);
 
diff --git a/src/libbiji/biji-date-time.c b/src/libbiji/biji-date-time.c
index 2df770f..abb4a6e 100644
--- a/src/libbiji/biji-date-time.c
+++ b/src/libbiji/biji-date-time.c
@@ -1,16 +1,16 @@
 /* biji-date-time.c
  * Copyright (C) Pierre-Yves LUYTEN 2011 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 
@@ -18,7 +18,7 @@
 
 #include "libbiji.h"
 
-gchar *
+const gchar *
 biji_get_time_diff_with_time (glong sec_since_epoch)
 {
   GTimeVal now;
diff --git a/src/libbiji/biji-date-time.h b/src/libbiji/biji-date-time.h
index b840586..87bab99 100644
--- a/src/libbiji/biji-date-time.h
+++ b/src/libbiji/biji-date-time.h
@@ -1,16 +1,16 @@
 /* biji-date-time.h
  * Copyright (C) Pierre-Yves LUYTEN 2011-2013 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 
@@ -23,7 +23,7 @@
 
 
 
-gchar            *biji_get_time_diff_with_time            (glong sec_since_epoch);
+const gchar      *biji_get_time_diff_with_time            (glong sec_since_epoch);
 
 
 
diff --git a/src/libbiji/biji-error.c b/src/libbiji/biji-error.c
index 1c52243..df59208 100644
--- a/src/libbiji/biji-error.c
+++ b/src/libbiji/biji-error.c
@@ -46,7 +46,7 @@ biji_error_quark (void)
 
 GError *
 biji_error_new (BijiErrorType type,
-                gchar *message)
+                const gchar *message)
 {
   return g_error_new_literal (BIJI_ERROR, type, message);
 }
diff --git a/src/libbiji/biji-error.h b/src/libbiji/biji-error.h
index da89ff6..a4b3de3 100644
--- a/src/libbiji/biji-error.h
+++ b/src/libbiji/biji-error.h
@@ -45,7 +45,7 @@ GQuark               biji_error_quark                       (void);
 
 
 GError              *biji_error_new                        (BijiErrorType type,
-                                                            gchar *message);
+                                                            const gchar *message);
 
 
 G_END_DECLS
diff --git a/src/libbiji/biji-note-obj.c b/src/libbiji/biji-note-obj.c
index 6f86dca..968497e 100644
--- a/src/libbiji/biji-note-obj.c
+++ b/src/libbiji/biji-note-obj.c
@@ -367,7 +367,7 @@ biji_note_obj_get_mtime (BijiItem *note)
   return biji_note_id_get_mtime (BIJI_NOTE_OBJ (note)->priv->id);
 }
 
-gchar *
+const gchar *
 biji_note_obj_get_last_change_date_string (BijiNoteObj *self)
 {
   g_return_val_if_fail (BIJI_IS_NOTE_OBJ (self), "");
diff --git a/src/libbiji/biji-note-obj.h b/src/libbiji/biji-note-obj.h
index 04f54ed..d27b376 100644
--- a/src/libbiji/biji-note-obj.h
+++ b/src/libbiji/biji-note-obj.h
@@ -118,7 +118,7 @@ gboolean         biji_note_obj_set_mtime                     (BijiNoteObj* n,
                                                               gint64 time);
 
 
-gchar           *biji_note_obj_get_last_change_date_string   (BijiNoteObj *self);
+const gchar     *biji_note_obj_get_last_change_date_string   (BijiNoteObj *self);
 
 
 gint64           biji_note_obj_get_last_metadata_change_date (BijiNoteObj *note);
diff --git a/src/libbiji/biji-string.c b/src/libbiji/biji-string.c
index 8b6ed4b..a09898a 100644
--- a/src/libbiji/biji-string.c
+++ b/src/libbiji/biji-string.c
@@ -1,16 +1,16 @@
 /* biji-string.c
  * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -19,7 +19,9 @@
 #include "biji-string.h"
 
 gchar *
-biji_str_replace (const gchar *string, gchar *as_is, gchar *to_be)
+biji_str_replace (const gchar *string,
+                  const gchar *as_is,
+                  const gchar *to_be)
 {
   gchar **array;
   gchar *result = NULL;
diff --git a/src/libbiji/biji-string.h b/src/libbiji/biji-string.h
index a1d55a5..d9a8cef 100644
--- a/src/libbiji/biji-string.h
+++ b/src/libbiji/biji-string.h
@@ -1,16 +1,16 @@
 /* biji-string.h
  * Copyright (C) Pierre-Yves LUYTEN 2012 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
@@ -25,7 +25,7 @@ G_BEGIN_DECLS
 
 /* Replaces inside string the as_is with to_be
  * Returns a newly allocated string */
-gchar * biji_str_replace (const gchar *string, gchar *as_is, gchar *to_be);
+gchar * biji_str_replace (const gchar *string, const gchar *as_is, const gchar *to_be);
 
 /* Calls biji_str_replace as much as there are paired gchar* args
  * Returns a newly allocated string */
diff --git a/src/libbiji/biji-zeitgeist.c b/src/libbiji/biji-zeitgeist.c
index 29884f0..04da913 100644
--- a/src/libbiji/biji-zeitgeist.c
+++ b/src/libbiji/biji-zeitgeist.c
@@ -120,7 +120,7 @@ check_insert_create_zeitgeist (BijiNoteObj *note)
 
 void
 insert_zeitgeist (BijiNoteObj *note,
-                  gchar *zg_interpretation)
+                  const gchar *zg_interpretation)
 {
   gchar *uri;
   const gchar *title;
diff --git a/src/libbiji/biji-zeitgeist.h b/src/libbiji/biji-zeitgeist.h
index e41525d..165a714 100644
--- a/src/libbiji/biji-zeitgeist.h
+++ b/src/libbiji/biji-zeitgeist.h
@@ -1,16 +1,16 @@
 /* biji-zeitgeist.h
  * Copyright (C) Pierre-Yves LUYTEN 2011 <py luyten fr>
- * 
+ *
  * bijiben is free software: you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  * Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- * 
+ *
  * bijiben is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  * See the GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program.  If not, see <http://www.gnu.org/licenses/>.*/
 
@@ -31,7 +31,7 @@ ZeitgeistLog           *biji_zeitgeist_init             (void);
 
 
 void                    insert_zeitgeist                (BijiNoteObj *note,
-                                                         gchar *zg_interpretation);
+                                                         const gchar *zg_interpretation);
 
 #endif /* BUILD_ZEITGEIST */
 
diff --git a/src/libbiji/provider/biji-import-provider.c b/src/libbiji/provider/biji-import-provider.c
index 7da19a3..f56aca5 100644
--- a/src/libbiji/provider/biji-import-provider.c
+++ b/src/libbiji/provider/biji-import-provider.c
@@ -234,7 +234,7 @@ biji_import_provider_constructed (GObject *object)
 
   priv->info.unique_id = NULL;
   priv->info.datasource = NULL;
-  priv->info.name = "import-provider";
+  priv->info.name = (gchar *) "import-provider";
   priv->info.icon =  NULL;
   priv->info.domain = NULL;
   priv->info.user = NULL;
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
index eb25196..72c41df 100644
--- a/src/libbiji/provider/biji-local-provider.c
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -211,8 +211,8 @@ enumerate_next_files_ready_cb (GObject *source,
         continue;
 
       info.url = g_build_filename (base_path, name, NULL);
-      info.title = "";
-      info.content = "";
+      info.title = (gchar *) "";
+      info.content = (gchar *) "";
       info.mtime = 0;
 
 
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index 3b2e3c9..ed0322e 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -912,7 +912,7 @@ own_cloud_create_note (BijiProvider *provider,
   info.url = NULL;
   info.title = NULL;
   info.mtime = g_get_real_time ();
-  info.content = "";
+  info.content = (gchar *) "";
   info.created = g_get_real_time ();
 
   return biji_own_cloud_note_new_from_info (
diff --git a/src/libbiji/serializer/biji-lazy-serializer.c b/src/libbiji/serializer/biji-lazy-serializer.c
index eef19f2..1e5c2ae 100644
--- a/src/libbiji/serializer/biji-lazy-serializer.c
+++ b/src/libbiji/serializer/biji-lazy-serializer.c
@@ -131,7 +131,9 @@ biji_lazy_serializer_class_init (BijiLazySerializerClass *klass)
 }
 
 static void
-serialize_node (xmlTextWriterPtr writer, gchar *node, gchar *value)
+serialize_node (xmlTextWriterPtr writer,
+                const gchar *node,
+                const gchar *value)
 {
   xmlTextWriterWriteRaw     (writer, BAD_CAST "\n  ");
   xmlTextWriterStartElement (writer, BAD_CAST node);


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