[sound-juicer] Constify string literals



commit 67439853e2c3f799f4752d095ea2cfc5ac623339
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Tue Oct 11 11:00:32 2016 +0100

    Constify string literals
    
    Ensure string literals are declared const to prevent warnings from
    -Wwrite-strings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777692

 libjuicer/rb-gst-media-types.c       |    2 +-
 libjuicer/sj-metadata-musicbrainz5.c |   15 ++++++++++-----
 libjuicer/sj-metadata.c              |    4 ++--
 src/sj-main.c                        |   20 ++++++++++----------
 src/sj-prefs.c                       |   16 ++++++++--------
 5 files changed, 31 insertions(+), 26 deletions(-)
---
diff --git a/libjuicer/rb-gst-media-types.c b/libjuicer/rb-gst-media-types.c
index b8ab009..fc581e0 100644
--- a/libjuicer/rb-gst-media-types.c
+++ b/libjuicer/rb-gst-media-types.c
@@ -205,7 +205,7 @@ GstEncodingTarget *
 rb_gst_get_default_encoding_target (void)
 {
        if (default_target == NULL) {
-               char *target_file;
+                const char *target_file;
                GError *error = NULL;
 
                if (g_file_test (SOURCE_ENCODING_TARGET_FILE,
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index c073645..253282e 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -213,12 +213,12 @@ static Mb5Metadata
 query_musicbrainz (SjMetadataMusicbrainz5  *self,
                    const char              *entity,
                    const char              *id,
-                   char                    *includes,
+                   const char              *includes,
                    GCancellable            *cancellable,
                    GError                 **error)
 {
   Mb5Metadata metadata;
-  char *inc[] = { "inc" };
+  char *inc, *includes_copy;
   gint64 delay = 4 * G_USEC_PER_SEC;
   int count = 0;
   SjMetadataMusicbrainz5Private *priv = GET_PRIVATE (self);
@@ -226,6 +226,9 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
 
   g_info ("Querying %s %s", entity, id);
 
+  inc = g_strdup ("inc");
+  includes_copy = g_strdup (includes);
+
   while (TRUE) {
     if (g_cancellable_set_error_if_cancelled (cancellable, error))
       return NULL;
@@ -241,7 +244,7 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
                                   0, NULL, NULL);
     else
       metadata = mb5_query_query (priv->mb, entity, id, "",
-                                  1, inc, &includes);
+                                  1, &inc, &includes_copy);
 
     if (metadata != NULL || ++count == 5 ||
         mb5_query_get_lasthttpcode (priv->mb) != 503)
@@ -261,6 +264,8 @@ query_musicbrainz (SjMetadataMusicbrainz5  *self,
     print_musicbrainz_query_error (self, entity, id);
 
   last_query_time = g_get_monotonic_time ();
+  g_free (inc);
+  g_free (includes_copy);
   return metadata;
 }
 
@@ -1124,7 +1129,7 @@ mb5_list_albums (SjMetadata    *metadata,
     AlbumDetails *album;
     Mb5Release full_release = NULL;
     Mb5Metadata release_md = NULL;
-    char *release_includes = "aliases artists artist-credits labels recordings \
+    const char *release_includes = "aliases artists artist-credits labels recordings \
 release-groups url-rels discids recording-level-rels work-level-rels work-rels \
 artist-rels";
 
@@ -1152,7 +1157,7 @@ artist-rels";
          * release-group, so run a separate query to get these urls
          */
         char *releasegroupid = NULL;
-        char *group_includes = "artists url-rels";
+        const char *group_includes = "artists url-rels";
 
         GET (releasegroupid, mb5_releasegroup_get_id, group);
         group_md = query_musicbrainz (self, "release-group", releasegroupid, group_includes, cancellable, 
error);
diff --git a/libjuicer/sj-metadata.c b/libjuicer/sj-metadata.c
index 51bb387..3817db7 100644
--- a/libjuicer/sj-metadata.c
+++ b/libjuicer/sj-metadata.c
@@ -367,8 +367,8 @@ sj_metadata_helper_lookup_country_code (const char *code)
      treat those as a special case if we don't get a match from the
      iso-codes data */
   static const struct {
-    char *code;
-    char *name;
+    const char *code;
+    const char *name;
   } mb_countries[]  = {
     {"XC", N_("Czechoslovakia")},
     {"XG", N_("East Germany")},
diff --git a/src/sj-main.c b/src/sj-main.c
index 0c86dfd..83f6746 100644
--- a/src/sj-main.c
+++ b/src/sj-main.c
@@ -693,7 +693,7 @@ choose_album(GList *albums)
 /**
  * The GSettings key for the base path changed
  */
-static void baseuri_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void baseuri_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   gchar *value;
   g_assert (strcmp (key, SJ_SETTINGS_BASEURI) == 0);
@@ -718,7 +718,7 @@ static void baseuri_changed_cb (GSettings *settings, gchar *key, gpointer user_d
 /**
  * The GSettings key for the directory pattern changed
  */
-static void path_pattern_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void path_pattern_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_PATH_PATTERN) == 0);
   g_free (sj_path_pattern);
@@ -733,7 +733,7 @@ static void path_pattern_changed_cb (GSettings *settings, gchar *key, gpointer u
 /**
  * The GSettings key for the filename pattern changed
  */
-static void file_pattern_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void file_pattern_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_FILE_PATTERN) == 0);
   g_free (sj_file_pattern);
@@ -748,7 +748,7 @@ static void file_pattern_changed_cb (GSettings *settings, gchar *key, gpointer u
 /**
  * The GSettings key for the paranoia mode has changed
  */
-static void paranoia_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void paranoia_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   int value;
   g_assert (strcmp (key, SJ_SETTINGS_PARANOIA) == 0);
@@ -765,7 +765,7 @@ static void paranoia_changed_cb (GSettings *settings, gchar *key, gpointer user_
 /**
  * The GSettings key for the strip characters option changed
  */
-static void strip_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void strip_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_STRIP) == 0);
   strip_chars = g_settings_get_boolean (settings, key);
@@ -774,7 +774,7 @@ static void strip_changed_cb (GSettings *settings, gchar *key, gpointer user_dat
 /**
  * The GSettings key for the eject when finished option changed
  */
-static void eject_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void eject_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_EJECT) == 0);
   eject_finished = g_settings_get_boolean (settings, key);
@@ -783,7 +783,7 @@ static void eject_changed_cb (GSettings *settings, gchar *key, gpointer user_dat
 /**
  * The GSettings key for the open when finished option changed
  */
-static void open_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void open_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_OPEN) == 0);
   open_finished = g_settings_get_boolean (settings, key);
@@ -792,7 +792,7 @@ static void open_changed_cb (GSettings *settings, gchar *key, gpointer user_data
 /**
  * The GSettings key for audio volume changes
  */
-static void audio_volume_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void audio_volume_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   g_assert (strcmp (key, SJ_SETTINGS_AUDIO_VOLUME) == 0);
 
@@ -1097,7 +1097,7 @@ prefs_get_default_device (void)
 /**
  * The GSettings key for the device changed
  */
-static void device_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void device_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   const char *device;
   char *value;
@@ -1128,7 +1128,7 @@ static void device_changed_cb (GSettings *settings, gchar *key, gpointer user_da
   g_free (value);
 }
 
-static void profile_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void profile_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   GstEncodingProfile *profile;
   char *media_type;
diff --git a/src/sj-prefs.c b/src/sj-prefs.c
index 87832b6..adc17a2 100644
--- a/src/sj-prefs.c
+++ b/src/sj-prefs.c
@@ -43,8 +43,8 @@ static GtkWidget *cd_option, *path_option, *file_option, *basepath_fcb, *check_s
 static GtkWidget *path_example_label;
 
 typedef struct {
-  char* name;
-  char* pattern;
+  const char* name;
+  const char* pattern;
 } FilePattern;
 
 static const FilePattern path_patterns[] = {
@@ -156,7 +156,7 @@ static void prefs_pattern_option_changed (GtkComboBox *combo, gpointer key)
   }
 }
 
-static void baseuri_changed_cb  (GSettings *settings, gchar *key, gpointer user_data)
+static void baseuri_changed_cb  (GSettings *settings, const gchar *key, gpointer user_data)
 {
   /*
    * The conflict between separation of the prefs and the main window,
@@ -260,7 +260,7 @@ static void pattern_label_update (void)
   g_free (format);
 }
 
-static void settings_changed_cb (GSettings *settings, gchar *key, gpointer combo)
+static void settings_changed_cb (GSettings *settings, const gchar *key, gpointer combo)
 {
   char *value;
 
@@ -275,7 +275,7 @@ static void settings_changed_cb (GSettings *settings, gchar *key, gpointer combo
 /**
  * Default device changed (either GSettings key or the widget)
  */
-static void device_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void device_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   BraseroDrive *drive;
   BraseroMediumMonitor *monitor;
@@ -310,7 +310,7 @@ static void prefs_drive_changed (BraseroDriveSelection *selection, BraseroDrive
 /**
  * The GSettings key for the strip characters option changed
  */
-static void strip_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+static void strip_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
   /* NOTE that strip_changed_cb in sj-main.c will also be called, and will also update
      the global value strip_chars - but which function will get called first?
@@ -378,8 +378,8 @@ void show_preferences_dialog ()
   if (prefs_dialog) {
     gtk_window_present (GTK_WINDOW (prefs_dialog));
   } else {
-    static gchar *path_key = SJ_SETTINGS_PATH_PATTERN;
-    static gchar *file_key = SJ_SETTINGS_FILE_PATTERN;
+    static const gchar *path_key = SJ_SETTINGS_PATH_PATTERN;
+    static const gchar *file_key = SJ_SETTINGS_FILE_PATTERN;
 
     prefs_dialog = GET_WIDGET ("prefs_dialog");
     g_assert (prefs_dialog != NULL);


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