summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-04-20 22:11:50 +0200
committerRobin Gareus <robin@gareus.org>2017-04-20 22:12:33 +0200
commitffff31b832ca05cd80a1b21cc8226ccf134bb787 (patch)
tree5104f959b67f27a8d4b6c147854d7c3685f747ed /libs/pbd
parentd4f91010c37a3ce185bb3c8bcf6453503eccd2b2 (diff)
Relax LocaleGuards
Arodur itself on longer depends on C/C++ locale for saving/loading sessions. However, the Localeguard is kept for 3rd party plugins: Reset the C locale to "C" to enforce consisten numerics and portable sessions as well as verify that no plugin changes the C++ locale.
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/locale_guard.cc38
1 files changed, 6 insertions, 32 deletions
diff --git a/libs/pbd/locale_guard.cc b/libs/pbd/locale_guard.cc
index 93ff11e293..dc2657c239 100644
--- a/libs/pbd/locale_guard.cc
+++ b/libs/pbd/locale_guard.cc
@@ -55,36 +55,10 @@ LocaleGuard::LocaleGuard ()
char const * const current_c_locale = setlocale (LC_NUMERIC, 0);
if (strcmp ("C", current_c_locale) != 0) {
-
old_c_locale = strdup (current_c_locale);
-
- try {
- /* set the C++ global/default locale to whatever we are using
- * now, but with "C" numeric handling.
- *
- * this also sets the C locale, so no additional call to setlocale() is required.
- */
-
- std::locale::global (std::locale (old_cpp_locale, "C", std::locale::numeric));
- pre_cpp_locale = std::locale();
- DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: change C & C++ locale from '%1' => %2\n", old_cpp_locale.name(), pre_cpp_locale.name()));
-
- } catch (...) {
- /* Apple in particular have historically done a
- * terrible job supporting setlocale and even more so
- * with the C++ API. Using any locale other than "C" or
- * "POSIX" will fail, and in the case of the C++ API,
- * will throw an exception. In that case, just try to
- * use setlocale() to reset *only* the numeric aspect
- * of the current locale settings back to "C", which is
- * likely to work everywhere.
- */
-
- setlocale (LC_NUMERIC, "C");
- pre_cpp_locale = std::locale();
- DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: C++ locale API failed, change just C locale from '%1' => 'C' (C++ locale is %2)\n", old_c_locale, pre_cpp_locale.name()));
- }
-
+ setlocale (LC_NUMERIC, "C");
+ pre_cpp_locale = std::locale();
+ DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: change C locale from '%1' => 'C' (C++ locale is %2)\n", old_c_locale, pre_cpp_locale.name()));
}
}
@@ -95,7 +69,7 @@ LocaleGuard::~LocaleGuard ()
if (current_cpp_locale != pre_cpp_locale) {
- PBD::warning << string_compose ("LocaleGuard: someone (a plugin) changed the C++ locale from\n\t%1\nto\n\t%2\n, expect non-portable session files. Decimal OK ? %2",
+ PBD::warning << string_compose ("LocaleGuard: someone (a plugin) changed the C++ locale from\n\t%1\nto\n\t%2\n, expect non-portable session files. Decimal OK ? %3",
old_cpp_locale.name(), current_cpp_locale.name(),
(std::use_facet<std::numpunct<char> >(std::locale()).decimal_point() == '.'))
<< endmsg;
@@ -120,8 +94,8 @@ LocaleGuard::~LocaleGuard ()
DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: C++ locale API failed, restore C locale from %1 to\n'%2'\n(C++ is '%3')\n", current_c_locale, old_c_locale, std::locale().name()));
}
- } else if (old_c_locale && (strcmp (current_c_locale, old_c_locale) != 0)) {
-
+ }
+ if (old_c_locale && (strcmp (current_c_locale, old_c_locale) != 0)) {
/* reset only the C locale */
setlocale (LC_NUMERIC, old_c_locale);
DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: restore C locale from %1 to\n'%2'\n(C++ is '%3')\n", current_c_locale, old_c_locale, std::locale().name()));