13
0

locale debugging

This commit is contained in:
Robin Gareus 2016-05-07 12:15:12 +02:00
parent 3d7cbe9d94
commit f445ba8bdc
3 changed files with 11 additions and 4 deletions

View File

@ -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

View File

@ -22,8 +22,10 @@
#include <assert.h>
#include <locale.h>
#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);
}

View File

@ -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 */