diff --git a/libs/pbd/debug.cc b/libs/pbd/debug.cc index e6d4abcee7..0940146aef 100644 --- a/libs/pbd/debug.cc +++ b/libs/pbd/debug.cc @@ -56,6 +56,7 @@ DebugBits PBD::DEBUG::Configuration = PBD::new_debug_bit ("configuration"); DebugBits PBD::DEBUG::UndoHistory = PBD::new_debug_bit ("undohistory"); DebugBits PBD::DEBUG::Timing = PBD::new_debug_bit ("timing"); DebugBits PBD::DEBUG::Threads = PBD::new_debug_bit ("threads"); +DebugBits PBD::DEBUG::Locale = PBD::new_debug_bit ("locale"); /* These are debug bits that are used by backends. Since these are loaded dynamically, after command-line parsing, defining them in code that is part of the backend diff --git a/libs/pbd/locale_guard.cc b/libs/pbd/locale_guard.cc index 6e95ea9dcd..b4225d3875 100644 --- a/libs/pbd/locale_guard.cc +++ b/libs/pbd/locale_guard.cc @@ -22,8 +22,10 @@ #include #include -#include "pbd/locale_guard.h" +#include "pbd/compose.h" +#include "pbd/debug.h" #include "pbd/error.h" +#include "pbd/locale_guard.h" using namespace PBD; @@ -39,17 +41,17 @@ LocaleGuard::LocaleGuard () { char* actual = setlocale (LC_NUMERIC, NULL); if (strcmp ("C", actual)) { + DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: change locale from '%1' to 'C'\n", actual)); /* purpose of LocaleGuard is to make sure we're using "C" for the numeric locale during its lifetime, so make it so. */ old_c = strdup (actual); - /* this changes both C++ and C locale (according to specs) */ + /* this changes both C++ and C locale */ std::locale::global (std::locale (std::locale::classic(), "C", std::locale::numeric)); - /* ..but maybe not.. */ - setlocale (LC_NUMERIC, "C"); } if (old_cpp != std::locale::classic ()) { PBD::error << "LocaleGuard: initial C++ locale is not 'C'. Expect non-portable session files.\n"; + DEBUG_TRACE (DEBUG::Locale, "LG: initial C++ locale is not 'C'. Expect non-portable session files.\n"); } } @@ -67,11 +69,14 @@ LocaleGuard::~LocaleGuard () */ if (old_cpp != std::locale::classic ()) { PBD::error << "LocaleGuard: someone (a plugin) changed the C++ locale, expect non-portable session files.\n"; + DEBUG_TRACE (DEBUG::Locale, "LG: someone (a plugin) changed the C++ locale, expect non-portable session files.\n"); } std::locale::global (old_cpp); + DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: restore C++ locale: '%1'\n", old_cpp.name ())); } if (old_c && strcmp (old_c, actual)) { setlocale (LC_NUMERIC, old_c); + DEBUG_TRACE (DEBUG::Locale, string_compose ("LG: restore C locale: '%1'\n", old_c)); } free (old_c); } diff --git a/libs/pbd/pbd/debug.h b/libs/pbd/pbd/debug.h index 3696e7a346..8db198e82e 100644 --- a/libs/pbd/pbd/debug.h +++ b/libs/pbd/pbd/debug.h @@ -58,6 +58,7 @@ namespace PBD { LIBPBD_API extern DebugBits UndoHistory; LIBPBD_API extern DebugBits Timing; LIBPBD_API extern DebugBits Threads; + LIBPBD_API extern DebugBits Locale; /* See notes in ../debug.cc on why these are defined here */