From 9f678cc47abfc9bbc18a9a9cefc47502e1974c59 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 30 Jan 2020 22:03:36 +0100 Subject: [PATCH] Fix code relying on initialization order Allows Debug - LLVM to boot --- Utilities/Log.cpp | 2 +- rpcs3/main.cpp | 2 +- rpcs3/rpcs3_version.cpp | 6 +++++- rpcs3/rpcs3_version.h | 3 +-- rpcs3/rpcs3qt/about_dialog.cpp | 2 +- rpcs3/rpcs3qt/gs_frame.cpp | 4 ++-- rpcs3/rpcs3qt/main_window.cpp | 2 +- rpcs3/util/fixed_typemap.hpp | 8 ++++---- rpcs3/util/typeindices.hpp | 13 +++++++++---- 9 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 2e8c239b00..59126b3761 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -629,7 +629,7 @@ logs::file_listener::file_listener(const std::string& name) ver.m.ch = nullptr; ver.m.sev = level::always; ver.stamp = 0; - ver.text = fmt::format("RPCS3 v%s | %s%s\n%s", rpcs3::version.to_string(), rpcs3::get_branch(), firmware_string, utils::get_system_info()); + ver.text = fmt::format("RPCS3 v%s | %s%s\n%s", rpcs3::get_version().to_string(), rpcs3::get_branch(), firmware_string, utils::get_system_info()); file_writer::log(logs::level::always, ver.text.data(), ver.text.size()); file_writer::log(logs::level::always, "\n", 1); diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 692d670aa1..cac0e65199 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -221,7 +221,7 @@ int main(int argc, char** argv) const bool use_cli_style = find_arg(arg_style, argc, argv) || find_arg(arg_stylesheet, argc, argv); QScopedPointer app(createApplication(argc, argv)); - app->setApplicationVersion(qstr(rpcs3::version.to_string())); + app->setApplicationVersion(qstr(rpcs3::get_version().to_string())); app->setApplicationName("RPCS3"); // Command line args diff --git a/rpcs3/rpcs3_version.cpp b/rpcs3/rpcs3_version.cpp index d5dd1c7d00..d24b00e274 100644 --- a/rpcs3/rpcs3_version.cpp +++ b/rpcs3/rpcs3_version.cpp @@ -21,5 +21,9 @@ namespace rpcs3 // TODO: Make this accessible from cmake and keep in sync with MACOSX_BUNDLE_BUNDLE_VERSION. // Currently accessible by Windows and Linux build scripts, see implementations when doing MACOSX - const extern utils::version version{ 0, 0, 8, utils::version_type::alpha, 1, RPCS3_GIT_VERSION }; + const utils::version& get_version() + { + static constexpr utils::version version{ 0, 0, 8, utils::version_type::alpha, 1, RPCS3_GIT_VERSION }; + return version; + } } diff --git a/rpcs3/rpcs3_version.h b/rpcs3/rpcs3_version.h index a95f145d5b..a1ef0e1dc4 100644 --- a/rpcs3/rpcs3_version.h +++ b/rpcs3/rpcs3_version.h @@ -7,6 +7,5 @@ namespace rpcs3 { std::string get_branch(); std::pair get_commit_and_hash(); - - extern const utils::version version; + const utils::version& get_version(); } diff --git a/rpcs3/rpcs3qt/about_dialog.cpp b/rpcs3/rpcs3qt/about_dialog.cpp index a92851eae5..002baf7c60 100644 --- a/rpcs3/rpcs3qt/about_dialog.cpp +++ b/rpcs3/rpcs3qt/about_dialog.cpp @@ -14,7 +14,7 @@ about_dialog::about_dialog(QWidget* parent) : QDialog(parent), ui(new Ui::about_ ui->close->setDefault(true); - ui->version->setText(tr("RPCS3 Version: %1").arg(qstr(rpcs3::version.to_string()))); + ui->version->setText(tr("RPCS3 Version: %1").arg(qstr(rpcs3::get_version().to_string()))); // Events connect(ui->gitHub, &QPushButton::clicked, [] { QDesktopServices::openUrl(QUrl("https://www.github.com/RPCS3")); }); diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index e64b3cfd1b..0be3d50118 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -39,13 +39,13 @@ gs_frame::gs_frame(const QString& title, const QRect& geometry, const QIcon& app m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool(); // Get version by substringing VersionNumber-buildnumber-commithash to get just the part before the dash - std::string version = rpcs3::version.to_string(); + std::string version = rpcs3::get_version().to_string(); version = version.substr(0 , version.find_last_of('-')); // Add branch and commit hash to version on frame unless it's master. if ((rpcs3::get_branch().compare("master") != 0) && (rpcs3::get_branch().compare("HEAD") != 0)) { - version = version + "-" + rpcs3::version.to_string().substr((rpcs3::version.to_string().find_last_of('-') + 1), 8) + "-" + rpcs3::get_branch(); + version = version + "-" + rpcs3::get_version().to_string().substr((rpcs3::get_version().to_string().find_last_of('-') + 1), 8) + "-" + rpcs3::get_branch(); } m_windowTitle += qstr(" | " + version); diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 9378551766..2651ac8783 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -94,7 +94,7 @@ void main_window::Init() CreateConnects(); setMinimumSize(350, minimumSizeHint().height()); // seems fine on win 10 - setWindowTitle(QString::fromStdString("RPCS3 " + rpcs3::version.to_string())); + setWindowTitle(QString::fromStdString("RPCS3 " + rpcs3::get_version().to_string())); Q_EMIT RequestGlobalStylesheetChange(guiSettings->GetCurrentStylesheetPath()); ConfigureGuiFromSettings(true); diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index e84eb20587..c793f6981c 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -79,7 +79,7 @@ namespace stx // Destroy all objects and keep them in uninitialized state, must be called first void reset() noexcept { - const auto total_count = stx::typelist_v.count(); + const auto total_count = stx::typelist().count(); if (!m_list) { @@ -96,13 +96,13 @@ namespace stx void(*destroy)(void*& ptr) noexcept; }; - auto all_data = std::make_unique(stx::typelist_v.count()); + auto all_data = std::make_unique(stx::typelist().count()); // Actual number of created objects unsigned _max = 0; // Create destroy list - for (auto& type : stx::typelist_v) + for (auto& type : stx::typelist()) { if (m_order[type.index()] == 0) { @@ -136,7 +136,7 @@ namespace stx // Default initialize all objects if possible and not already initialized void init() noexcept { - for (auto& type : stx::typelist_v) + for (auto& type : stx::typelist()) { type.create(m_list[type.index()]); diff --git a/rpcs3/util/typeindices.hpp b/rpcs3/util/typeindices.hpp index 1e2443d306..403f449d13 100644 --- a/rpcs3/util/typeindices.hpp +++ b/rpcs3/util/typeindices.hpp @@ -112,16 +112,21 @@ namespace stx // Global typecounter instance template - inline type_counter typelist_v{}; + auto& typelist() + { + static type_counter typelist_v; + return typelist_v; + } template type_info::type_info(Info info, decltype(sizeof(int))) noexcept : Info(info) - , type(typelist_v.count()) + , type(typelist().count()) { // Update linked list - typelist_v.next->next = this; - typelist_v.next = this; + auto& tl = typelist(); + tl.next->next = this; + tl.next = this; } // Type index accessor