From 17876410b5c93b84d2ab0a0c168739ff65e1d7a9 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 6 May 2020 00:10:10 +1000 Subject: [PATCH] rewrote OCIO C locale patch Previous build was getting optimized out. This one shouldn't. --- app/render/colormanager.cpp | 16 +++++++++++-- app/render/colormanager.h | 45 +++++------------------------------ app/render/colorprocessor.cpp | 2 ++ 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/app/render/colormanager.cpp b/app/render/colormanager.cpp index 0ecd73f83..5b2cc1838 100644 --- a/app/render/colormanager.cpp +++ b/app/render/colormanager.cpp @@ -51,7 +51,7 @@ OCIO::ConstConfigRcPtr ColorManager::GetConfig() const OCIO::ConstConfigRcPtr ColorManager::CreateConfigFromFile(const QString &filename) { - SetCLocale(); + OCIO_SET_C_LOCALE_FOR_SCOPE; return OCIO::Config::CreateFromFile(filename.toUtf8()); } @@ -68,10 +68,11 @@ OCIO::ConstConfigRcPtr ColorManager::GetDefaultConfig() void ColorManager::SetUpDefaultConfig() { + OCIO_SET_C_LOCALE_FOR_SCOPE; + if (!qgetenv("OCIO").isEmpty()) { // Attempt to set config from "OCIO" environment variable try { - SetCLocale(); default_config_ = OCIO::Config::CreateFromEnv(); return; @@ -381,4 +382,15 @@ void ColorManager::AssociateAlphaInternal(ColorManager::AlphaAction action, T *d } } +ColorManager::SetLocale::SetLocale(const char* new_locale) +{ + old_locale_ = setlocale(LC_NUMERIC, nullptr); + setlocale(LC_NUMERIC, new_locale); +} + +ColorManager::SetLocale::~SetLocale() +{ + setlocale(LC_NUMERIC, old_locale_.toUtf8()); +} + OLIVE_NAMESPACE_EXIT diff --git a/app/render/colormanager.h b/app/render/colormanager.h index f6ffb3349..e4e6ff1d8 100644 --- a/app/render/colormanager.h +++ b/app/render/colormanager.h @@ -26,6 +26,8 @@ #include "codec/frame.h" #include "colorprocessor.h" +#define OCIO_SET_C_LOCALE_FOR_SCOPE ColorManager::SetLocale d("C") + OLIVE_NAMESPACE_ENTER class ColorManager : public QObject @@ -92,50 +94,15 @@ public: static void SetOCIOMethodForMode(RenderMode::Mode mode, OCIOMethod method); - class SetCLocale + class SetLocale { public: - SetCLocale() - { -#ifdef Q_OS_WINDOWS - // set locale will only change locale on the current thread - previousThreadConfig = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + SetLocale(const char* new_locale); - // get and store current locale - ssaLocale.convert(setlocale(LC_ALL, NULL)); - - // set to "C" locale - setlocale(LC_ALL, "C"); -#else - // set to C locale, saving the old one (returned from useLocale) - currentLocale = newlocale(LC_ALL_MASK,"C",NULL); - oldLocale = uselocale(currentLocale); -#endif - } - - ~SetCLocale() - { -#ifdef Q_OS_WINDOWS - // thread specific - setlocale(LC_ALL, ssaLocale.c_str()); - - // set back to global settings] - _configthreadlocale(previousThreadConfig); -#else - // restore the previous locale and freeing the created locale - uselocale(oldLocale); - freelocale(currentLocale); -#endif - } + ~SetLocale(); private: -#ifdef Q_OS_WINDOWS - SoStringA ssaLocale; - int previousThreadConfig; -#else - locale_t oldLocale; - locale_t currentLocale; -#endif + QString old_locale_; }; diff --git a/app/render/colorprocessor.cpp b/app/render/colorprocessor.cpp index 6f4a18e52..4b98a5133 100644 --- a/app/render/colorprocessor.cpp +++ b/app/render/colorprocessor.cpp @@ -44,10 +44,12 @@ ColorProcessor::ColorProcessor(ColorManager *config, const QString &input, const display_transform->setLooksOverrideEnabled(true); } + OCIO_SET_C_LOCALE_FOR_SCOPE; processor_ = config->GetConfig()->getProcessor(display_transform); } else { + OCIO_SET_C_LOCALE_FOR_SCOPE; processor_ = config->GetConfig()->getProcessor(input.toUtf8(), output.toUtf8());