Author: jghali
Date: Mon Dec  4 11:53:32 2017
New Revision: 22234

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22234
Log:
avoid calling setlocale() in ScCLocale::strtod() as setlocale() affects all 
threads

Modified:
    trunk/Scribus/scribus/scclocale.cpp
    trunk/Scribus/scribus/scclocale.h

Modified: trunk/Scribus/scribus/scclocale.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22234&path=/trunk/Scribus/scribus/scclocale.cpp
==============================================================================
--- trunk/Scribus/scribus/scclocale.cpp (original)
+++ trunk/Scribus/scribus/scclocale.cpp Mon Dec  4 11:53:32 2017
@@ -13,13 +13,14 @@
 #include "scclocale.h"
 
 #include <cstdlib>
+#include <sstream>
 
 #include <QByteArray>
 #include <QDebug>
 
 ScCLocale * ScCLocale::m_instance = 0;
 ScCLocale::ScCLocale()
-       :qLocale(QLocale::C)
+       :qLocale(QLocale::C), cLocale(0)
 {
        qLocale.setNumberOptions(QLocale::OmitGroupSeparator);
 
@@ -174,33 +175,34 @@
        return that()->qLocale.toString(d, 'f', prec);
 }
 
-double ScCLocale::strtod ( const char * str, char ** endptr )
-{
-       if(NULL == that()->cLocale)
+double ScCLocale::strtod(const char * str, char ** endptr)
+{
+       if (NULL == that()->cLocale)
        {
                // a sade workaround
                double result(0.0);
-               setlocale(LC_NUMERIC, "C");
-               result = std::strtod(str, endptr);
-               setlocale(LC_NUMERIC, "");
+               std::streamoff bytesRead;
+               std::istringstream sstream(str);
+               sstream.imbue(std::locale::classic());
+               sstream >> result;
+               bytesRead = sstream.eof() ? strlen(str) : sstream.tellg();
+               *endptr = const_cast<char*>(str) + bytesRead;
                return result;
        }
-       else
-       {
-#if defined(Q_OS_WIN)
-               return _strtod_l(str, endptr, that()->cLocale);
+
+#if defined(Q_OS_SOLARIS) || defined (Q_OS_OPENBSD) || defined(Q_OS_FREEBSD) 
|| defined(Q_OS_HAIKU)
+       double result(0.0);
+       std::streamoff bytesRead;
+       std::istringstream sstream(str);
+       sstream.imbue(std::locale::classic());
+       sstream >> result;
+       bytesRead = sstream.eof() ? strlen(str) : sstream.tellg();
+       *endptr = const_cast<char*>(str) + bytesRead;
+       return result;
+#elif defined(Q_OS_WIN)
+       return _strtod_l(str, endptr, that()->cLocale);
 #else
-  #if defined(Q_OS_SOLARIS) or defined (Q_OS_OPENBSD) or defined(Q_OS_FREEBSD) 
or defined(Q_OS_HAIKU)
-               char *oldlocale=setlocale(LC_NUMERIC, NULL);
-               double result(0.0);
-               setlocale(LC_NUMERIC, "C");
-               result = std::strtod(str, endptr);
-               setlocale(LC_NUMERIC, oldlocale);
-               return result;
-  #else
-               return strtod_l(str, endptr, that()->cLocale);
-  #endif
+       return strtod_l(str, endptr, that()->cLocale);
 #endif
-       }
-}
-
+}
+

Modified: trunk/Scribus/scribus/scclocale.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22234&path=/trunk/Scribus/scribus/scclocale.h
==============================================================================
--- trunk/Scribus/scribus/scclocale.h   (original)
+++ trunk/Scribus/scribus/scclocale.h   Mon Dec  4 11:53:32 2017
@@ -41,6 +41,7 @@
 {
        ScCLocale();
        ~ScCLocale();
+
        QLocale qLocale;
        XLocaleType cLocale;
 
@@ -55,8 +56,7 @@
                static float toFloatC(const QString& str, bool * ok = 0);
                static float toFloatC(const QString& str, float defValue);
                static QString toQStringC(double d, int prec = 3);
-               static double strtod ( const char * str, char ** endptr );
-               
+               static double strtod(const char * str, char ** endptr);
 };
 
 // The code of this function has been borrowed from Qt SVG module


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to