From cf2220385506fe9f94ef1dbfa43518e489e04155 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 16 Oct 2017 22:31:42 -0700 Subject: Add a comment about the weird refcount for adopted QThreadData It's perfectly benign, but I spent a lot of time debugging this and trying to figure out how to solve something that didn't need solving. So document for posterity. For an adopted thread, the TLS destructors or the adopted thread watcher on Windows will call QThreadData::deref(): - QThreadData::deref(), count drops to zero -> delete this; - ~QThreadData() deletes the QAdoptedThread -> delete t; - ~QThreadPrivate() calls deref() again -> data->deref(); - QThreadData::deref(), count drops to -1, no action taken - ~QObjectPrivate() calls deref() yet again -> threadData->deref() - QThreadData::deref(), count drops to -2, no action taken Change-Id: Icaa86fc7b54d4b368c0efffd14ee448e0796e8d7 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- src/corelib/thread/qthread.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index e92be64dfa..cad7a14017 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -78,6 +78,13 @@ QThreadData::~QThreadData() QThreadData::clearCurrentThreadData(); } + // ~QThread() sets thread to nullptr, so if it isn't null here, it's + // because we're being run before the main object itself. This can only + // happen for QAdoptedThread. Note that both ~QThreadPrivate() and + // ~QObjectPrivate() will deref this object again, but that is acceptable + // because this destructor is still running (the _ref sub-object has not + // been destroyed) and there's no reentrancy. The refcount will become + // negative, but that's acceptable. QThread *t = thread; thread = 0; delete t; -- cgit v1.2.3 From fd9dd8e95b7563a439b1672fa622729bdcb6f4fc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 20 Oct 2017 12:09:14 -0700 Subject: Move the minimum Linux version declarations to a header I'll need it in the AF_NETLINK implementation of QNetworkInterface. Change-Id: Icaa86fc7b54d4b368c0efffd14ef5ce895d0ed5b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/global/global.pri | 1 + src/corelib/global/minimum-linux.S | 33 ++---------- src/corelib/global/minimum-linux_p.h | 98 ++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 src/corelib/global/minimum-linux_p.h (limited to 'src/corelib') diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index 7c31df4d6a..e1ca8828f9 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -73,6 +73,7 @@ linux:!static { } else { SOURCES += global/minimum-linux.S } + HEADERS += global/minimum-linux_p.h } qtConfig(slog2): \ diff --git a/src/corelib/global/minimum-linux.S b/src/corelib/global/minimum-linux.S index 6b7fb4f63b..dfc3cec1be 100644 --- a/src/corelib/global/minimum-linux.S +++ b/src/corelib/global/minimum-linux.S @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include "private/qglobal_p.h" +#include "minimum-linux_p.h" /* Copied from #include : */ @@ -76,31 +76,6 @@ /* Operating systems: */ .long ELF_NOTE_OS_LINUX -/* Minimum Linux kernel version: - * We require the following features in Qt (unconditional, no fallback): - * Feature Added in version Macro - * - inotify_init1 before 2.6.12-rc12 - * - futex(2) before 2.6.12-rc12 - * - linkat(2) 2.6.17 O_TMPFILE - * - FUTEX_PRIVATE_FLAG 2.6.22 - * - O_CLOEXEC 2.6.23 - * - eventfd 2.6.23 - * - pipe2 & dup3 2.6.27 - * - accept4 2.6.28 - * - renameat2 3.16 QT_CONFIG(renameat2) - * - getrandom 3.17 QT_CONFIG(getentropy) - */ - -#if QT_CONFIG(getentropy) - .long 3 - .long 17 - .long 0 -#elif QT_CONFIG(renameat2) - .long 3 - .long 16 - .long 0 -#else - .long 2 - .long 6 - .long 28 -#endif + .long MINLINUX_MAJOR + .long MINLINUX_MINOR + .long MINLINUX_PATCH diff --git a/src/corelib/global/minimum-linux_p.h b/src/corelib/global/minimum-linux_p.h new file mode 100644 index 0000000000..324744b856 --- /dev/null +++ b/src/corelib/global/minimum-linux_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MINIMUMLINUX_P_H +#define MINIMUMLINUX_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +// EXTRA WARNING +// ------------- +// +// This file must also be valid assembler source. +// + +#include "private/qglobal_p.h" + +QT_BEGIN_NAMESPACE + +/* Minimum Linux kernel version: + * We require the following features in Qt (unconditional, no fallback): + * Feature Added in version Macro + * - inotify_init1 before 2.6.12-rc12 + * - futex(2) before 2.6.12-rc12 + * - FUTEX_WAKE_OP 2.6.14 FUTEX_OP + * - linkat(2) 2.6.17 O_TMPFILE + * - FUTEX_PRIVATE_FLAG 2.6.22 + * - O_CLOEXEC 2.6.23 + * - eventfd 2.6.23 + * - pipe2 & dup3 2.6.27 + * - accept4 2.6.28 + * - renameat2 3.16 QT_CONFIG(renameat2) + * - getrandom 3.17 QT_CONFIG(getentropy) + */ + +#if QT_CONFIG(getentropy) +# define MINLINUX_MAJOR 3 +# define MINLINUX_MINOR 17 +# define MINLINUX_PATCH 0 +#elif QT_CONFIG(renameat2) +# define MINLINUX_MAJOR 3 +# define MINLINUX_MINOR 16 +# define MINLINUX_PATCH 0 +#else +# define MINLINUX_MAJOR 2 +# define MINLINUX_MINOR 6 +# define MINLINUX_PATCH 28 +#endif + +#define MINIMUM_LINUX_VERSION QT_VERSION_CHECK(MINLINUX_MAJOR, MINLINUX_MINOR, MINLINUX_PATCH) + +QT_END_NAMESPACE + +#endif // MINIMUMLINUX_P_H -- cgit v1.2.3 From 81f251660026fff198daf8920edc62bbc782ff7d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 12 Oct 2017 14:59:51 -0700 Subject: QRandomGenerator: add system() and global() Right now,this does really nothing. This commit is just to allow us to transition the other modules (besides qtbase) to use the syntax that will become the API. I've marked three places to use the system CSPRNG: 1) the QHash seed 2) QUuid 3) QAuthenticator I didn't think the HTTP multipart boundary needed to be cryptographically safe, so I changed that one to the global generator. Change-Id: Ib17dde1a1dbb49a7bba8fffd14ecf1938bd8ff61 Reviewed-by: Edward Welbourne --- src/corelib/global/qrandom.h | 9 +++++---- src/corelib/plugin/quuid.cpp | 2 +- src/corelib/tools/qhash.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qrandom.h b/src/corelib/global/qrandom.h index 2259f2657a..049495d4e8 100644 --- a/src/corelib/global/qrandom.h +++ b/src/corelib/global/qrandom.h @@ -51,9 +51,12 @@ class QRandomGenerator template using IfValidUInt = typename std::enable_if::value && sizeof(UInt) >= sizeof(uint), bool>::type; public: + static QRandomGenerator system() { return {}; } + static QRandomGenerator global() { return {}; } QRandomGenerator() = default; // ### REMOVE BEFORE 5.10 + QRandomGenerator *operator->() { return this; } static quint32 get32() { return generate(); } static quint64 get64() { return generate64(); } static qreal getReal() { return generateDouble(); } @@ -135,13 +138,14 @@ public: static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits::max)(); } private: - Q_DISABLE_COPY(QRandomGenerator) static Q_CORE_EXPORT void fillRange_helper(void *buffer, void *bufferEnd); }; class QRandomGenerator64 { public: + static QRandomGenerator64 system() { return {}; } + static QRandomGenerator64 global() { return {}; } QRandomGenerator64() = default; static quint64 generate() { return QRandomGenerator::generate64(); } @@ -152,9 +156,6 @@ public: double entropy() const Q_DECL_NOTHROW { return 0.0; } static Q_DECL_CONSTEXPR result_type min() { return (std::numeric_limits::min)(); } static Q_DECL_CONSTEXPR result_type max() { return (std::numeric_limits::max)(); } - -private: - Q_DISABLE_COPY(QRandomGenerator64) }; diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 11ef247531..3a1c0495fe 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -945,7 +945,7 @@ QUuid QUuid::createUuid() QUuid result(Qt::Uninitialized); uint *data = &(result.data1); enum { AmountToRead = 4 }; - QRandomGenerator::fillRange(data, AmountToRead); + QRandomGenerator::system()->fillRange(data, AmountToRead); result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE result.data3 = (result.data3 & 0x0FFF) | 0x4000; // UV_Random diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 485c6591c2..ded9ad354e 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -296,7 +296,7 @@ static uint qt_create_qhash_seed() return seed; } - seed = QRandomGenerator::generate(); + seed = QRandomGenerator::system()->generate(); #endif // QT_BOOTSTRAPPED return seed; -- cgit v1.2.3 From 0e0f656f5031585c6b691d80057dfdc00bc48400 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 17 Oct 2017 07:31:42 -0700 Subject: Mark the previously public qstringalgorithms.h functions private Discussed during Qt Contributor Summit 2017. We concluded that we don't want to make these functions public, as they do not follow Qt coding style API. Specifically, qStartsWith(a, b) is not easily understood which argument is the needle and which argument is the haystack (same problem memcpy() has). Compare that to a.startsWith(b) which can clearly be read in English as a subject-verb-object sentence. This commit removes the unit tests that called compare(). Discussed-on: http://lists.qt-project.org/pipermail/development/2017-October/031060.html Change-Id: Icaa86fc7b54d4b368c0efffd14ee6205eb9043fb Reviewed-by: Friedemann Kleint --- src/corelib/doc/snippets/qstring/main.cpp | 10 +-- src/corelib/tools/qstring.cpp | 119 ++++++++++++------------------ src/corelib/tools/qstring.h | 56 +++++++------- src/corelib/tools/qstringalgorithms.h | 40 +++++----- src/corelib/tools/qstringview.h | 20 ++--- src/corelib/tools/qvector.h | 2 +- 6 files changed, 115 insertions(+), 132 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp index f740888fe7..3d09e3618e 100644 --- a/src/corelib/doc/snippets/qstring/main.cpp +++ b/src/corelib/doc/snippets/qstring/main.cpp @@ -333,11 +333,11 @@ void Widget::compareSensitiveFunction() int z = QString::compare("auto", "Car", Qt::CaseInsensitive); // z < 0 //! [16] - //! [qCompareStrings-QSV-QSV] - int x = qCompareStrings(u"aUtO", u"AuTo", Qt::CaseInsensitive); // x == 0 - int y = qCompareStrings(u"auto", u"Car", Qt::CaseSensitive); // y > 0 - int z = qCompareStrings(u"auto", u"Car", Qt::CaseInsensitive); // z < 0 - //! [qCompareStrings-QSV-QSV] + //! [QtPrivate::compareStrings-QSV-QSV] + int x = QtPrivate::compareStrings(u"aUtO", u"AuTo", Qt::CaseInsensitive); // x == 0 + int y = QtPrivate::compareStrings(u"auto", u"Car", Qt::CaseSensitive); // y > 0 + int z = QtPrivate::compareStrings(u"auto", u"Car", Qt::CaseInsensitive); // z < 0 + //! [QtPrivate::compareStrings-QSV-QSV] } void Widget::containsFunction() diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 57a43205b7..c10987a5fe 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -160,7 +160,7 @@ static inline bool qt_ends_with(QStringView haystack, QStringView needle, Qt::Ca static inline bool qt_ends_with(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs); static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSensitivity cs); -qssize_t qustrlen(const ushort *str) Q_DECL_NOTHROW +qssize_t QtPrivate::qustrlen(const ushort *str) Q_DECL_NOTHROW { qssize_t result = 0; @@ -758,6 +758,7 @@ static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSens /*! \relates QStringView + \internal \since 5.10 Returns an integer that compares to 0 as \a lhs compares to \a rhs. @@ -771,13 +772,14 @@ static int qt_compare_strings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSens \snippet qstring/main.cpp qCompareStrings-QSV-QSV */ -int qCompareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_compare_strings(lhs, rhs, cs); } /*! \relates QStringView + \internal \since 5.10 \overload @@ -790,13 +792,14 @@ int qCompareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_ of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int qCompareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_compare_strings(lhs, rhs, cs); } /*! \relates QStringView + \internal \since 5.10 \overload @@ -809,13 +812,14 @@ int qCompareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs) of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int qCompareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_compare_strings(lhs, rhs, cs); } /*! \relates QStringView + \internal \since 5.10 \overload @@ -828,7 +832,7 @@ int qCompareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs) of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with QString::localeAwareCompare(). */ -int qCompareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +int QtPrivate::compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_compare_strings(lhs, rhs, cs); } @@ -4732,15 +4736,17 @@ QByteArray QString::toLatin1_helper(const QChar *data, int length) /*! \since 5.10 + \internal \relates QStringView Returns a Latin-1 representation of \a string as a QByteArray. The behavior is undefined if \a string contains non-Latin1 characters. - \sa QString::toLatin1(), QStringView::toLatin1(), qConvertToUtf8(), qConvertToLocal8Bit(), qConvertToUcs4() + \sa QString::toLatin1(), QStringView::toLatin1(), QtPrivate::convertToUtf8(), + QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUcs4() */ -QByteArray qConvertToLatin1(QStringView string) +QByteArray QtPrivate::convertToLatin1(QStringView string) { return qt_convert_to_latin1(string); } @@ -4853,6 +4859,7 @@ static QByteArray qt_convert_to_local_8bit(QStringView string) /*! \since 5.10 + \internal \relates QStringView Returns a local 8-bit representation of \a string as a QByteArray. @@ -4864,9 +4871,10 @@ static QByteArray qt_convert_to_local_8bit(QStringView string) The behavior is undefined if \a string contains characters not supported by the locale's 8-bit encoding. - \sa QString::toLocal8Bit(), QStringView::toLocal8Bit(), qConvertToLatin1(), qConvertToUtf8(), qConvertToUcs4() + \sa QString::toLocal8Bit(), QStringView::toLocal8Bit(), QtPrivate::vonvertToLatin1(), + QtPrivate::convertToUtf8(), QtPrivate::convertToUcs4() */ -QByteArray qConvertToLocal8Bit(QStringView string) +QByteArray QtPrivate::convertToLocal8Bit(QStringView string) { return qt_convert_to_local_8bit(string); } @@ -4899,6 +4907,7 @@ static QByteArray qt_convert_to_utf8(QStringView str) /*! \since 5.10 + \internal \relates QStringView Returns a UTF-8 representation of \a string as a QByteArray. @@ -4906,9 +4915,10 @@ static QByteArray qt_convert_to_utf8(QStringView str) UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QStringView. - \sa QString::toUtf8(), QStringView::toUtf8(), qConvertToLatin1(), qConvertToLocal8Bit(), qConvertToUcs4() + \sa QString::toUtf8(), QStringView::toUtf8(), QtPrivate::convertToLatin1(), + QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUcs4() */ -QByteArray qConvertToUtf8(QStringView string) +QByteArray QtPrivate::convertToUtf8(QStringView string) { return qt_convert_to_utf8(string); } @@ -4947,6 +4957,7 @@ static QVector qt_convert_to_ucs4(QStringView string) /*! \since 5.10 + \internal \relates QStringView Returns a UCS-4/UTF-32 representation of \a string as a QVector. @@ -4958,9 +4969,10 @@ static QVector qt_convert_to_ucs4(QStringView string) The returned vector is not NUL terminated. - \sa QString::toUcs4(), QStringView::toUcs4(), qConvertToLatin1(), qConvertToLocal8Bit(), qConvertToUtf8() + \sa QString::toUcs4(), QStringView::toUcs4(), QtPrivate::convertToLatin1(), + QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUtf8() */ -QVector qConvertToUcs4(QStringView string) +QVector QtPrivate::convertToUcs4(QStringView string) { return qt_convert_to_ucs4(string); } @@ -5269,6 +5281,7 @@ namespace { /*! \fn QStringView qTrimmed(QStringView s) \fn QLatin1String qTrimmed(QLatin1String s) + \internal \relates QStringView \since 5.10 @@ -5280,12 +5293,12 @@ namespace { \sa QString::trimmed(), QStringView::trimmed(), QLatin1String::trimmed() */ -QStringView qTrimmed(QStringView s) Q_DECL_NOTHROW +QStringView QtPrivate::trimmed(QStringView s) Q_DECL_NOTHROW { return qt_trimmed(s); } -QLatin1String qTrimmed(QLatin1String s) Q_DECL_NOTHROW +QLatin1String QtPrivate::trimmed(QLatin1String s) Q_DECL_NOTHROW { return qt_trimmed(s); } @@ -5646,8 +5659,6 @@ QString& QString::fill(QChar ch, int size) Note that no string is equal to \a s1 being 0. Equivalent to \c {s1 != 0 && compare(s1, s2) == 0}. - - \sa qCompareStrings() */ /*! @@ -5659,8 +5670,6 @@ QString& QString::fill(QChar ch, int size) For \a s1 != 0, this is equivalent to \c {compare(} \a s1, \a s2 \c {) != 0}. Note that no string is equal to \a s1 being 0. - - \sa qCompareStrings() */ /*! @@ -5675,8 +5684,6 @@ QString& QString::fill(QChar ch, int size) of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. - - \sa qCompareStrings() */ /*! @@ -5691,8 +5698,6 @@ QString& QString::fill(QChar ch, int size) of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare(). - - \sa qCompareStrings() */ /*! @@ -5706,8 +5711,6 @@ QString& QString::fill(QChar ch, int size) of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function. - - \sa qCompareStrings() */ /*! @@ -5788,7 +5791,7 @@ QString& QString::fill(QChar ch, int size) \snippet qstring/main.cpp 16 - \sa qCompareStrings(), operator==(), operator<(), operator>() + \sa operator==(), operator<(), operator>() */ /*! @@ -5798,8 +5801,6 @@ QString& QString::fill(QChar ch, int size) Performs a comparison of \a s1 and \a s2, using the case sensitivity setting \a cs. - - \sa qCompareStrings() */ /*! @@ -5810,8 +5811,6 @@ QString& QString::fill(QChar ch, int size) Performs a comparison of \a s1 and \a s2, using the case sensitivity setting \a cs. - - \sa qCompareStrings() */ @@ -5825,8 +5824,6 @@ QString& QString::fill(QChar ch, int size) string. Same as compare(*this, \a other, \a cs). - - \sa qCompareStrings() */ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { @@ -5852,8 +5849,6 @@ int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, \since 4.2 Same as compare(*this, \a other, \a cs). - - \sa qCompareStrings() */ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW { @@ -5867,8 +5862,6 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const Q_DECL_N Compares the string reference, \a ref, with the string and returns an integer less than, equal to, or greater than zero if the string is less than, equal to, or greater than \a ref. - - \sa qCompareStrings() */ /*! @@ -5894,8 +5887,6 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2, /*! \fn int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) \overload compare() - - \sa qCompareStrings() */ /*! @@ -10218,8 +10209,6 @@ QStringRef QStringRef::appendTo(QString *string) const If \a cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive. - - \sa qCompareStrings() */ /*! @@ -10233,8 +10222,6 @@ QStringRef QStringRef::appendTo(QString *string) const If \a cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive. - - \sa qCompareStrings() */ /*! @@ -10248,8 +10235,6 @@ QStringRef QStringRef::appendTo(QString *string) const If \a cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive. - - \sa qCompareStrings() */ /*! @@ -10265,8 +10250,6 @@ QStringRef QStringRef::appendTo(QString *string) const otherwise the comparison is case insensitive. Equivalent to \c {compare(*this, other, cs)}. - - \sa qCompareStrings() */ /*! @@ -10282,8 +10265,6 @@ QStringRef QStringRef::appendTo(QString *string) const otherwise the comparison is case insensitive. Equivalent to \c {compare(*this, other, cs)}. - - \sa qCompareStrings() */ /*! @@ -10299,8 +10280,6 @@ QStringRef QStringRef::appendTo(QString *string) const otherwise the comparison is case insensitive. Equivalent to \c {compare(*this, other, cs)}. - - \sa qCompareStrings() */ /*! @@ -10317,8 +10296,6 @@ QStringRef QStringRef::appendTo(QString *string) const otherwise the comparison is case insensitive. Equivalent to \c {compare(*this, other, cs)}. - - \sa qCompareStrings() */ /*! @@ -11107,14 +11084,15 @@ static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSe } /*! - \fn bool qStartsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qStartsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qStartsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::startsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qStartsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) \since 5.10 + \internal \relates QStringView Returns \c true if \a haystack starts with \a needle, @@ -11123,25 +11101,25 @@ static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSe If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa qEndsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() + \sa QtPrivate::endsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() */ -bool qStartsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_starts_with_impl(haystack, needle, cs); } -bool qStartsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_starts_with_impl(haystack, needle, cs); } -bool qStartsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_starts_with_impl(haystack, needle, cs); } -bool qStartsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_starts_with_impl(haystack, needle, cs); } @@ -11179,14 +11157,15 @@ static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSens } /*! - \fn bool qEndsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qEndsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qEndsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::endsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) \since 5.10 - \fn bool qEndsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \fn bool QtPrivate::endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) \since 5.10 + \internal \relates QStringView Returns \c true if \a haystack ends with \a needle, @@ -11195,25 +11174,25 @@ static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSens If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; otherwise the search is case-insensitive. - \sa qEndsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() + \sa QtPrivate::startsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() */ -bool qEndsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_ends_with_impl(haystack, needle, cs); } -bool qEndsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_ends_with_impl(haystack, needle, cs); } -bool qEndsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_ends_with_impl(haystack, needle, cs); } -bool qEndsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +bool QtPrivate::endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { return qt_ends_with_impl(haystack, needle, cs); } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index b38c7536b7..fe7e9b050b 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -113,22 +113,22 @@ public: Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QLatin1Char back() const { return at(size() - 1); } Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qStartsWith(*this, s, cs); } + { return QtPrivate::startsWith(*this, s, cs); } Q_REQUIRED_RESULT bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qStartsWith(*this, s, cs); } + { return QtPrivate::startsWith(*this, s, cs); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool startsWith(QChar c) const Q_DECL_NOTHROW { return !isEmpty() && front() == c; } Q_REQUIRED_RESULT inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW - { return qStartsWith(*this, QStringView(&c, 1), cs); } + { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qEndsWith(*this, s, cs); } + { return QtPrivate::endsWith(*this, s, cs); } Q_REQUIRED_RESULT bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qEndsWith(*this, s, cs); } + { return QtPrivate::endsWith(*this, s, cs); } Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool endsWith(QChar c) const Q_DECL_NOTHROW { return !isEmpty() && back() == c; } Q_REQUIRED_RESULT inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW - { return qEndsWith(*this, QStringView(&c, 1), cs); } + { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } using value_type = const char; using reference = value_type&; @@ -167,7 +167,7 @@ public: Q_DECL_RELAXED_CONSTEXPR void truncate(int n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; } - Q_REQUIRED_RESULT QLatin1String trimmed() const Q_DECL_NOTHROW { return qTrimmed(*this); } + Q_REQUIRED_RESULT QLatin1String trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); } inline bool operator==(const QString &s) const Q_DECL_NOTHROW; inline bool operator!=(const QString &s) const Q_DECL_NOTHROW; @@ -205,9 +205,9 @@ typedef QLatin1String QLatin1Literal; // QStringView members that require QLatin1String: // bool QStringView::startsWith(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return qStartsWith(*this, s, cs); } +{ return QtPrivate::startsWith(*this, s, cs); } bool QStringView::endsWith(QLatin1String s, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW -{ return qEndsWith(*this, s, cs); } +{ return QtPrivate::endsWith(*this, s, cs); } class Q_CORE_EXPORT QString { @@ -390,7 +390,7 @@ public: bool startsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qStartsWith(*this, s, cs); } + { return QtPrivate::startsWith(*this, s, cs); } bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -399,7 +399,7 @@ public: bool endsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qEndsWith(*this, s, cs); } + { return QtPrivate::endsWith(*this, s, cs); } bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -1485,7 +1485,7 @@ public: bool isRightToLeft() const; Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qStartsWith(*this, s, cs); } + { return QtPrivate::startsWith(*this, s, cs); } bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_STRINGVIEW_LEVEL < 2 @@ -1494,7 +1494,7 @@ public: #endif Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qEndsWith(*this, s, cs); } + { return QtPrivate::endsWith(*this, s, cs); } bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_STRINGVIEW_LEVEL < 2 @@ -1715,12 +1715,12 @@ inline bool operator<=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(r inline bool operator>=(QLatin1String lhs, QChar rhs) Q_DECL_NOTHROW { return !(rhs > lhs); } // QStringView <> QStringView -inline bool operator==(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && qCompareStrings(lhs, rhs) == 0; } +inline bool operator==(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } inline bool operator!=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) < 0; } -inline bool operator<=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) <= 0; } -inline bool operator> (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) > 0; } -inline bool operator>=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) >= 0; } +inline bool operator< (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QStringView lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } // QStringView <> QChar inline bool operator==(QStringView lhs, QChar rhs) Q_DECL_NOTHROW { return lhs == QStringView(&rhs, 1); } @@ -1738,19 +1738,19 @@ inline bool operator> (QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStri inline bool operator>=(QChar lhs, QStringView rhs) Q_DECL_NOTHROW { return QStringView(&lhs, 1) >= rhs; } // QStringView <> QLatin1String -inline bool operator==(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && qCompareStrings(lhs, rhs) == 0; } +inline bool operator==(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } inline bool operator!=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) < 0; } -inline bool operator<=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) <= 0; } -inline bool operator> (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) > 0; } -inline bool operator>=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) >= 0; } +inline bool operator< (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QStringView lhs, QLatin1String rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } -inline bool operator==(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && qCompareStrings(lhs, rhs) == 0; } +inline bool operator==(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return lhs.size() == rhs.size() && QtPrivate::compareStrings(lhs, rhs) == 0; } inline bool operator!=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return !(lhs == rhs); } -inline bool operator< (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) < 0; } -inline bool operator<=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) <= 0; } -inline bool operator> (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) > 0; } -inline bool operator>=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return qCompareStrings(lhs, rhs) >= 0; } +inline bool operator< (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) < 0; } +inline bool operator<=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) <= 0; } +inline bool operator> (QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) > 0; } +inline bool operator>=(QLatin1String lhs, QStringView rhs) Q_DECL_NOTHROW { return QtPrivate::compareStrings(lhs, rhs) >= 0; } #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) // QStringRef <> QByteArray diff --git a/src/corelib/tools/qstringalgorithms.h b/src/corelib/tools/qstringalgorithms.h index eaa7207bec..336da87468 100644 --- a/src/corelib/tools/qstringalgorithms.h +++ b/src/corelib/tools/qstringalgorithms.h @@ -53,31 +53,35 @@ class QLatin1String; class QStringView; template class QVector; +namespace QtPrivate { + Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION qssize_t qustrlen(const ushort *str) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int qCompareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QStringView lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QStringView rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION int compareStrings(QLatin1String lhs, QLatin1String rhs, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; + +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool startsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qStartsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qStartsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qStartsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qStartsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool endsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qEndsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qEndsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qEndsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool qEndsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView trimmed(QStringView s) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String trimmed(QLatin1String s) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QStringView qTrimmed(QStringView s) Q_DECL_NOTHROW; -Q_REQUIRED_RESULT Q_CORE_EXPORT Q_DECL_PURE_FUNCTION QLatin1String qTrimmed(QLatin1String s) Q_DECL_NOTHROW; +Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLatin1(QStringView str); +Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToUtf8(QStringView str); +Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray convertToLocal8Bit(QStringView str); +Q_REQUIRED_RESULT Q_CORE_EXPORT QVector convertToUcs4(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray qConvertToLatin1(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray qConvertToUtf8(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QByteArray qConvertToLocal8Bit(QStringView str); -Q_REQUIRED_RESULT Q_CORE_EXPORT QVector qConvertToUcs4(QStringView str); +} // namespace QtPRivate QT_END_NAMESPACE diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 764da71d0b..14405f325d 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -154,11 +154,11 @@ private: ++result; } #endif - return qustrlen(reinterpret_cast(str)); + return QtPrivate::qustrlen(reinterpret_cast(str)); } static qssize_t lengthHelperPointer(const QChar *str) Q_DECL_NOTHROW { - return qustrlen(reinterpret_cast(str)); + return QtPrivate::qustrlen(reinterpret_cast(str)); } template @@ -224,9 +224,9 @@ public: // QString API // - Q_REQUIRED_RESULT QByteArray toLatin1() const { return qConvertToLatin1(*this); } - Q_REQUIRED_RESULT QByteArray toUtf8() const { return qConvertToUtf8(*this); } - Q_REQUIRED_RESULT QByteArray toLocal8Bit() const { return qConvertToLocal8Bit(*this); } + Q_REQUIRED_RESULT QByteArray toLatin1() const { return QtPrivate::convertToLatin1(*this); } + Q_REQUIRED_RESULT QByteArray toUtf8() const { return QtPrivate::convertToUtf8(*this); } + Q_REQUIRED_RESULT QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); } Q_REQUIRED_RESULT inline QVector toUcs4() const; // defined in qvector.h Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar at(qssize_t n) const { return (*this)[n]; } @@ -247,23 +247,23 @@ public: Q_DECL_RELAXED_CONSTEXPR void chop(qssize_t n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } - Q_REQUIRED_RESULT QStringView trimmed() const Q_DECL_NOTHROW { return qTrimmed(*this); } + Q_REQUIRED_RESULT QStringView trimmed() const Q_DECL_NOTHROW { return QtPrivate::trimmed(*this); } Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qStartsWith(*this, s, cs); } + { return QtPrivate::startsWith(*this, s, cs); } Q_REQUIRED_RESULT inline bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; Q_REQUIRED_RESULT bool startsWith(QChar c) const Q_DECL_NOTHROW { return !empty() && front() == c; } Q_REQUIRED_RESULT bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW - { return qStartsWith(*this, QStringView(&c, 1), cs); } + { return QtPrivate::startsWith(*this, QStringView(&c, 1), cs); } Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW - { return qEndsWith(*this, s, cs); } + { return QtPrivate::endsWith(*this, s, cs); } Q_REQUIRED_RESULT inline bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW; Q_REQUIRED_RESULT bool endsWith(QChar c) const Q_DECL_NOTHROW { return !empty() && back() == c; } Q_REQUIRED_RESULT bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW - { return qEndsWith(*this, QStringView(&c, 1), cs); } + { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } // // STL compatibility API: diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index f00cecbc83..4daf894887 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -1004,7 +1004,7 @@ Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector; Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector; #endif -QVector QStringView::toUcs4() const { return qConvertToUcs4(*this); } +QVector QStringView::toUcs4() const { return QtPrivate::convertToUcs4(*this); } QT_END_NAMESPACE -- cgit v1.2.3 From fb5976038162d93d60c7f76376bbb4df38e83ba9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Sep 2017 00:02:16 -0700 Subject: Fix GCC -Wfloat-conversion warnings (available since GCC 4.9) This warning used to be part of -Wconversion, but that generates too more noise than we're willing to fix now (like conversion from qint64 to int). The float conversion does trigger for conversion from double to float, as shown in all the QVectorND uses of float, but more importantly, it triggers on passing floats to ints. Change-Id: I69f37f9304f24709a823fffd14e69cfd33f75988 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/global/qfloat16.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 89a62a93db..10598adb1d 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -167,7 +167,8 @@ inline qfloat16 operator/(qfloat16 a, qfloat16 b) Q_DECL_NOTHROW { return qfloat inline FP operator OP(qfloat16 lhs, FP rhs) Q_DECL_NOTHROW { return static_cast(lhs) OP rhs; } \ inline FP operator OP(FP lhs, qfloat16 rhs) Q_DECL_NOTHROW { return lhs OP static_cast(rhs); } #define QF16_MAKE_ARITH_OP_EQ_FP(FP, OP_EQ, OP) \ - inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) Q_DECL_NOTHROW { lhs = qfloat16(static_cast(lhs) OP rhs); return lhs; } + inline qfloat16& operator OP_EQ(qfloat16& lhs, FP rhs) Q_DECL_NOTHROW \ + { lhs = qfloat16(float(static_cast(lhs) OP rhs)); return lhs; } #define QF16_MAKE_ARITH_OP(FP) \ QF16_MAKE_ARITH_OP_FP(FP, +) \ QF16_MAKE_ARITH_OP_FP(FP, -) \ -- cgit v1.2.3 From ea0e868c4881944207e9b3a77011e05a505ff3b7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 24 Oct 2017 13:48:15 -0700 Subject: QFileSystemEngine: Fix renameat2() failures on non-local filesystems The RENAME_NOREPLACE flag is supported for all Linux local filesystems, since that can be easily checked by the VFS layer (it knows which files exist and which ones don't). For non-local filesystems, the backend needs support and that might need server-side support too. So we may get EINVAL errors for those, in which case we fall back to link/unlink, which in turn can fall back to rename(). EINVAL can also happen if we attempt to make a directory a subdirectory of itself. In that case, we will attempt to link() it, which will result in EPERM as we can't hardlink directories. Then we try rename() again, which should result in the expected EINVAL. Task-number: QTBUG-64008 Change-Id: Icaa86fc7b54d4b368c0efffd14f09ca23602dd2e Reviewed-by: Oswald Buddenhagen Reviewed-by: Edward Welbourne --- src/corelib/io/qfilesystemengine_unix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 52512c5e13..d77cdc123c 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1261,7 +1261,8 @@ bool QFileSystemEngine::renameFile(const QFileSystemEntry &source, const QFileSy // If we're using syscall(), check for ENOSYS; // if renameat2 came from libc, we don't accept ENOSYS. - if (QT_CONFIG(renameat2) || errno != ENOSYS) { + // We can also get EINVAL for some non-local filesystems. + if ((QT_CONFIG(renameat2) || errno != ENOSYS) && errno != EINVAL) { error = QSystemError(errno, QSystemError::StandardLibraryError); return false; } -- cgit v1.2.3