From c344fa6a506d117f1e4c9a6213c5c94937631ff9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Oct 2008 20:13:50 -0700 Subject: Assert if we don't have song or song->url set song objects cannot exist without a path or URL --- src/song.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index ab98963ad..27f48ad03 100644 --- a/src/song.c +++ b/src/song.c @@ -31,8 +31,13 @@ static Song * song_alloc(const char *url, Directory *parent) { - size_t urllen = strlen(url); - Song *song = xmalloc(sizeof(Song) + urllen); + size_t urllen; + Song *song; + + assert(url); + urllen = strlen(url); + assert(urllen); + song = xmalloc(sizeof(Song) + urllen); song->tag = NULL; memcpy(song->url, url, urllen + 1); @@ -44,6 +49,7 @@ static Song * song_alloc(const char *url, Directory *parent) Song *newSong(const char *url, Directory * parentDir) { Song *song; + assert(*url); if (strchr(url, '\n')) { DEBUG("newSong: '%s' is not a valid uri\n", url); -- cgit v1.2.3 From a5f8bb82300d08568180482c93e8b9a067cc715d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Oct 2008 20:54:11 -0700 Subject: song: replace printSong* with song_print_* This make argument order more consistent for iterators. Additionally, these now return ssize_t results for error checking. --- src/song.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index 27f48ad03..61fe78a43 100644 --- a/src/song.c +++ b/src/song.c @@ -92,24 +92,24 @@ void freeJustSong(Song * song) free(song); } -void printSongUrl(int fd, Song * song) +ssize_t song_print_url(Song *song, int fd) { - if (song->parentDir && song->parentDir->path) { - fdprintf(fd, "%s%s/%s\n", SONG_FILE, - getDirectoryPath(song->parentDir), song->url); - } else { - fdprintf(fd, "%s%s\n", SONG_FILE, song->url); - } + if (song->parentDir && song->parentDir->path) + return fdprintf(fd, "%s%s/%s\n", SONG_FILE, + getDirectoryPath(song->parentDir), song->url); + return fdprintf(fd, "%s%s\n", SONG_FILE, song->url); } -int printSongInfo(int fd, Song * song) +ssize_t song_print_info(Song *song, int fd) { - printSongUrl(fd, song); + ssize_t ret = song_print_url(song, fd); + if (ret < 0) + return ret; if (song->tag) tag_print(fd, song->tag); - return 0; + return ret; } static void insertSongIntoList(struct songvec *sv, Song *newsong) -- cgit v1.2.3 From 9bda68824ebd1b87d5ab28802ab4c310bc9d148a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 6 Oct 2008 01:44:53 -0700 Subject: song: add print_song_info_x for iterators tha pass void * traverseAllIn will be modified to take < 0 as errors instead of non-zero... --- src/song.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index 61fe78a43..71191c149 100644 --- a/src/song.c +++ b/src/song.c @@ -112,6 +112,11 @@ ssize_t song_print_info(Song *song, int fd) return ret; } +int song_print_info_x(Song * song, void *data) +{ + return song_print_info(song, (int)(size_t)data); +} + static void insertSongIntoList(struct songvec *sv, Song *newsong) { Song *existing = songvec_find(sv, newsong->url); -- cgit v1.2.3 From a67facd051d817dd53bac1aebfc554b07420e8cd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 7 Oct 2008 02:06:01 -0700 Subject: song: Add song_print_url_x It'll be handy for passing throug songvec_for_each like song_print_info_x. --- src/song.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index 71191c149..f967e3e17 100644 --- a/src/song.c +++ b/src/song.c @@ -117,6 +117,11 @@ int song_print_info_x(Song * song, void *data) return song_print_info(song, (int)(size_t)data); } +int song_print_url_x(Song * song, void *data) +{ + return song_print_url(song, (int)(size_t)data); +} + static void insertSongIntoList(struct songvec *sv, Song *newsong) { Song *existing = songvec_find(sv, newsong->url); -- cgit v1.2.3 From 19c6f1ee92cf6514e885def44f7deb9d225de4dc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 7 Oct 2008 02:57:59 -0700 Subject: directory: serialize song deletes from playlist during update This makes the update code thread-safe and doesn't penalize the playlist code by complicating it with complicated and error-prone locks (and the associated overhead, not everybody has a thread-implementation as good as NPTL). The update task blocks during the delete; but the update task is a slow task anyways so we can block w/o people caring too much. This was also our only freeSong call site, so remove that function. Note that deleting entire directories is not fully thread-safe, yet; as their traversals are not yet locked. --- src/song.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index f967e3e17..c9301386d 100644 --- a/src/song.c +++ b/src/song.c @@ -79,12 +79,6 @@ Song *newSong(const char *url, Directory * parentDir) return song; } -void freeSong(Song * song) -{ - deleteASongFromPlaylist(song); - freeJustSong(song); -} - void freeJustSong(Song * song) { if (song->tag) -- cgit v1.2.3