From ebc006ab529169d3d067231863ab7fc52fd9c49a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Jul 2018 16:46:01 +0200 Subject: [PATCH] db/simple: wrap LightSong in Manual<> Prepare to make LightSong non-assignable. --- src/db/plugins/simple/SimpleDatabasePlugin.cxx | 18 ++++++++++-------- src/db/plugins/simple/SimpleDatabasePlugin.hxx | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 772b4d826..6ea2bf9bd 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -237,30 +237,32 @@ SimpleDatabase::GetSong(const char *uri) const throw DatabaseError(DatabaseErrorCode::NOT_FOUND, "No such song"); - light_song = song->Export(); + light_song.Construct(song->Export()); #ifndef NDEBUG ++borrowed_song_count; #endif - return &light_song; + return &light_song.Get(); } void SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const { assert(song != nullptr); - assert(song == &light_song || song == prefixed_light_song); - - delete prefixed_light_song; - prefixed_light_song = nullptr; + assert(song == &light_song.Get() || song == prefixed_light_song); + if (prefixed_light_song != nullptr) { + delete prefixed_light_song; + prefixed_light_song = nullptr; + } else { #ifndef NDEBUG - if (song == &light_song) { assert(borrowed_song_count > 0); --borrowed_song_count; - } #endif + + light_song.Destruct(); + } } void diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.hxx b/src/db/plugins/simple/SimpleDatabasePlugin.hxx index c18b580eb..4d167eabf 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.hxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.hxx @@ -24,6 +24,7 @@ #include "db/Interface.hxx" #include "fs/AllocatedPath.hxx" #include "db/LightSong.hxx" +#include "util/Manual.hxx" #include "Compiler.h" #include @@ -61,7 +62,7 @@ class SimpleDatabase : public Database { /** * A buffer for GetSong(). */ - mutable LightSong light_song; + mutable Manual light_song; #ifndef NDEBUG mutable unsigned borrowed_song_count;