aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* song: don't allow calling song_get_url(NULL)Max Kellermann2008-10-081-3/+1
| | | | | | The runtime check suggests that the author has somehow thought song_get_url(NULL) might be valid. It should not be. Replace it with an assertion.
* song: use song_file_update() in song_file_load()Max Kellermann2008-10-081-10/+3
| | | | Eliminate duplicated code.
* song: song_file_update() returns boolMax Kellermann2008-10-081-3/+3
| | | | | | Instead of returning 0 or -1, return true on success and false on failure. This seems more natural, and when the C library was designed, there was no "bool" data type.
* song: don't check song_is_file() in song_file_update()Max Kellermann2008-10-081-17/+16
| | | | | This function was never used on remote songs. Replace the runtime check with an assertion.
* song: removed CamelCaseMax Kellermann2008-10-081-10/+10
| | | | CamelCase is ugly... rename all functions.
* song: replaced all song constructorsMax Kellermann2008-10-081-21/+32
| | | | | | Provide separate constructors for creating a remote song, a local song, and one for loading data from a song file. This way, we can add more assertions.
* don't include os_compat.hMax Kellermann2008-10-081-2/+0
| | | | | When there are standardized headers, use these instead of the bloated os_compat.h.
* song: converted typedef Song to struct songMax Kellermann2008-10-081-7/+11
| | | | Again, a data type which can be forward-declared.
* directory: converted typedef Directory to struct directoryMax Kellermann2008-10-081-2/+2
| | | | | The struct can be forward-declared by other headers, which relaxes the header dependencies.
* directory: serialize song deletes from playlist during updateEric Wong2008-10-071-6/+0
| | | | | | | | | | | | | | | | 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.
* Assert if we don't have song or song->url setEric Wong2008-10-071-2/+8
| | | | song objects cannot exist without a path or URL
* song: stop storing song_typeEric Wong2008-10-061-8/+5
| | | | | | | We already know if a song is a URL or not based on whether it has parentDir defined or not. Hopefully one day in the future we can drop HTTP support from MPD entirely when an HTTP filesystem comes along and we can access streams via open(2).
* song: don't make the struct packedMax Kellermann2008-10-061-1/+1
| | | | | | The "packed" attribute may have negative side effects on performance. Remove the "packed" attribute, and increase the size of "song.url" to a multiple of the machine word size.
* song: use flex arrays to store song->urlEric Wong2008-10-061-7/+15
| | | | | | Reduce the number of allocations we make, so there's less pressure on the allocator and less overhead to keep track of the allocations in.
* song: get rid of newNullSong()Eric Wong2008-10-061-13/+2
| | | | | It didn't save us any lines of code nor did it do anything useful since we would overwrite everything anyways.
* song: call freeJustSong if newSong failsEric Wong2008-10-061-1/+1
| | | | | There's no reason to scan the playlist for a song we just allocated.
* decoder: renamed plugin methodsMax Kellermann2008-09-291-2/+2
| | | | | Why have a "_func" prefix on all method names? Also don't typedef the methods, there is no advantage in that.
* song: converted "type" to enumMax Kellermann2008-09-291-1/+1
| | | | | | Having an enum type is much nicer than an anonymous integer plus CPP macros. Note that the old code didn't save any space by declaring the variable 8 bit, due to padding.
* song: removed type SongListMax Kellermann2008-09-261-36/+0
| | | | SongList has been superseded by struct songvec.
* Replace SongList with struct songvecEric Wong2008-09-231-0/+1
| | | | | | | Our linked-list implementation is wasteful and the SongList isn't modified enough to benefit from being a linked list. So use a more compact array of song pointers which saves ~200K on a library with ~9K songs (on x86-32).
* song: moved code to song_print.c, song_save.cMax Kellermann2008-09-071-172/+1
| | | | | | | Move everything which dumps song information (via tag_print.c) to a separate source file. song_print.c gets code which writes song data to the client; song_save.c is responsible for serializing songs from the tag cache.
* tag: moved code to tag_print.cMax Kellermann2008-09-071-0/+1
| | | | | Move everything which dumps a tag to a file descriptor to tag_print.c. This relaxes dependencies and splits the code into smaller parts.
* tag: fix segfault on updateEric Wong2008-09-061-0/+1
| | | | | | | | | | | | clearMpdTag could be called on a tag that was still in a tag_begin_add transaction before tag_end_add is called. This was causing free() to attempt to operate on bulk.items; which is un-free()-able. Now instead we unmark the bulk.busy to avoid committing the tags to the heap only to be immediately freed. Additionally, we need to remember to call tag_end_add() when a song is updated before we NULL song->tag to avoid tripping an assertion the next time tag_begin_add() is called.
* tag: try not to reallocate tag.items in every add() callMax Kellermann2008-08-291-4/+16
| | | | | | | | | | | | | | | | If many tag_items are added at once while the tag cache is being loaded, manage these items in a static fixed list, instead of reallocating the list with every newly created item. This reduces heap fragmentation. Massif results again: mk before: total 12,837,632; useful 10,626,383; extra 2,211,249 mk now: total 12,736,720; useful 10,626,383; extra 2,110,337 The "useful" value is the same since this patch only changes the way we allocate the same amount of memory, but heap fragmentation was reduced by 5%.
* song: don't export newNullSong()Max Kellermann2008-08-291-1/+1
| | | | The function newNullSong() is only used internally in song.c.
* tag: renamed functions, no CamelCaseMax Kellermann2008-08-291-10/+10
|
* assert song->url != NULLMax Kellermann2008-08-261-0/+3
|
* no camel case in struct decoder_pluginMax Kellermann2008-08-261-2/+2
|
* renamed inputPlugin.* to decoder_list.*Max Kellermann2008-08-261-1/+1
| | | | | Since inputPlugin.c manages the list of registered decoders, we should rename the source file.
* renamed InputPlugin to struct decoder_pluginMax Kellermann2008-08-261-2/+3
| | | | | | "decoder plugin" is a better name than "input plugin", since the plugin does not actually do the input - InputStream does. Also don't use typedef, so we can forward-declare it if required.
* fix segmentation fault in song info parserMax Kellermann2008-03-261-4/+5
| | | | | | | The database parser does not check whether the song object has been initialized yet, which may lead to a NULL pointer dereference. Add this check. git-svn-id: https://svn.musicpd.org/mpd/trunk@7201 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* eliminated duplicate initializationMax Kellermann2008-03-261-7/+3
| | | | | | | Local variables which are never read before the first assignment don't need initialization. Saves a few bytes of text. Also don't reset variables which are never read until function return. git-svn-id: https://svn.musicpd.org/mpd/trunk@7199 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* fix -Wconst warningsMax Kellermann2008-02-051-2/+2
| | | | | | [ew: cleaned up the dirty union hack a bit] Signed-off-by: Eric Wong <normalperson@yhbt.net> git-svn-id: https://svn.musicpd.org/mpd/trunk@7180 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Cleanup #includes of standard system headers and put them in one placeEric Wong2008-01-031-3/+1
| | | | | | | | | | | | | This will make refactoring features easier, especially now that pthreads support and larger refactorings are on the horizon. Hopefully, this will make porting to other platforms (even non-UNIX-like ones for masochists) easier, too. os_compat.h will house all the #includes for system headers considered to be the "core" of MPD. Headers for optional features will be left to individual source files. git-svn-id: https://svn.musicpd.org/mpd/trunk@7130 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* song: updateSongInfo: left out charset conversion when going thread-safeEric Wong2008-01-011-2/+4
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@7124 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Merge branches/ew r7104Eric Wong2007-12-281-44/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | thread-safety work in preparation for rewrite to use pthreads Expect no regressions against trunk (r7078), possibly minor performance improvements in update (due to fewer heap allocations), but increased stack usage. Applied the following patches: * maxpath_str for reentrancy (temporary fix, reverted) * path: start working on thread-safe variants of these methods * Re-entrancy work on path/character-set conversions * directory.c: exploreDirectory() use reentrant functions here * directory/update: more use of reentrant functions + cleanups * string_toupper: a strdup-less version of strDupToUpper * get_song_url: a static-variable-free version of getSongUrl() * Use reentrant/thread-safe get_song_url everywhere * replace rmp2amp with the reentrant version, rmp2amp_r * Get rid of the non-reentrant/non-thread-safe rpp2app, too. * buffer2array: assert strdup() returns a usable value in unit tests * replace utf8ToFsCharset and fsCharsetToUtf8 with thread-safe variants * fix storing playlists w/o absolute paths * parent_path(), a reentrant version of parentPath() * parentPath => parent_path for reentrancy and thread-safety * allow "make test" to automatically run embedded unit tests * remove convStrDup() and maxpath_str() * use MPD_PATH_MAX everywhere instead of MAXPATHLEN * path: get rid of appendSlash, pfx_path and just use pfx_dir * get_song_url: fix the ability to play songs in the top-level music_directory git-svn-id: https://svn.musicpd.org/mpd/trunk@7106 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a singleJ. Alexander Treuman2007-05-261-8/+4
| | | | | call to FATAL(). git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* The massive copyright updateAvuton Olrich2007-04-051-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@5834 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Don't initialize globals to zero (or NULL)Eric Wong2007-01-141-3/+3
| | | | | | | | Some compilers and linkers aren't smart enough to optimize this, as global variables are implictly initialized to zero. As a result, binaries are a bit smaller as more goes in the .bss and less in the text section. git-svn-id: https://svn.musicpd.org/mpd/trunk@5254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* add support for: list fileWarren Dukes2006-10-271-2/+0
| | | | | This behaves the same as: list filename git-svn-id: https://svn.musicpd.org/mpd/trunk@4952 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Replace strdup and {c,re,m}alloc with x* variants to check for OOM errorsEric Wong2006-08-261-5/+6
| | | | | | | | | | | | | | | | | | | I'm checking for zero-size allocations and assert()-ing them, so we can more easily get backtraces and debug problems, but we'll also allow -DNDEBUG people to live on the edge if they wish. We do not rely on errno when checking for OOM errors because some implementations of malloc do not set it, and malloc is commonly overridden by userspace wrappers. I've spent some time looking through the source and didn't find any obvious places where we would explicitly allocate 0 bytes, so we shouldn't trip any of those assertions. We also avoid allocating zero bytes because C libraries don't handle this consistently (some return NULL, some not); and it's dangerous either way. git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* remove deprecated myfprintf wrapperEric Wong2006-07-301-4/+5
| | | | | | | This shaves another 5-6k because we've removed the paranoid fflush() calls after every fprintf. Now we only fflush() when we need to git-svn-id: https://svn.musicpd.org/mpd/trunk@4493 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* interface/connection malloc reductions from mpd-keEric Wong2006-07-301-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch massively reduces the amount of heap allocations at the interface/command layer. Most commands with minimal output should not allocate memory from the heap at all. Things like repeatedly polling status, currentsong, and volume changes should be faster as a result, and more importantly, not a source of memory fragmentation. These changes should be safe in that there's no way for a remote-client to corrupt memory or otherwise do bad stuff to MPD, but an extra set of eyes to review would be good. Of course there's never any warranty :) No longer do we use FILE * structures in the interface, which means we don't have to allocate any new memory for most connections. Now, before you go on about losing the buffering that FILE * +implies+, remember that myfprintf() never took advantage of any of the stdio buffering features. To reduce the diff and make bugs easier to spot in the diff, I've kept myfprintf in places where we write to files (and not network interfaces). Expect myfprintf to go away entirely soon (we'll use fprintf for writing regular files). git-svn-id: https://svn.musicpd.org/mpd/trunk@4483 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Add mpd-indent.shAvuton Olrich2006-07-201-121/+140
| | | | | | Indent the entire tree, hopefully we can keep it indented. git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* sparse: ANSI-fy function declarationsEric Wong2006-07-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are just warnings from sparse, but it makes the output easier to read. I ran this through a quick perl script, but of course verified the output by looking at the diff and making sure the thing still compiles. here's the quick perl script I wrote to generate this patch: ----------- 8< ----------- use Tie::File; defined(my $pid = open my $fh, '-|') or die $!; if (!$pid) { open STDERR, '>&STDOUT' or die $!; exec 'sparse', @ARGV or die $!; } my $na = 'warning: non-ANSI function declaration of function'; while (<$fh>) { print STDERR $_; if (/^(.+?\.[ch]):(\d+):(\d+): $na '(\w+)'/o) { my ($f, $l, $pos, $func) = ($1, $2, $3, $4); $l--; tie my @x, 'Tie::File', $f or die "$!: $f"; print '-', $x[$l], "\n"; $x[$l] =~ s/\b($func\s*)\(\s*\)/$1(void)/; print '+', $x[$l], "\n"; untie @x; } } git-svn-id: https://svn.musicpd.org/mpd/trunk@4378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* [CLEANUP] Remove unused codeAvuton Olrich2006-07-151-19/+7
| | | | | Cleanup whitespace->tabs git-svn-id: https://svn.musicpd.org/mpd/trunk@4347 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Change shank's email addressJ. Alexander Treuman2006-07-141-1/+1
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4333 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Huge header update, update the copyright and addAvuton Olrich2006-07-131-1/+1
| | | | | the GPL header where necessary git-svn-id: https://svn.musicpd.org/mpd/trunk@4317 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* Fix for bug 483Qball Cow2006-05-081-1/+2
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@4138 09075e82-0dd4-0310-85a5-a0d7c8717e4f
* merge with mpd/trunk up to r3925Eric Wong2006-03-161-7/+13
| | | git-svn-id: https://svn.musicpd.org/mpd/trunk@3926 09075e82-0dd4-0310-85a5-a0d7c8717e4f