summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp6
-rw-r--r--src/corelib/tools/qlocale.cpp36
-rw-r--r--src/corelib/tools/qlocale_p.h11
-rw-r--r--src/corelib/tools/qlocale_tools.cpp2
-rw-r--r--src/corelib/tools/qsharedpointer.cpp11
-rw-r--r--src/corelib/tools/qstring.cpp12
6 files changed, 54 insertions, 24 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 1d8621ad5a..70eae9e463 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -4112,7 +4112,8 @@ ushort QByteArray::toUShort(bool *ok, int base) const
/*!
Returns the byte array converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -4147,7 +4148,8 @@ double QByteArray::toDouble(bool *ok) const
/*!
Returns the byte array converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 4d5924a03e..51b886b0e0 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -1371,8 +1371,10 @@ qulonglong QLocale::toULongLong(const QString &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1391,8 +1393,10 @@ float QLocale::toFloat(const QString &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1538,8 +1542,10 @@ qulonglong QLocale::toULongLong(const QStringRef &s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1560,8 +1566,10 @@ float QLocale::toFloat(const QStringRef &s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1710,8 +1718,10 @@ qulonglong QLocale::toULongLong(QStringView s, bool *ok) const
}
/*!
- Returns the float represented by the localized string \a s, or 0.0
- if the conversion failed.
+ Returns the float represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -1729,8 +1739,10 @@ float QLocale::toFloat(QStringView s, bool *ok) const
}
/*!
- Returns the double represented by the localized string \a s, or
- 0.0 if the conversion failed.
+ Returns the double represented by the localized string \a s.
+
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for any other reason (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index 9f5811990b..98b6a31a46 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -251,7 +251,16 @@ public:
if (std::fabs(d) > std::numeric_limits<float>::max()) {
if (ok != 0)
*ok = false;
- return 0.0f;
+ const float huge = std::numeric_limits<float>::infinity();
+ return d < 0 ? -huge : huge;
+ }
+ if (std::fabs(d) >= std::numeric_limits<double>::min() // i.e. d != 0
+ && std::fabs(d) < std::numeric_limits<float>::min()) {
+ // Values smaller than std::numeric_limits<double>::min() have
+ // failed already; match them.
+ if (ok != 0)
+ *ok = false;
+ return 0;
}
return float(d);
}
diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp
index bde52a20b9..53258bec3e 100644
--- a/src/corelib/tools/qlocale_tools.cpp
+++ b/src/corelib/tools/qlocale_tools.cpp
@@ -354,7 +354,7 @@ double qt_asciiToDouble(const char *num, int numLen, bool &ok, int &processed,
ok = false;
for (int i = 0; i < processed; ++i) {
char c = num[i];
- if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e') {
+ if ((c < '0' || c > '9') && c != '.' && c != '-' && c != '+' && c != 'e' && c != 'E') {
// Garbage found
processed = 0;
return 0.0;
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 622b03f42d..a1caeeb135 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1383,15 +1383,18 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized);
x->strongref.store(-1);
x->weakref.store(2); // the QWeakPointer that called us plus the QObject itself
- if (!d->sharedRefcount.testAndSetRelease(0, x)) {
+
+ ExternalRefCountData *ret;
+ if (d->sharedRefcount.testAndSetOrdered(nullptr, x, ret)) { // ought to be release+acquire; this is acq_rel+acquire
+ ret = x;
+ } else {
// ~ExternalRefCountData has a Q_ASSERT, so we use this trick to
// only execute this if Q_ASSERTs are enabled
Q_ASSERT((x->weakref.store(0), true));
delete x;
- x = d->sharedRefcount.loadAcquire();
- x->weakref.ref();
+ ret->weakref.ref();
}
- return x;
+ return ret;
}
/**
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 90713bab10..5ea5aeca12 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -7401,7 +7401,8 @@ ushort QString::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -7439,7 +7440,8 @@ double QString::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12008,7 +12010,8 @@ ushort QStringRef::toUShort(bool *ok, int base) const
/*!
Returns the string converted to a \c double value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.
@@ -12033,7 +12036,8 @@ double QStringRef::toDouble(bool *ok) const
/*!
Returns the string converted to a \c float value.
- Returns 0.0 if the conversion fails.
+ Returns an infinity if the conversion overflows or 0.0 if the
+ conversion fails for other reasons (e.g. underflow).
If \a ok is not \c nullptr, failure is reported by setting *\a{ok}
to \c false, and success by setting *\a{ok} to \c true.