From bf5befcd5e8cb97fbbd35bbf598358b8a8816b47 Mon Sep 17 00:00:00 2001 From: SyedSaifuddin045 <93501325+SyedSaifuddin045@users.noreply.github.com> Date: Wed, 8 Mar 2023 03:42:09 +0530 Subject: [PATCH] Remove obsolete mutex Reverts b780da4 and fixes #7371 --- src/gettext.cpp | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/gettext.cpp b/src/gettext.cpp index 812653f8e72..8e262f0f314 100644 --- a/src/gettext.cpp +++ b/src/gettext.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -44,8 +43,6 @@ namespace bl = boost::locale; namespace { - //This mutex avoids a random crash that sevu reported in bug #2013 as occurring when starting wesnoth from the commandline with --turns -1: - std::mutex& get_mutex() { static std::mutex* m = new std::mutex(); return *m; } class default_utf8_locale_name { @@ -425,12 +422,10 @@ namespace translation std::string dgettext(const char* domain, const char* msgid) { - std::scoped_lock lock(get_mutex()); return bl::dgettext(domain, msgid, get_manager().get_locale()); } std::string egettext(char const *msgid) { - std::scoped_lock lock(get_mutex()); return msgid[0] == '\0' ? msgid : bl::gettext(msgid, get_manager().get_locale()); } @@ -466,12 +461,8 @@ inline const char* is_unlocalized_string2(const std::string& str, const char* si std::string dsngettext (const char * domainname, const char *singular, const char *plural, int n) { - std::string msgval; - //Braces so that only the line that needs to be in the lock is in it: - { - std::scoped_lock lock(get_mutex()); - msgval = bl::dngettext(domainname, singular, plural, n, get_manager().get_locale()); - } + std::string msgval = bl::dngettext(domainname, singular, plural, n, get_manager().get_locale()); + auto original = is_unlocalized_string2(msgval, singular, plural); if (original) { const char* firsthat = std::strchr (original, '^'); @@ -486,7 +477,6 @@ std::string dsngettext (const char * domainname, const char *singular, const cha void bind_textdomain(const char* domain, const char* directory, const char* /*encoding*/) { LOG_G << "adding textdomain '" << domain << "' in directory '" << directory << "'"; - std::scoped_lock lock(get_mutex()); get_manager().add_messages_domain(domain); get_manager().add_messages_path(directory); get_manager().update_locale(); @@ -495,7 +485,6 @@ void bind_textdomain(const char* domain, const char* directory, const char* /*en void set_default_textdomain(const char* domain) { LOG_G << "set_default_textdomain: '" << domain << "'"; - std::scoped_lock lock(get_mutex()); get_manager().set_default_messages_domain(domain); } @@ -505,13 +494,11 @@ void set_language(const std::string& language, const std::vector* / // why should we need alternates? which languages we support should only be related // to which languages we ship with and not which the os supports LOG_G << "setting language to '" << language << "'"; - std::scoped_lock lock(get_mutex()); get_manager().set_language(language); } int compare(const std::string& s1, const std::string& s2) { - std::scoped_lock lock(get_mutex()); try { return std::use_facet>(get_manager().get_locale()).compare(s1.c_str(), s1.c_str() + s1.size(), s2.c_str(), s2.c_str() + s2.size()); @@ -534,7 +521,6 @@ int icompare(const std::string& s1, const std::string& s2) // https://github.com/wesnoth/wesnoth/issues/2094 return compare(ascii_to_lowercase(s1), ascii_to_lowercase(s2)); #else - std::scoped_lock lock(get_mutex()); try { #if BOOST_VERSION < 108100 @@ -567,7 +553,6 @@ int icompare(const std::string& s1, const std::string& s2) std::string strftime(const std::string& format, const std::tm* time) { std::basic_ostringstream dummy; - std::scoped_lock lock(get_mutex()); dummy.imbue(get_manager().get_locale()); // TODO: Calling imbue() with hard-coded locale appears to work with put_time in glibc, but not with get_locale()... // Revert to use of boost (from 1.14) instead of std::put_time() because the latter does not appear to handle locale properly in Linux dummy << bl::as::ftime(format) << mktime(const_cast(time)); @@ -577,7 +562,6 @@ std::string strftime(const std::string& format, const std::tm* time) bool ci_search(const std::string& s1, const std::string& s2) { - std::scoped_lock lock(get_mutex()); const std::locale& locale = get_manager().get_locale(); std::string ls1 = bl::to_lower(s1, locale); @@ -589,7 +573,6 @@ bool ci_search(const std::string& s1, const std::string& s2) const boost::locale::info& get_effective_locale_info() { - std::scoped_lock lock(get_mutex()); return std::use_facet(get_manager().get_locale()); } }