From b268bd9dbaf4e33a73a175cfddb517c51c0a2ed6 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 11 Dec 2012 00:41:35 +0100 Subject: [PATCH] Use QString::toDouble to convert to numbers QString::toDouble() is always using the C locale in Qt 5, strtod_l seems to have some stability issues for me, and creating a locale on the stack doesn't sound very performant. Change-Id: I35705a125b0c5913a5390ed1429c4e7490300f92 Reviewed-by: Erik Verbruggen --- qmljs_runtime.cpp | 16 ++++++++++++---- v4.pro | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 62e7be4..1e664d2 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -44,6 +44,7 @@ #include "qmljs_objects.h" #include "qv4ir_p.h" #include "qv4ecmaobjects_p.h" +#include "private/qlocale_tools_p.h" #include #include @@ -52,7 +53,6 @@ #include #include #include -#include namespace QQmlJS { namespace VM { @@ -436,9 +436,17 @@ double __qmljs_string_to_number(ExecutionContext *, String *string) const QString s = string->toQString(); if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X"))) return s.toLong(0, 16); - locale_t c_locale = newlocale(LC_ALL_MASK, NULL, NULL); - double d = ::strtod_l(s.toUtf8().constData(), 0, c_locale); - freelocale(c_locale); + bool ok; + QByteArray ba = s.toLatin1(); + const char *begin = ba.constData(); + const char *end = 0; + double d = qstrtod(begin, &end, &ok); + if (end - begin != ba.size() - 1) { + if (ba == "Infinity") + d = INFINITY; + else + d = nan(""); + } return d; } diff --git a/v4.pro b/v4.pro index 3aecdab..1f1604b 100644 --- a/v4.pro +++ b/v4.pro @@ -1,4 +1,4 @@ -QT = core qmldevtools-private +QT = core-private qmldevtools-private CONFIG -= app_bundle CONFIG += console -- 2.7.4