decoder/sidplay: automatic memory management inside struct SidplayGlobal
This commit is contained in:
parent
bed8a0e040
commit
a7976cd0f2
@ -56,6 +56,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -69,7 +70,7 @@
|
|||||||
static constexpr Domain sidplay_domain("sidplay");
|
static constexpr Domain sidplay_domain("sidplay");
|
||||||
|
|
||||||
struct SidplayGlobal {
|
struct SidplayGlobal {
|
||||||
SidDatabase *songlength_database;
|
std::unique_ptr<SidDatabase> songlength_database;
|
||||||
|
|
||||||
bool all_files_are_containers;
|
bool all_files_are_containers;
|
||||||
unsigned default_songlength;
|
unsigned default_songlength;
|
||||||
@ -78,19 +79,10 @@ struct SidplayGlobal {
|
|||||||
bool filter_setting;
|
bool filter_setting;
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
uint8_t *kernal = nullptr, *basic = nullptr;
|
std::unique_ptr<uint8_t[]> kernal, basic;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
explicit SidplayGlobal(const ConfigBlock &block);
|
explicit SidplayGlobal(const ConfigBlock &block);
|
||||||
|
|
||||||
~SidplayGlobal() noexcept {
|
|
||||||
delete songlength_database;
|
|
||||||
|
|
||||||
#ifdef HAVE_SIDPLAYFP
|
|
||||||
delete[] basic;
|
|
||||||
delete[] kernal;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static SidplayGlobal *sidplay_global;
|
static SidplayGlobal *sidplay_global;
|
||||||
@ -109,10 +101,10 @@ static void loadRom(const Path rom_path, uint8_t *dump)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static SidDatabase *
|
static std::unique_ptr<SidDatabase>
|
||||||
sidplay_load_songlength_db(const Path path) noexcept
|
sidplay_load_songlength_db(const Path path) noexcept
|
||||||
{
|
{
|
||||||
SidDatabase *db = new SidDatabase();
|
auto db = std::make_unique<SidDatabase>();
|
||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
bool error = !db->open(path.c_str());
|
bool error = !db->open(path.c_str());
|
||||||
#else
|
#else
|
||||||
@ -122,7 +114,6 @@ sidplay_load_songlength_db(const Path path) noexcept
|
|||||||
FormatError(sidplay_domain,
|
FormatError(sidplay_domain,
|
||||||
"unable to read songlengths file %s: %s",
|
"unable to read songlengths file %s: %s",
|
||||||
path.c_str(), db->error());
|
path.c_str(), db->error());
|
||||||
delete db;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,16 +142,16 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
|
|||||||
const auto kernal_path = block.GetPath("kernal");
|
const auto kernal_path = block.GetPath("kernal");
|
||||||
if (!kernal_path.IsNull())
|
if (!kernal_path.IsNull())
|
||||||
{
|
{
|
||||||
kernal = new uint8_t[rom_size];
|
kernal.reset(new uint8_t[rom_size]);
|
||||||
loadRom(kernal_path, kernal);
|
loadRom(kernal_path, kernal.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read basic rom dump file */
|
/* read basic rom dump file */
|
||||||
const auto basic_path = block.GetPath("basic");
|
const auto basic_path = block.GetPath("basic");
|
||||||
if (!basic_path.IsNull())
|
if (!basic_path.IsNull())
|
||||||
{
|
{
|
||||||
basic = new uint8_t[rom_size];
|
basic.reset(new uint8_t[rom_size]);
|
||||||
loadRom(basic_path, basic);
|
loadRom(basic_path, basic.get());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -272,7 +263,9 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
#ifdef HAVE_SIDPLAYFP
|
#ifdef HAVE_SIDPLAYFP
|
||||||
sidplayfp player;
|
sidplayfp player;
|
||||||
|
|
||||||
player.setRoms(sidplay_global->kernal, sidplay_global->basic, nullptr);
|
player.setRoms(sidplay_global->kernal.get(),
|
||||||
|
sidplay_global->basic.get(),
|
||||||
|
nullptr);
|
||||||
#else
|
#else
|
||||||
sidplay2 player;
|
sidplay2 player;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user