mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
Fix static initialisation order fiasco issue for Version variables
Fixes a crash that could occur if the static constructor function for the MainSettings.cpp TU happened to run before the variables in Common/Version.cpp are initialised. (This is known as the static initialisation order fiasco.) By using wrapper functions, those variables are now guaranteed to be constructed on first use.
This commit is contained in:
@ -149,8 +149,8 @@ private:
|
||||
{
|
||||
// Null-terminator is intentionally not copied.
|
||||
std::memcpy(&id, "DCAC", sizeof(u32));
|
||||
std::memcpy(ver, Common::scm_rev_git_str.c_str(),
|
||||
std::min(Common::scm_rev_git_str.size(), sizeof(ver)));
|
||||
std::memcpy(ver, Common::GetScmRevGitStr().c_str(),
|
||||
std::min(Common::GetScmRevGitStr().size(), sizeof(ver)));
|
||||
}
|
||||
|
||||
u32 id = 0;
|
||||
|
@ -17,28 +17,61 @@ namespace Common
|
||||
#define BUILD_TYPE_STR ""
|
||||
#endif
|
||||
|
||||
const std::string scm_rev_str = "Dolphin "
|
||||
const std::string& GetScmRevStr()
|
||||
{
|
||||
static const std::string scm_rev_str = "Dolphin "
|
||||
#if !SCM_IS_MASTER
|
||||
"[" SCM_BRANCH_STR "] "
|
||||
"[" SCM_BRANCH_STR "] "
|
||||
#endif
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
BUILD_TYPE_STR SCM_DESC_STR "-ICC";
|
||||
BUILD_TYPE_STR SCM_DESC_STR "-ICC";
|
||||
#else
|
||||
BUILD_TYPE_STR SCM_DESC_STR;
|
||||
BUILD_TYPE_STR SCM_DESC_STR;
|
||||
#endif
|
||||
return scm_rev_str;
|
||||
}
|
||||
|
||||
const std::string scm_rev_git_str = SCM_REV_STR;
|
||||
const std::string scm_desc_str = SCM_DESC_STR;
|
||||
const std::string scm_branch_str = SCM_BRANCH_STR;
|
||||
const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
|
||||
const std::string scm_update_track_str = SCM_UPDATE_TRACK_STR;
|
||||
const std::string& GetScmRevGitStr()
|
||||
{
|
||||
static const std::string scm_rev_git_str = SCM_REV_STR;
|
||||
return scm_rev_git_str;
|
||||
}
|
||||
|
||||
const std::string& GetScmDescStr()
|
||||
{
|
||||
static const std::string scm_desc_str = SCM_DESC_STR;
|
||||
return scm_desc_str;
|
||||
}
|
||||
|
||||
const std::string& GetScmBranchStr()
|
||||
{
|
||||
static const std::string scm_branch_str = SCM_BRANCH_STR;
|
||||
return scm_branch_str;
|
||||
}
|
||||
|
||||
const std::string& GetScmDistributorStr()
|
||||
{
|
||||
static const std::string scm_distributor_str = SCM_DISTRIBUTOR_STR;
|
||||
return scm_distributor_str;
|
||||
}
|
||||
|
||||
const std::string& GetScmUpdateTrackStr()
|
||||
{
|
||||
static const std::string scm_update_track_str = SCM_UPDATE_TRACK_STR;
|
||||
return scm_update_track_str;
|
||||
}
|
||||
|
||||
const std::string& GetNetplayDolphinVer()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const std::string netplay_dolphin_ver = SCM_DESC_STR " Win";
|
||||
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Win";
|
||||
#elif __APPLE__
|
||||
const std::string netplay_dolphin_ver = SCM_DESC_STR " Mac";
|
||||
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Mac";
|
||||
#else
|
||||
const std::string netplay_dolphin_ver = SCM_DESC_STR " Lin";
|
||||
static const std::string netplay_dolphin_ver = SCM_DESC_STR " Lin";
|
||||
#endif
|
||||
return netplay_dolphin_ver;
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
@ -7,12 +7,11 @@
|
||||
|
||||
namespace Common
|
||||
{
|
||||
// Git version number
|
||||
extern const std::string scm_desc_str;
|
||||
extern const std::string scm_branch_str;
|
||||
extern const std::string scm_rev_str;
|
||||
extern const std::string scm_rev_git_str;
|
||||
extern const std::string scm_distributor_str;
|
||||
extern const std::string scm_update_track_str;
|
||||
extern const std::string netplay_dolphin_ver;
|
||||
const std::string& GetScmDescStr();
|
||||
const std::string& GetScmBranchStr();
|
||||
const std::string& GetScmRevStr();
|
||||
const std::string& GetScmRevGitStr();
|
||||
const std::string& GetScmDistributorStr();
|
||||
const std::string& GetScmUpdateTrackStr();
|
||||
const std::string& GetNetplayDolphinVer();
|
||||
} // namespace Common
|
||||
|
Reference in New Issue
Block a user