17 #ifndef DISTRHO_SCOPED_SAFE_LOCALE_HPP_INCLUDED
18 #define DISTRHO_SCOPED_SAFE_LOCALE_HPP_INCLUDED
20 #include "../DistrhoUtils.hpp"
24 #if ! (defined(DISTRHO_OS_HAIKU) || defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS))
25 # define DISTRHO_USE_NEWLOCALE
28 #if defined(DISTRHO_OS_WINDOWS) && __MINGW64_VERSION_MAJOR >= 5
29 # define DISTRHO_USE_CONFIGTHREADLOCALE
72 #ifdef DISTRHO_USE_NEWLOCALE
73 locale_t newloc, oldloc;
75 # ifdef DISTRHO_USE_CONFIGTHREADLOCALE
76 const int oldthreadloc;
82 DISTRHO_PREVENT_HEAP_ALLOCATION
88 #ifdef DISTRHO_USE_NEWLOCALE
89 static constexpr
const locale_t kNullLocale = (locale_t)
nullptr;
92 inline ScopedSafeLocale::ScopedSafeLocale() noexcept
93 #ifdef DISTRHO_USE_NEWLOCALE
94 : newloc(::newlocale(LC_NUMERIC_MASK,
"C", kNullLocale)),
95 oldloc(newloc != kNullLocale ? ::uselocale(newloc) : kNullLocale) {}
97 # ifdef DISTRHO_USE_CONFIGTHREADLOCALE
98 : oldthreadloc(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)),
102 oldloc(strdup(::setlocale(LC_NUMERIC,
nullptr)))
104 ::setlocale(LC_NUMERIC,
"C");
108 inline ScopedSafeLocale::~ScopedSafeLocale() noexcept
110 #ifdef DISTRHO_USE_NEWLOCALE
111 if (oldloc != kNullLocale)
113 if (newloc != kNullLocale)
114 ::freelocale(newloc);
116 if (oldloc !=
nullptr)
118 ::setlocale(LC_NUMERIC, oldloc);
122 # ifdef DISTRHO_USE_CONFIGTHREADLOCALE
123 if (oldthreadloc != -1)
124 _configthreadlocale(oldthreadloc);
131 #undef DISTRHO_USE_CONFIGTHREADLOCALE
132 #undef DISTRHO_USE_NEWLOCALE
Definition: ScopedSafeLocale.hpp:57
#define END_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:949
#define START_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:943