From d184231169687025200e189afe898d955fa095cb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Feb 2017 09:58:20 +0100 Subject: [PATCH] db/DatabaseSong: DatabaseDetachSong(uri) returns instance, not pointer --- src/SongLoader.cxx | 2 +- src/db/DatabaseSong.cxx | 4 ++-- src/db/DatabaseSong.hxx | 8 ++++---- test/test_translate_song.cxx | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SongLoader.cxx b/src/SongLoader.cxx index b01060610..04940cd53 100644 --- a/src/SongLoader.cxx +++ b/src/SongLoader.cxx @@ -41,7 +41,7 @@ SongLoader::LoadFromDatabase(const char *uri) const { #ifdef ENABLE_DATABASE if (db != nullptr) - return DatabaseDetachSong(*db, *storage, uri); + return new DetachedSong(DatabaseDetachSong(*db, *storage, uri)); #else (void)uri; #endif diff --git a/src/db/DatabaseSong.cxx b/src/db/DatabaseSong.cxx index aadc0bee4..ca39ffa49 100644 --- a/src/db/DatabaseSong.cxx +++ b/src/db/DatabaseSong.cxx @@ -41,7 +41,7 @@ DatabaseDetachSong(const Storage &storage, const LightSong &song) return detached; } -DetachedSong * +DetachedSong DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri) { const LightSong *tmp = db.GetSong(uri); @@ -49,5 +49,5 @@ DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri) AtScopeExit(&db, tmp) { db.ReturnSong(tmp); }; - return new DetachedSong(DatabaseDetachSong(storage, *tmp)); + return DatabaseDetachSong(storage, *tmp); } diff --git a/src/db/DatabaseSong.hxx b/src/db/DatabaseSong.hxx index bafc1df89..b47c4e2a2 100644 --- a/src/db/DatabaseSong.hxx +++ b/src/db/DatabaseSong.hxx @@ -37,12 +37,12 @@ DatabaseDetachSong(const Storage &storage, const LightSong &song); /** * Look up a song in the database and convert it to a #DetachedSong - * instance. The caller is responsible for freeing it. + * instance. * - * @return nullptr on error + * Throws std::runtime_error on error. */ -gcc_malloc gcc_nonnull_all -DetachedSong * +gcc_pure +DetachedSong DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri); diff --git a/test/test_translate_song.cxx b/test/test_translate_song.cxx index bbe4d798a..0c4be2f37 100644 --- a/test/test_translate_song.cxx +++ b/test/test_translate_song.cxx @@ -107,15 +107,15 @@ MakeTag2c() static const char *uri1 = "/foo/bar.ogg"; static const char *uri2 = "foo/bar.ogg"; -DetachedSong * +DetachedSong DatabaseDetachSong(gcc_unused const Database &db, gcc_unused const Storage &_storage, const char *uri) { if (strcmp(uri, uri2) == 0) - return new DetachedSong(uri, MakeTag2a()); + return DetachedSong(uri, MakeTag2a()); - return nullptr; + throw std::runtime_error("No such song"); } bool