- char* actual = setlocale (LC_NUMERIC, NULL);
- std::locale current;
-
- if (current != old_cpp) {
- /* the C++ locale should always be "C", that's the default
- * at application start, and ardour never changes it to
- * anything but "C".
- *
- * if it's not: some plugin meddled with it.
- */
- assert (old_cpp == std::locale::classic ());
- std::locale::global (old_cpp);
+ char const * current_c_locale = setlocale (LC_NUMERIC, 0);
+ std::locale current_cpp_locale;
+
+ 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 ? %3",
+ old_cpp_locale.name(), current_cpp_locale.name(),
+ (std::use_facet<std::numpunct<char> >(std::locale()).decimal_point() == '.'))
+ << endmsg;
+
+ try {
+ /* this resets C & C++ locales */
+ std::locale::global (old_cpp_locale);
+ DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: restore C & C++ locale: '%1'\n", std::locale().name()));
+ } catch (...) {
+ /* see comments in the constructor regarding the
+ * exception.
+ *
+ * This should restore restore numeric handling back to
+ * the default (which may reflect user
+ * preferences). This probably can't fail, because
+ * old_c_locale was already in use during the
+ * constructor for this object.
+ *
+ * Still ... Apple ... locale support ... just sayin' ....
+ */
+ setlocale (LC_NUMERIC, old_c_locale);
+ 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()));
+ }
+