From f43e674bc0e47b7360c2a1ee335f7536e1638ae1 Mon Sep 17 00:00:00 2001 From: Michael Welter Date: Sun, 11 Sep 2022 20:56:18 +0200 Subject: Fix initialization order issues --- migration/migration.cpp | 31 +++++++++++++++++++++---------- migration/migration.hpp | 3 +++ 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'migration') diff --git a/migration/migration.cpp b/migration/migration.cpp index 4ddb2c8c..f4b1739b 100644 --- a/migration/migration.cpp +++ b/migration/migration.cpp @@ -26,14 +26,25 @@ using namespace options::globals; namespace migrations::detail { -static std::vector migration_list; -static std::vector migration_thunks; + +std::vector& migrator::migration_list() +{ + static std::vector v; + return v; +} + +std::vector& migrator::migration_thunks() +{ + static std::vector v; + return v; +} + void migrator::register_migration(mptr const& m) { const QString date = m->unique_date(); - for (mptr const& m2 : migration_list) + for (mptr const& m2 : migration_list()) if (m2->unique_date() == date) std::abort(); @@ -65,35 +76,35 @@ void migrator::register_migration(mptr const& m) if (day_ < 1 || day_ > 31) abort(); - migration_list.push_back(m); + migration_list().push_back(m); } void migrator::eval_thunks() { - for (auto& fun : migration_thunks) + for (auto& fun : migration_thunks()) { mptr m = fun(); register_migration(m); } - if (!migration_thunks.empty()) + if (!migration_thunks().empty()) sort_migrations(); - migration_thunks.clear(); + migration_thunks().clear(); } void migrator::add_migration_thunk(mfun& thunk) { - migration_thunks.push_back(thunk); + migration_thunks().push_back(thunk); } std::vector& migrator::migrations() { eval_thunks(); - return migration_list; + return migration_list(); } void migrator::sort_migrations() { - std::sort(migration_list.begin(), migration_list.end(), + std::sort(migration_list().begin(), migration_list().end(), [](const mptr x, const mptr y) { return x->unique_date() < y->unique_date(); }); diff --git a/migration/migration.hpp b/migration/migration.hpp index a3035247..7fc18c97 100644 --- a/migration/migration.hpp +++ b/migration/migration.hpp @@ -43,6 +43,9 @@ namespace detail { static void set_last_migration_time(const QString& val); static int to_int(const QString& str, bool& ok); + + static std::vector& migration_list(); + static std::vector& migration_thunks(); }; template -- cgit v1.2.3