summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-06-06 08:34:03 +0200
committerLiang Qi <liang.qi@qt.io>2016-06-06 09:04:55 +0200
commit57057f76add416d0faf2e09a90c126baafb6198e (patch)
tree07d54f8e5daeb3ed1161723542e94c324d745166 /src/corelib/tools
parentdc0ae02ebc8e221f952829230c0301a718a6f10b (diff)
parentfd70978693bd92761e9989bc1c76bf83c1e8c987 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: .qmake.conf config.tests/unix/nis/nis.cpp mkspecs/unsupported/freebsd-g++/qplatformdefs.h src/corelib/tools/qdatetime.cpp src/corelib/tools/qsimd.cpp src/corelib/tools/qsimd_p.h src/network/access/access.pri src/network/access/qnetworkreplynsurlconnectionimpl.mm src/network/access/qnetworkreplynsurlconnectionimpl_p.h src/plugins/platforms/cocoa/qnsview.mm src/plugins/printsupport/windows/qwindowsprintdevice.cpp tests/auto/corelib/kernel/qobject/tst_qobject.cpp tests/auto/network/access/qnetworkreply/BLACKLIST tests/auto/widgets/widgets/qopenglwidget/BLACKLIST Change-Id: I4b32055bbf922392ef0264fd403405416fffee57
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbitarray.cpp26
-rw-r--r--src/corelib/tools/qcryptographichash.cpp20
-rw-r--r--src/corelib/tools/qdatetime.cpp2
-rw-r--r--src/corelib/tools/qhash.cpp9
-rw-r--r--src/corelib/tools/qmessageauthenticationcode.cpp20
-rw-r--r--src/corelib/tools/qsimd.cpp22
-rw-r--r--src/corelib/tools/qstring.cpp2
-rw-r--r--src/corelib/tools/qtimezoneprivate_tz.cpp214
8 files changed, 196 insertions, 119 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index 446e09b1c0..12e4687b3c 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -42,6 +42,7 @@
#include <qalgorithms.h>
#include <qdatastream.h>
#include <qdebug.h>
+#include <qendian.h>
#include <string.h>
QT_BEGIN_NAMESPACE
@@ -169,25 +170,6 @@ QBitArray::QBitArray(int size, bool value)
Same as size().
*/
-template <typename T> T qUnalignedLoad(const uchar *ptr)
-{
- /*
- * Testing with different compilers shows that they all optimize the memcpy
- * call away and replace with direct loads whenever possible. On x86 and PPC,
- * GCC does direct unaligned loads; on MIPS, it generates a pair of load-left
- * and load-right instructions. ICC and Clang do the same on x86. This is both
- * 32- and 64-bit.
- *
- * On ARM cores without unaligned loads, the compiler leaves a call to
- * memcpy.
- */
-
- T u;
- memcpy(&u, ptr, sizeof(u));
- return u;
-}
-
-
/*!
If \a on is true, this function returns the number of
1-bits stored in the bit array; otherwise the number
@@ -203,17 +185,17 @@ int QBitArray::count(bool on) const
const quint8 *const end = reinterpret_cast<const quint8 *>(d.end());
while (bits + 7 <= end) {
- quint64 v = qUnalignedLoad<quint64>(bits);
+ quint64 v = qFromUnaligned<quint64>(bits);
bits += 8;
numBits += int(qPopulationCount(v));
}
if (bits + 3 <= end) {
- quint32 v = qUnalignedLoad<quint32>(bits);
+ quint32 v = qFromUnaligned<quint32>(bits);
bits += 4;
numBits += int(qPopulationCount(v));
}
if (bits + 1 < end) {
- quint16 v = qUnalignedLoad<quint16>(bits);
+ quint16 v = qFromUnaligned<quint16>(bits);
bits += 2;
numBits += int(qPopulationCount(v));
}
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index 3cb3606013..08f89d2f02 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -95,9 +95,29 @@ static SHA3Final * const sha3Final = Final;
available on all platforms (MSVC 2008, for example), we #define them to the
Qt equivalents.
*/
+
+#ifdef uint64_t
+#undef uint64_t
+#endif
+
#define uint64_t QT_PREPEND_NAMESPACE(quint64)
+
+#ifdef uint32_t
+#undef uint32_t
+#endif
+
#define uint32_t QT_PREPEND_NAMESPACE(quint32)
+
+#ifdef uint8_t
+#undef uint8_t
+#endif
+
#define uint8_t QT_PREPEND_NAMESPACE(quint8)
+
+#ifdef int_least16_t
+#undef int_least16_t
+#endif
+
#define int_least16_t QT_PREPEND_NAMESPACE(qint16)
// Header from rfc6234 with 1 modification:
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index e18c220884..6750925853 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -2180,7 +2180,7 @@ static int qt_timezone()
// number of seconds west of UTC.
// - It also takes DST into account, so we need to adjust it to always
// get the Standard Time offset.
- return -t.tm_gmtoff + (t.tm_isdst ? SECS_PER_HOUR : 0L);
+ return -t.tm_gmtoff + (t.tm_isdst ? (long)SECS_PER_HOUR : 0L);
#elif defined(Q_OS_INTEGRITY)
return 0;
#else
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 2f0886edce..593a87e65d 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -58,6 +58,7 @@
#include <qbytearray.h>
#include <qdatetime.h>
#include <qbasicatomic.h>
+#include <qendian.h>
#include <private/qsimd_p.h>
#ifndef QT_BOOTSTRAPPED
@@ -112,24 +113,24 @@ static uint crc32(const Char *ptr, size_t len, uint h)
p += 8;
for ( ; p <= e; p += 8)
- h2 = _mm_crc32_u64(h2, qUnalignedLoad<qlonglong>(p - 8));
+ h2 = _mm_crc32_u64(h2, qFromUnaligned<qlonglong>(p - 8));
h = h2;
p -= 8;
len = e - p;
if (len & 4) {
- h = _mm_crc32_u32(h, qUnalignedLoad<uint>(p));
+ h = _mm_crc32_u32(h, qFromUnaligned<uint>(p));
p += 4;
}
# else
p += 4;
for ( ; p <= e; p += 4)
- h = _mm_crc32_u32(h, qUnalignedLoad<uint>(p - 4));
+ h = _mm_crc32_u32(h, qFromUnaligned<uint>(p - 4));
p -= 4;
len = e - p;
# endif
if (len & 2) {
- h = _mm_crc32_u16(h, qUnalignedLoad<ushort>(p));
+ h = _mm_crc32_u16(h, qFromUnaligned<ushort>(p));
p += 2;
}
if (sizeof(Char) == 1 && len & 1)
diff --git a/src/corelib/tools/qmessageauthenticationcode.cpp b/src/corelib/tools/qmessageauthenticationcode.cpp
index 9b91474283..9a84191452 100644
--- a/src/corelib/tools/qmessageauthenticationcode.cpp
+++ b/src/corelib/tools/qmessageauthenticationcode.cpp
@@ -46,9 +46,29 @@
available on all platforms (MSVC 2008, for example), we #define them to the
Qt equivalents.
*/
+
+#ifdef uint64_t
+#undef uint64_t
+#endif
+
#define uint64_t QT_PREPEND_NAMESPACE(quint64)
+
+#ifdef uint32_t
+#undef uint32_t
+#endif
+
#define uint32_t QT_PREPEND_NAMESPACE(quint32)
+
+#ifdef uint8_t
+#undef uint8_t
+#endif
+
#define uint8_t QT_PREPEND_NAMESPACE(quint8)
+
+#ifdef int_least16_t
+#undef int_least16_t
+#endif
+
#define int_least16_t QT_PREPEND_NAMESPACE(qint16)
// Header from rfc6234 with 1 modification:
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 3a5f0f18a1..c869c4e089 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -751,26 +751,4 @@ void qDumpCPUFeatures()
puts("");
}
-/*!
- \internal
- \fn T qUnalignedLoad(const void *ptr)
- \since 5.6.1
-
- Loads a \c{T} from address \a ptr, which may be misaligned.
-
- Use of this function avoid the undefined behavior that the C++ standard
- otherwise attributes to unaligned loads.
-*/
-
-/*!
- \internal
- \fn void qUnalignedStore(void *ptr, T t)
- \since 5.6.1
-
- Stores \a t to address \a ptr, which may be misaligned.
-
- Use of this function avoid the undefined behavior that the C++ standard
- otherwise attributes to unaligned stores.
-*/
-
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 9f968978dc..940fd5817b 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -584,7 +584,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l)
// we'll read uc[offset..offset+7] (16 bytes) and c[offset..offset+7] (8 bytes)
if (uc + offset + 7 < e) {
// same, but we're using an 8-byte load
- __m128i chunk = _mm_cvtsi64_si128(qUnalignedLoad<long long>(c + offset));
+ __m128i chunk = _mm_cvtsi64_si128(qFromUnaligned<long long>(c + offset));
__m128i secondHalf = _mm_unpacklo_epi8(chunk, nullmask);
__m128i ucdata = _mm_loadu_si128((const __m128i*)(uc + offset));
diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
index 8040365581..c2630c8593 100644
--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
+++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
@@ -47,6 +47,8 @@
#include <qdebug.h>
+#include "qlocale_tools_p.h"
+
#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -376,39 +378,126 @@ static QDate calculatePosixDate(const QByteArray &dateRule, int year)
}
}
-static QTime parsePosixTime(const QByteArray &timeRule)
+// returns the time in seconds, INT_MIN if we failed to parse
+static int parsePosixTime(const char *begin, const char *end)
{
- // Format "HH:mm:ss", put check parts count just in case
- QList<QByteArray> parts = timeRule.split(':');
- int count = parts.count();
- if (count == 3)
- return QTime(parts.at(0).toInt(), parts.at(1).toInt(), parts.at(2).toInt());
- else if (count == 2)
- return QTime(parts.at(0).toInt(), parts.at(1).toInt(), 0);
- else if (count == 1)
- return QTime(parts.at(0).toInt(), 0, 0);
- return QTime(2, 0, 0);
+ // Format "hh[:mm[:ss]]"
+ int hour, min = 0, sec = 0;
+
+ // Note that the calls to qstrtoll do *not* check the end pointer, which
+ // means they proceed until they find a non-digit. We check that we're
+ // still in range at the end, but we may have read from past end. It's the
+ // caller's responsibility to ensure that begin is part of a
+ // null-terminated string.
+
+ bool ok = false;
+ hour = qstrtoll(begin, &begin, 10, &ok);
+ if (!ok || hour < 0)
+ return INT_MIN;
+ if (begin < end && *begin == ':') {
+ // minutes
+ ++begin;
+ min = qstrtoll(begin, &begin, 10, &ok);
+ if (!ok || min < 0)
+ return INT_MIN;
+
+ if (begin < end && *begin == ':') {
+ // seconds
+ ++begin;
+ sec = qstrtoll(begin, &begin, 10, &ok);
+ if (!ok || sec < 0)
+ return INT_MIN;
+ }
+ }
+
+ // we must have consumed everything
+ if (begin != end)
+ return INT_MIN;
+
+ return (hour * 60 + min) * 60 + sec;
}
-static int parsePosixOffset(const QByteArray &timeRule)
+static QTime parsePosixTransitionTime(const QByteArray &timeRule)
+{
+ // Format "hh[:mm[:ss]]"
+ int value = parsePosixTime(timeRule.constBegin(), timeRule.constEnd());
+ if (value == INT_MIN) {
+ // if we failed to parse, return 02:00
+ return QTime(2, 0, 0);
+ }
+ return QTime::fromMSecsSinceStartOfDay(value * 1000);
+}
+
+static int parsePosixOffset(const char *begin, const char *end)
{
// Format "[+|-]hh[:mm[:ss]]"
- QList<QByteArray> parts = timeRule.split(':');
- int count = parts.count();
- if (count == 3) {
- int hour = parts.at(0).toInt();
- int sign = hour >= 0 ? -1 : 1;
- return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60) + parts.at(2).toInt());
- } else if (count == 2) {
- int hour = parts.at(0).toInt();
- int sign = hour >= 0 ? -1 : 1;
- return sign * ((qAbs(hour) * 60 * 60) + (parts.at(1).toInt() * 60));
- } else if (count == 1) {
- int hour = parts.at(0).toInt();
- int sign = hour >= 0 ? -1 : 1;
- return sign * (qAbs(hour) * 60 * 60);
- }
- return 0;
+ // note that the sign is inverted because POSIX counts in hours West of GMT
+ bool negate = true;
+ if (*begin == '+') {
+ ++begin;
+ } else if (*begin == '-') {
+ negate = false;
+ ++begin;
+ }
+
+ int value = parsePosixTime(begin, end);
+ if (value == INT_MIN)
+ return value;
+ return negate ? -value : value;
+}
+
+static inline bool asciiIsLetter(char ch)
+{
+ ch |= 0x20; // lowercases if it is a letter, otherwise just corrupts ch
+ return ch >= 'a' && ch <= 'z';
+}
+
+// Returns the zone name, the offset (in seconds) and advances \a begin to
+// where the parsing ended. Returns a zone of INT_MIN in case an offset
+// couldn't be read.
+static QPair<QString, int> parsePosixZoneNameAndOffset(const char *&pos, const char *end)
+{
+ static const char offsetChars[] = "0123456789:";
+ QPair<QString, int> result = qMakePair(QString(), INT_MIN);
+
+ const char *nameBegin = pos;
+ const char *nameEnd;
+ Q_ASSERT(pos < end);
+
+ if (*pos == '<') {
+ nameBegin = pos + 1; // skip the '<'
+ nameEnd = nameBegin;
+ while (nameEnd < end && *nameEnd != '>') {
+ // POSIX says only alphanumeric, but we allow anything
+ ++nameEnd;
+ }
+ pos = nameEnd + 1; // skip the '>'
+ } else {
+ nameBegin = pos;
+ nameEnd = nameBegin;
+ while (nameEnd < end && asciiIsLetter(*nameEnd))
+ ++nameEnd;
+ pos = nameEnd;
+ }
+ if (nameEnd - nameBegin < 3)
+ return result; // name must be at least 3 characters long
+
+ // zone offset, form [+-]hh:mm:ss
+ const char *zoneBegin = pos;
+ const char *zoneEnd = pos;
+ if (zoneEnd < end && (zoneEnd[0] == '+' || zoneEnd[0] == '-'))
+ ++zoneEnd;
+ while (zoneEnd < end) {
+ if (strchr(offsetChars, char(*zoneEnd)) == NULL)
+ break;
+ ++zoneEnd;
+ }
+
+ result.first = QString::fromUtf8(nameBegin, nameEnd - nameBegin);
+ if (zoneEnd > zoneBegin)
+ result.second = parsePosixOffset(zoneBegin, zoneEnd);
+ pos = zoneEnd;
+ return result;
}
static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray &posixRule,
@@ -425,58 +514,45 @@ static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArra
// POSIX Format is like "TZ=CST6CDT,M3.2.0/2:00:00,M11.1.0/2:00:00"
// i.e. "std offset dst [offset],start[/time],end[/time]"
- // See http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
+ // See the section about TZ at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
QList<QByteArray> parts = posixRule.split(',');
- QString name = QString::fromUtf8(parts.at(0));
- QString stdName;
- QString stdOffsetString;
- QString dstName;
- QString dstOffsetString;
- bool parsedStdName = false;
- bool parsedStdOffset = false;
- for (int i = 0; i < name.size(); ++i) {
- if (name.at(i).isLetter()) {
- if (parsedStdName) {
- parsedStdOffset = true;
- dstName.append(name.at(i));
- } else {
- stdName.append(name.at(i));
+ QPair<QString, int> stdZone, dstZone;
+ {
+ const QByteArray &zoneinfo = parts.at(0);
+ const char *begin = zoneinfo.constBegin();
+
+ stdZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd());
+ if (stdZone.second == INT_MIN) {
+ stdZone.second = 0; // reset to UTC if we failed to parse
+ } else if (begin < zoneinfo.constEnd()) {
+ dstZone = parsePosixZoneNameAndOffset(begin, zoneinfo.constEnd());
+ if (dstZone.second == INT_MIN) {
+ // if the dst offset isn't provided, it is 1 hour ahead of the standard offset
+ dstZone.second = stdZone.second + (60 * 60);
}
- } else {
- parsedStdName = true;
- if (parsedStdOffset)
- dstOffsetString.append(name.at(i));
- else
- stdOffsetString.append(name.at(i));
}
}
- int utcOffset = parsePosixOffset(stdOffsetString.toUtf8());
-
// If only the name part then no transitions
if (parts.count() == 1) {
QTimeZonePrivate::Data data;
data.atMSecsSinceEpoch = lastTranMSecs;
- data.offsetFromUtc = utcOffset;
- data.standardTimeOffset = utcOffset;
+ data.offsetFromUtc = stdZone.second;
+ data.standardTimeOffset = stdZone.second;
data.daylightTimeOffset = 0;
- data.abbreviation = stdName;
+ data.abbreviation = stdZone.first;
result << data;
return result;
}
- // If not populated the total dst offset is 1 hour
- int dstOffset = utcOffset + (60 * 60);
- if (!dstOffsetString.isEmpty())
- dstOffset = parsePosixOffset(dstOffsetString.toUtf8());
// Get the std to dst transtion details
QList<QByteArray> dstParts = parts.at(1).split('/');
QByteArray dstDateRule = dstParts.at(0);
QTime dstTime;
if (dstParts.count() > 1)
- dstTime = parsePosixTime(dstParts.at(1));
+ dstTime = parsePosixTransitionTime(dstParts.at(1));
else
dstTime = QTime(2, 0, 0);
@@ -485,25 +561,25 @@ static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArra
QByteArray stdDateRule = stdParts.at(0);
QTime stdTime;
if (stdParts.count() > 1)
- stdTime = parsePosixTime(stdParts.at(1));
+ stdTime = parsePosixTransitionTime(stdParts.at(1));
else
stdTime = QTime(2, 0, 0);
for (int year = startYear; year <= endYear; ++year) {
QTimeZonePrivate::Data dstData;
QDateTime dst(calculatePosixDate(dstDateRule, year), dstTime, Qt::UTC);
- dstData.atMSecsSinceEpoch = dst.toMSecsSinceEpoch() - (utcOffset * 1000);
- dstData.offsetFromUtc = dstOffset;
- dstData.standardTimeOffset = utcOffset;
- dstData.daylightTimeOffset = dstOffset - utcOffset;
- dstData.abbreviation = dstName;
+ dstData.atMSecsSinceEpoch = dst.toMSecsSinceEpoch() - (stdZone.second * 1000);
+ dstData.offsetFromUtc = dstZone.second;
+ dstData.standardTimeOffset = stdZone.second;
+ dstData.daylightTimeOffset = dstZone.second - stdZone.second;
+ dstData.abbreviation = dstZone.first;
QTimeZonePrivate::Data stdData;
QDateTime std(calculatePosixDate(stdDateRule, year), stdTime, Qt::UTC);
- stdData.atMSecsSinceEpoch = std.toMSecsSinceEpoch() - (dstOffset * 1000);
- stdData.offsetFromUtc = utcOffset;
- stdData.standardTimeOffset = utcOffset;
+ stdData.atMSecsSinceEpoch = std.toMSecsSinceEpoch() - (dstZone.second * 1000);
+ stdData.offsetFromUtc = stdZone.second;
+ stdData.standardTimeOffset = stdZone.second;
stdData.daylightTimeOffset = 0;
- stdData.abbreviation = stdName;
+ stdData.abbreviation = stdZone.first;
// Part of the high year will overflow
if (year == 292278994 && (dstData.atMSecsSinceEpoch < 0 || stdData.atMSecsSinceEpoch < 0)) {
if (dstData.atMSecsSinceEpoch > 0) {