Constify argument of playlist_open() and change_current_mood().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 21 Mar 2016 22:17:22 +0000 (22:17 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 8 May 2016 12:29:27 +0000 (14:29 +0200)
The only reason these arguments are not const is that we create an
osl object out of it, which contains a non-constant data pointer.

The osl library functions we call here will not touch this memory,
so it's safe to let both functions take a const pointer and cast it at
initialization of the non-constant ->data pointer of struct osl object.

The single caller of each function is activate_mood_or_playlist()
whose argument can now also me made to point to constant memory.

Finally, the arg pointer of com_select_callback() is passed to
activate_mood_or_playlist(), so the variable can be of type const
char * as well.

afs.c
afs.h
mood.c
mood.h
playlist.c

diff --git a/afs.c b/afs.c
index 0b24a3b8cdb7c53f70b09bba317f9afe523d9320..cc3fc020370821ff028a2543c354dab4acc08039 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -497,7 +497,7 @@ no_admissible_files:
 }
 
 /* Never fails if arg == NULL */
 }
 
 /* Never fails if arg == NULL */
-static int activate_mood_or_playlist(char *arg, int *num_admissible)
+static int activate_mood_or_playlist(const char *arg, int *num_admissible)
 {
        enum play_mode mode;
        int ret;
 {
        enum play_mode mode;
        int ret;
@@ -590,7 +590,7 @@ static void flush_and_free_pb(struct para_buffer *pb)
 
 static int com_select_callback(struct afs_callback_arg *aca)
 {
 
 static int com_select_callback(struct afs_callback_arg *aca)
 {
-       char *arg = aca->query.data;
+       const char *arg = aca->query.data;
        int num_admissible, ret;
 
        ret = clear_score_table();
        int num_admissible, ret;
 
        ret = clear_score_table();
diff --git a/afs.h b/afs.h
index 25ff421d8b86d0f5708d4b4f3749f310f9c4a877..2f9d7e5fc40bdc9c1661336ffce20d7a7df76148 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -263,7 +263,7 @@ int audio_file_loop(void *private_data, osl_rbtree_loop_func *func);
 int aft_check_callback(struct afs_callback_arg *aca);
 
 /* playlist */
 int aft_check_callback(struct afs_callback_arg *aca);
 
 /* playlist */
-int playlist_open(char *name);
+int playlist_open(const char *name);
 void playlist_close(void);
 int playlist_check_callback(struct afs_callback_arg *aca);
 
 void playlist_close(void);
 int playlist_check_callback(struct afs_callback_arg *aca);
 
diff --git a/mood.c b/mood.c
index daa8196ad1a05fc9a7aa3d0ad648fdcaddf56fb0..83c3a574a53c5658afe43a296ae2de9f2c368873 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -795,7 +795,7 @@ void close_current_mood(void)
  * \sa struct admissible_file_info, struct admissible_array, struct
  * afs_info::last_played, mood_close().
  */
  * \sa struct admissible_file_info, struct admissible_array, struct
  * afs_info::last_played, mood_close().
  */
-int change_current_mood(char *mood_name)
+int change_current_mood(const char *mood_name)
 {
        int i, ret;
        struct admissible_array aa = {
 {
        int i, ret;
        struct admissible_array aa = {
@@ -807,7 +807,7 @@ int change_current_mood(char *mood_name)
                struct mood *m;
                struct osl_row *row;
                struct osl_object obj = {
                struct mood *m;
                struct osl_row *row;
                struct osl_object obj = {
-                       .data = mood_name,
+                       .data = (char *)mood_name,
                        .size = strlen(mood_name) + 1
                };
                ret = osl(osl_get_row(moods_table, BLOBCOL_NAME, &obj, &row));
                        .size = strlen(mood_name) + 1
                };
                ret = osl(osl_get_row(moods_table, BLOBCOL_NAME, &obj, &row));
diff --git a/mood.h b/mood.h
index 10e9319b2b2c8e7a7a094207609634a23a6b3a22..f7055753cf82fee8533f4f5fb0519ae4c86790d9 100644 (file)
--- a/mood.h
+++ b/mood.h
@@ -6,6 +6,6 @@
 
 /** \file mood.h Public functions of mood.c. */
 
 
 /** \file mood.h Public functions of mood.c. */
 
-int change_current_mood(char *mood_name);
+int change_current_mood(const char *mood_name);
 void close_current_mood(void);
 int mood_check_callback(struct afs_callback_arg *aca);
 void close_current_mood(void);
 int mood_check_callback(struct afs_callback_arg *aca);
index 01392030a00305cea41707f4e40016507f0e20e1..8ea1854bddfc004db52d6d0afe577d6601960b07 100644 (file)
@@ -159,13 +159,13 @@ void playlist_close(void)
  *
  * \return Standard.
  */
  *
  * \return Standard.
  */
-int playlist_open(char *name)
+int playlist_open(const char *name)
 {
        struct osl_object obj;
        int ret;
        struct osl_row *row;
 
 {
        struct osl_object obj;
        int ret;
        struct osl_row *row;
 
-       obj.data = name;
+       obj.data = (char *)name;
        obj.size = strlen(obj.data);
        ret = osl(osl_get_row(playlists_table, BLOBCOL_NAME, &obj, &row));
        if (ret < 0) {
        obj.size = strlen(obj.data);
        ret = osl(osl_get_row(playlists_table, BLOBCOL_NAME, &obj, &row));
        if (ret < 0) {