r22254 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Sat Dec 16 13:19:07 UTC 2017
Author: jghali
Date: Sat Dec 16 13:19:07 2017
New Revision: 22254
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22254
Log:
Backport from trunk: avoid calling setlocale() in ScCLocale::strtod() as setlocale() affects all threads
Modified:
branches/Version14x/Scribus/scribus/scclocale.cpp
branches/Version14x/Scribus/scribus/scclocale.h
Modified: branches/Version14x/Scribus/scribus/scclocale.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22254&path=/branches/Version14x/Scribus/scribus/scclocale.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scclocale.cpp (original)
+++ branches/Version14x/Scribus/scribus/scclocale.cpp Sat Dec 16 13:19:07 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,33 @@
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) : (std::streamoff) sstream.tellg();
+ *endptr = const_cast<char*>(str) + bytesRead;
return result;
}
- else
- {
-#if defined(Q_WS_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) : (std::streamoff) 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: branches/Version14x/Scribus/scribus/scclocale.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22254&path=/branches/Version14x/Scribus/scribus/scclocale.h
==============================================================================
--- branches/Version14x/Scribus/scribus/scclocale.h (original)
+++ branches/Version14x/Scribus/scribus/scclocale.h Sat Dec 16 13:19:07 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
More information about the scribus-commit
mailing list