From: Andre Noll Date: Mon, 21 Mar 2016 22:17:22 +0000 (+0000) Subject: Constify argument of playlist_open() and change_current_mood(). X-Git-Tag: v0.5.6~30 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=c2396d21b32adec8a94bdae47d66bdc492779775 Constify argument of playlist_open() and change_current_mood(). 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. --- diff --git a/afs.c b/afs.c index 0b24a3b8..cc3fc020 100644 --- a/afs.c +++ b/afs.c @@ -497,7 +497,7 @@ no_admissible_files: } /* 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; @@ -590,7 +590,7 @@ static void flush_and_free_pb(struct para_buffer *pb) 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(); diff --git a/afs.h b/afs.h index 25ff421d..2f9d7e5f 100644 --- 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 playlist_open(char *name); +int playlist_open(const char *name); void playlist_close(void); int playlist_check_callback(struct afs_callback_arg *aca); diff --git a/mood.c b/mood.c index daa8196a..83c3a574 100644 --- 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(). */ -int change_current_mood(char *mood_name) +int change_current_mood(const char *mood_name) { 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 = { - .data = mood_name, + .data = (char *)mood_name, .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 10e9319b..f7055753 100644 --- a/mood.h +++ b/mood.h @@ -6,6 +6,6 @@ /** \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); diff --git a/playlist.c b/playlist.c index 01392030..8ea1854b 100644 --- a/playlist.c +++ b/playlist.c @@ -159,13 +159,13 @@ void playlist_close(void) * * \return Standard. */ -int playlist_open(char *name) +int playlist_open(const char *name) { 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) {