Skip to content

Instantly share code, notes, and snippets.

@dexX7
Last active August 29, 2015 14:20
Show Gist options
  • Save dexX7/7394a947b29c7d84c710 to your computer and use it in GitHub Desktop.
Save dexX7/7394a947b29c7d84c710 to your computer and use it in GitHub Desktop.
boost::filesystem::path workarounds
# Using std::locale::classic() over std::locale("C") may be the preferable
# default, given the following properties.
#
# According to http://en.cppreference.com/w/cpp/locale/locale/classic:
#
# Some of the standard-required facets, such as the UTF-8/UTF-32 conversion
# facet std::codecvt<char32_t, char, std::mbstate_t>, have no equivalents in
# the "C" locale, but they are nevertheless present in the locale returned
# by std::locale::classic(), as in any other locale constructed in a C++
# program.
diff --git a/src/util.cpp b/src/util.cpp
index 4fea18b..1053903 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -713,7 +713,7 @@ void RenameThread(const char* name)
void SetupEnvironment()
{
- std::locale loc("C");
+ std::locale loc = std::locale::classic();
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
# boost::filesystem::path::imbue() returns the previously used locale, which
# should be the right one, if called in a pristine environment.
# This is probably the preferable choice, because the goal is not to set the
# locale at all, but to prevent the deinitialization issue.
diff --git a/src/util.cpp b/src/util.cpp
index 4fea18b..68fb326 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -713,18 +713,20 @@ void RenameThread(const char* name)
void SetupEnvironment()
{
- std::locale loc("C");
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
try {
- loc = std::locale(""); // Raises a runtime error if current locale is invalid
+ std::locale(""); // Raises a runtime error if current locale is invalid
} catch (const std::runtime_error&) {
setenv("LC_ALL", "C", 1);
}
#endif
// The path locale is lazy initialized and to avoid deinitialization errors
// in multithreading environments, it is set explicitly by the main thread.
+ // A dummy locale is used to extract the internal default locale, used by
+ // boost::filesystem::path, which is then used to explicitly imbue the path.
+ std::locale loc = boost::filesystem::path::imbue(std::locale::classic());
boost::filesystem::path::imbue(loc);
}
Test method B:
1. bitcoin-qt.exe -regtest -keypool=3 -choosedatadir
2. Use [path to test] as custom data directory
3. Continue, then shutdown the client
4. No exception or error is expected
Results on Windows 8.1 Pro N x64, German localization:
E:\LocaleTests\юзза
bitcoin-0.9.3: Fehler: Angegebenes Datenverzeichnis "E:\LocaleTests\????" existiert nicht.
bitcoin-0.10.0: Error: Specified data directory "E:\LocaleTests\????" does not exist.
bitcoin-0.10.1: APPCRASH / Runtime Error
dummy-workaround: Error: Specified data directory "E:\LocaleTests\????" does not exist.
classic-workaround: APPCRASH / Runtime Error
csimple-theuni: APPCRASH / Runtime Error
E:\LocaleTests\œ
bitcoin-0.9.3: OK
bitcoin-0.10.1: APPCRASH / Runtime Error
dummy-workaround: OK
classic-workaround: APPCRASH / Runtime Error
csimple-theuni: OK
E:\LocaleTests\™
bitcoin-0.9.3: OK
bitcoin-0.10.1: APPCRASH / Runtime Error
dummy-workaround: OK
classic-workaround: APPCRASH / Runtime Error
csimple-theuni: OK
E:\LocaleTests\€@ä®
bitcoin-0.9.3: OK
bitcoin-0.10.1: APPCRASH / Runtime Error
dummy-workaround: OK
classic-workaround: APPCRASH / Runtime Error
csimple-theuni: OK
E:\LocaleTests\ÐÑ©÷
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\©
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\÷
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\öää`
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\#&%@
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
Test method A:
1. Create [path to test]
2. bitcoind.exe -regtest -keypool=3 -rpcuser=user -rpcpassword=pw -datadir=[path to test]
3. bitcoin-cli.exe -regtest -rpcuser=user -rpcpassword=pw getinfo
4. bitcoin-cli.exe -regtest -rpcuser=user -rpcpassword=pw stop
5. No exception or error is expected
Results of Windows 8.1 Pro N x64, German localization:
E:\LocaleTests\юзза
bitcoin-0.9.3: Error: Specified data directory "E:\LocaleTests\????" does not exist.
bitcoin-0.10.0: Error: Specified data directory "E:\LocaleTests\????" does not exist.
bitcoin-0.10.1: Error: Specified data directory "E:\LocaleTests\????" does not exist.
dummy-workaround: Error: Specified data directory "E:\LocaleTests\????" does not exist.
classic-workaround: Error: Specified data directory "E:\LocaleTests\????" does not exist.
csimple-theuni: Error: Specified data directory "E:\LocaleTests\????" does not exist.
E:\LocaleTests\œ
bitcoin-0.9.3: OK
bitcoin-0.10.1: Error: Specified data directory "E:\LocaleTests\£" does not exist.
dummy-workaround: OK
classic-workaround: Error: Specified data directory "E:\LocaleTests\£" does not exist.
csimple-theuni: OK
E:\LocaleTests\™
bitcoin-0.9.3: OK
bitcoin-0.10.1: Error: Specified data directory "E:\LocaleTests\Ö" does not exist.
dummy-workaround: OK
classic-workaround: Error: Specified data directory "E:\LocaleTests\Ö" does not exist.
csimple-theuni: OK
E:\LocaleTests\€@ä®
bitcoin-0.9.3: OK
bitcoin-0.10.1: Error: Specified data directory "E:\LocaleTests\Ç@õ«" does not exist.
dummy-workaround: OK
classic-workaround: Error: Specified data directory "E:\LocaleTests\Ç@õ«" does not exist.
csimple-theuni: OK
E:\LocaleTests\ÐÑ©÷
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\©
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\÷
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\öää`
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
E:\LocaleTests\#&%@
bitcoin-0.9.3: OK
bitcoin-0.10.1: OK
dummy-workaround: OK
classic-workaround: OK
csimple-theuni: OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment