diff options
Diffstat (limited to 'src/corelib')
62 files changed, 1052 insertions, 555 deletions
diff --git a/src/corelib/Qt5Config.cmake.in b/src/corelib/Qt5Config.cmake.in index a872d0e917..75b53485b7 100644 --- a/src/corelib/Qt5Config.cmake.in +++ b/src/corelib/Qt5Config.cmake.in @@ -22,18 +22,24 @@ get_filename_component(_qt5_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/..\" ABSO set(_Qt5_NOTFOUND_MESSAGE) +include(${CMAKE_CURRENT_LIST_DIR}/Qt5ModuleLocation.cmake) + foreach(module ${Qt5_FIND_COMPONENTS}) find_package(Qt5${module} ${_Qt5_FIND_PARTS_QUIET} ${_Qt5_FIND_PARTS_REQUIRED} - PATHS \"${_qt5_install_prefix}\" NO_DEFAULT_PATH + PATHS ${_qt5_module_paths} NO_DEFAULT_PATH ) if (NOT Qt5${module}_FOUND) + string(CONFIGURE ${_qt5_module_location_template} _expected_module_location @ONLY) + if (Qt5_FIND_REQUIRED_${module}) - set(_Qt5_NOTFOUND_MESSAGE \"${_Qt5_NOTFOUND_MESSAGE}Failed to find Qt5 component \\\"${module}\\\" config file at \\\"${_qt5_install_prefix}/Qt5${module}/Qt5${module}Config.cmake\\\"\\n\") + set(_Qt5_NOTFOUND_MESSAGE \"${_Qt5_NOTFOUND_MESSAGE}Failed to find Qt5 component \\\"${module}\\\" config file at \\\"${_expected_module_location}\\\"\\n\") elseif(NOT Qt5_FIND_QUIETLY) - message(WARNING \"Failed to find Qt5 component \\\"${module}\\\" config file at \\\"${_qt5_install_prefix}/Qt5${module}/Qt5${module}Config.cmake\\\"\") + message(WARNING \"Failed to find Qt5 component \\\"${module}\\\" config file at \\\"${_expected_module_location}\\\"\") endif() + + unset(_expected_module_location) endif() endforeach() diff --git a/src/corelib/Qt5ModuleLocation.cmake.in b/src/corelib/Qt5ModuleLocation.cmake.in new file mode 100644 index 0000000000..5065ada56e --- /dev/null +++ b/src/corelib/Qt5ModuleLocation.cmake.in @@ -0,0 +1,15 @@ +!!IF !isEmpty(_QMAKE_SUPER_CACHE_) +get_filename_component(_qt5_root_dir \"${CMAKE_CURRENT_LIST_DIR}/../../../..\" ABSOLUTE) + +file(GLOB qtmodules ${_qt5_root_dir} "${_qt5_root_dir}/*") +foreach(qtmodule ${qtmodules}) + if(IS_DIRECTORY ${qtmodule}) + list(APPEND _qt5_module_paths ${qtmodule}) + endif() +endforeach() +!!ELSE +set(_qt5_root_dir ${_qt5_install_prefix}) +set(_qt5_module_paths ${_qt5_install_prefix}) +!!ENDIF + +set(_qt5_module_location_template ${_qt5_root_dir}) diff --git a/src/corelib/Qt5ModuleLocationForInstall.cmake.in b/src/corelib/Qt5ModuleLocationForInstall.cmake.in new file mode 100644 index 0000000000..e401b1fe34 --- /dev/null +++ b/src/corelib/Qt5ModuleLocationForInstall.cmake.in @@ -0,0 +1,4 @@ +set(_qt5_root_dir ${_qt5_install_prefix}) +set(_qt5_module_paths ${_qt5_install_prefix}) + +set(_qt5_module_location_template ${_qt5_install_prefix}/Qt5@module@/Qt5@module@Config.cmake) diff --git a/src/corelib/codecs/codecs.pri b/src/corelib/codecs/codecs.pri index 4fa778d042..dc8974d13f 100644 --- a/src/corelib/codecs/codecs.pri +++ b/src/corelib/codecs/codecs.pri @@ -43,12 +43,8 @@ qtConfig(icu) { qtConfig(iconv) { HEADERS += codecs/qiconvcodec_p.h SOURCES += codecs/qiconvcodec.cpp - qtConfig(gnu-libiconv) { - DEFINES += GNU_LIBICONV + qtConfig(gnu-libiconv): \ QMAKE_USE_PRIVATE += iconv - } else: qtConfig(sun-libiconv) { - DEFINES += GNU_LIBICONV - } } win32 { diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp index 845155dce0..e4fb359f2c 100644 --- a/src/corelib/codecs/qiconvcodec.cpp +++ b/src/corelib/codecs/qiconvcodec.cpp @@ -37,7 +37,9 @@ ** ****************************************************************************/ -#ifndef QT_NO_ICONV +#include <QtCore/private/qglobal_p.h> + +QT_REQUIRE_CONFIG(iconv); #include "qiconvcodec_p.h" #include "qtextcodec_p.h" @@ -62,7 +64,7 @@ #elif defined(Q_OS_AIX) # define NO_BOM # define UTF16 "UCS-2" -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC) +#elif defined(Q_OS_FREEBSD) # define NO_BOM # if Q_BYTE_ORDER == Q_BIG_ENDIAN # define UTF16 "UTF-16BE" @@ -73,19 +75,6 @@ # define UTF16 "UTF-16" #endif -#if defined(Q_OS_MAC) -#ifndef GNU_LIBICONV -#define GNU_LIBICONV -#endif -typedef iconv_t (*Ptr_iconv_open) (const char*, const char*); -typedef size_t (*Ptr_iconv) (iconv_t, const char **, size_t *, char **, size_t *); -typedef int (*Ptr_iconv_close) (iconv_t); - -static Ptr_iconv_open ptr_iconv_open = 0; -static Ptr_iconv ptr_iconv = 0; -static Ptr_iconv_close ptr_iconv_close = 0; -#endif - QT_BEGIN_NAMESPACE QIconvCodec::QIconvCodec() @@ -103,33 +92,6 @@ void QIconvCodec::init() const fprintf(stderr, "QIconvCodec::convertToUnicode: internal error, UTF-16 codec not found\n"); utf16Codec = reinterpret_cast<QTextCodec *>(~0); } -#if defined(Q_OS_MAC) - if (ptr_iconv_open == 0) { - QLibrary libiconv(QLatin1String("/usr/lib/libiconv")); - libiconv.setLoadHints(QLibrary::ExportExternalSymbolsHint); - - ptr_iconv_open = reinterpret_cast<Ptr_iconv_open>(libiconv.resolve("libiconv_open")); - if (!ptr_iconv_open) - ptr_iconv_open = reinterpret_cast<Ptr_iconv_open>(libiconv.resolve("iconv_open")); - ptr_iconv = reinterpret_cast<Ptr_iconv>(libiconv.resolve("libiconv")); - if (!ptr_iconv) - ptr_iconv = reinterpret_cast<Ptr_iconv>(libiconv.resolve("iconv")); - ptr_iconv_close = reinterpret_cast<Ptr_iconv_close>(libiconv.resolve("libiconv_close")); - if (!ptr_iconv_close) - ptr_iconv_close = reinterpret_cast<Ptr_iconv_close>(libiconv.resolve("iconv_close")); - - Q_ASSERT_X(ptr_iconv_open && ptr_iconv && ptr_iconv_close, - "QIconvCodec::QIconvCodec()", - "internal error, could not resolve the iconv functions"); - -# undef iconv_open -# define iconv_open ptr_iconv_open -# undef iconv -# define iconv ptr_iconv -# undef iconv_close -# define iconv_close ptr_iconv_close - } -#endif } QIconvCodec::~QIconvCodec() @@ -221,7 +183,7 @@ QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState IconvState *state = *pstate; size_t inBytesLeft = len; // best case assumption, each byte is converted into one UTF-16 character, plus 2 bytes for the BOM -#ifdef GNU_LIBICONV +#if !QT_CONFIG(posix_libiconv) // GNU doesn't disagree with POSIX :/ const char *inBytes = chars; #else @@ -320,7 +282,7 @@ static bool setByteOrder(iconv_t cd) size_t outBytesLeft = sizeof buf; size_t inBytesLeft = sizeof bom; -#if defined(GNU_LIBICONV) +#if !QT_CONFIG(posix_libiconv) const char **inBytesPtr = const_cast<const char **>(&inBytes); #else char **inBytesPtr = &inBytes; @@ -342,7 +304,7 @@ QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt char *outBytes; size_t inBytesLeft; -#if defined(GNU_LIBICONV) +#if !QT_CONFIG(posix_libiconv) const char **inBytesPtr = const_cast<const char **>(&inBytes); #else char **inBytesPtr = &inBytes; @@ -472,7 +434,7 @@ iconv_t QIconvCodec::createIconv_t(const char *to, const char *from) const init(); iconv_t cd = (iconv_t) -1; -#if defined(__GLIBC__) || defined(GNU_LIBICONV) || defined(Q_OS_QNX) +#if defined(__GLIBC__) || !QT_CONFIG(posix_libiconv) || defined(Q_OS_QNX) #if defined(Q_OS_QNX) // on QNX the default locale is UTF-8, and an empty string will cause iconv_open to fail static const char empty_codeset[] = "UTF-8"; @@ -562,5 +524,3 @@ iconv_t QIconvCodec::createIconv_t(const char *to, const char *from) const } QT_END_NAMESPACE - -#endif /* #ifndef QT_NO_ICONV */ diff --git a/src/corelib/codecs/qiconvcodec_p.h b/src/corelib/codecs/qiconvcodec_p.h index 238351bc81..9b8500538b 100644 --- a/src/corelib/codecs/qiconvcodec_p.h +++ b/src/corelib/codecs/qiconvcodec_p.h @@ -54,13 +54,9 @@ #include <QtCore/private/qglobal_p.h> #include "qtextcodec.h" -#if defined(Q_OS_UNIX) && !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED) +QT_REQUIRE_CONFIG(iconv); -#ifdef Q_OS_MAC -typedef void * iconv_t; -#else #include <iconv.h> -#endif QT_BEGIN_NAMESPACE @@ -100,6 +96,4 @@ public: QT_END_NAMESPACE -#endif // Q_OS_UNIX && !QT_NO_ICONV && !QT_BOOTSTRAPPED - #endif // QICONVCODEC_P_H diff --git a/src/corelib/codecs/qsimplecodec_p.h b/src/corelib/codecs/qsimplecodec_p.h index d268a9f5b8..188c3f3cb4 100644 --- a/src/corelib/codecs/qsimplecodec_p.h +++ b/src/corelib/codecs/qsimplecodec_p.h @@ -67,12 +67,12 @@ public: explicit QSimpleTextCodec(int); ~QSimpleTextCodec(); - QString convertToUnicode(const char *, int, ConverterState *) const; - QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const; + QString convertToUnicode(const char *, int, ConverterState *) const override; + QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const override; - QByteArray name() const; - QList<QByteArray> aliases() const; - int mibEnum() const; + QByteArray name() const override; + QList<QByteArray> aliases() const override; + int mibEnum() const override; private: int forwardIndex; diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 5098ac4242..aed3532024 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -58,10 +58,10 @@ #if !defined(QT_BOOTSTRAPPED) # include "qtsciicodec_p.h" # include "qisciicodec_p.h" -#if defined(QT_USE_ICU) +#if QT_CONFIG(icu) #include "qicucodec_p.h" #else -#if !defined(QT_NO_ICONV) +#if QT_CONFIG(iconv) # include "qiconvcodec_p.h" #endif #ifdef Q_OS_WIN @@ -79,7 +79,7 @@ # endif // !Q_OS_INTEGRITY #endif // !QT_NO_BIG_CODECS -#endif // QT_USE_ICU +#endif // icu #endif // QT_BOOTSTRAPPED #include "qmutex.h" @@ -99,7 +99,7 @@ typedef QList<QByteArray>::ConstIterator ByteArrayListConstIt; Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive)); QMutex *qTextCodecsMutex() { return textCodecsMutex(); } -#if !defined(QT_USE_ICU) +#if !QT_CONFIG(icu) static char qtolower(char c) { if (c >= 'A' && c <= 'Z') return c + 0x20; return c; } static bool qisalnum(char c) @@ -184,7 +184,7 @@ static QTextCodec *setupLocaleMapper() if (charset) locale = QTextCodec::codecForName(charset); #endif -#if !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED) +#if QT_CONFIG(iconv) if (!locale) { // no builtin codec for the locale found, let's try using iconv (void) new QIconvCodec(); @@ -286,7 +286,7 @@ static void setup() (void)new QBig5Codec; (void)new QBig5hkscsCodec; # endif // !QT_NO_BIG_CODECS && !Q_OS_INTEGRITY -#if !defined(QT_NO_ICONV) +#if QT_CONFIG(iconv) (void) new QIconvCodec; #endif #if defined(Q_OS_WIN32) @@ -306,7 +306,7 @@ static void setup() } #else static void setup() {} -#endif // QT_USE_ICU +#endif // icu /*! \enum QTextCodec::ConversionFlag @@ -519,7 +519,7 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name) return 0; setup(); -#ifndef QT_USE_ICU +#if !QT_CONFIG(icu) QTextCodecCache *cache = &globalData->codecCache; QTextCodec *codec; if (cache) { @@ -586,7 +586,7 @@ QTextCodec* QTextCodec::codecForMib(int mib) } } -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return QIcuCodec::codecForMibUnlocked(mib); #else return 0; @@ -618,7 +618,7 @@ QList<QByteArray> QTextCodec::availableCodecs() codecs += (*it)->aliases(); } -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) codecs += QIcuCodec::availableCodecs(); #endif @@ -634,7 +634,7 @@ QList<QByteArray> QTextCodec::availableCodecs() */ QList<int> QTextCodec::availableMibs() { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return QIcuCodec::availableMibs(); #else QMutexLocker locker(textCodecsMutex()); @@ -688,7 +688,7 @@ QTextCodec* QTextCodec::codecForLocale() QTextCodec *codec = globalData->codecForLocale.loadAcquire(); if (!codec) { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) textCodecsMutex()->lock(); codec = QIcuCodec::defaultCodecUnlocked(); textCodecsMutex()->unlock(); diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 02e82d686b..f4162956d3 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -245,21 +245,21 @@ "label": "iconv", "purpose": "Provides internationalization on Unix.", "section": "Internationalization", - "condition": "features.posix-libiconv || features.sun-libiconv || features.gnu-libiconv", + "condition": "!features.icu && (features.posix-libiconv || features.sun-libiconv || features.gnu-libiconv)", "output": [ "privateFeature", "feature" ] }, "posix-libiconv": { "label": "POSIX iconv", "enable": "input.iconv == 'posix'", "disable": "input.iconv == 'sun' || input.iconv == 'gnu' || input.iconv == 'no'", - "condition": "!config.win32 && !config.qnx && !config.android && !config.darwin && tests.posix-iconv" + "condition": "!config.win32 && !config.qnx && !config.android && !config.darwin && tests.posix-iconv", + "output": [ "privateFeature" ] }, "sun-libiconv": { "label": "SUN iconv", "enable": "input.iconv == 'sun'", "disable": "input.iconv == 'posix' || input.iconv == 'gnu' || input.iconv == 'no'", - "condition": "!config.win32 && !config.qnx && !config.android && !config.darwin && !features.posix-libiconv && tests.sun-iconv", - "output": [ "privateFeature", "publicQtConfig" ] + "condition": "!config.win32 && !config.qnx && !config.android && !config.darwin && !features.posix-libiconv && tests.sun-iconv" }, "gnu-libiconv": { "label": "GNU iconv", @@ -289,7 +289,7 @@ "label": "journald", "autoDetect": false, "condition": "libs.journald", - "output": [ "privateConfig" ] + "output": [ "privateFeature" ] }, "std-atomic64": { "label": "64 bit atomic operations", @@ -355,27 +355,16 @@ "condition": "features.statemachine", "output": [ "publicFeature" ] }, - "sharedmemory": { - "label": "Enable QSharedMemory", - "condition": "config.android || config.win32 || tests.ipc_sysv || tests.ipc_posix", - "output": [ { "type": "define", "negative": true, "name": "QT_NO_SHAREDMEMORY" } ] - }, "slog2": { "label": "slog2", "condition": "libs.slog2", - "emitIf": "config.qnx", - "output": [ "privateConfig" ] + "output": [ "privateFeature" ] }, "syslog": { "label": "syslog", "autoDetect": false, "condition": "tests.syslog", - "output": [ "privateConfig" ] - }, - "systemsemaphore": { - "label": "Enable QSystemSemaphore", - "condition": "config.android || config.win32 || tests.ipc_sysv || tests.ipc_posix", - "output": [ { "type": "define", "negative": true, "name": "QT_NO_SYSTEMSEMAPHORE" } ] + "output": [ "privateFeature" ] }, "threadsafe-cloexec": { "label": "Threadsafe pipe creation", @@ -401,12 +390,19 @@ "label": "QSharedMemory", "purpose": "Provides access to a shared memory segment.", "section": "Kernel", + "condition": [ + "config.android || config.win32 || (!config.vxworks && (tests.ipc_sysv || tests.ipc_posix))" + ], "output": [ "publicFeature", "feature" ] }, "systemsemaphore": { "label": "QSystemSemaphore", "purpose": "Provides a general counting system semaphore.", "section": "Kernel", + "condition": [ + "!config.integrity && !config.vxworks", + "config.android || config.win32 || tests.ipc_sysv || tests.ipc_posix" + ], "output": [ "publicFeature", "feature" ] }, "xmlstream": { @@ -446,6 +442,7 @@ "label": "QProcess", "purpose": "Supports external process invocation.", "section": "File I/O", + "condition": "!config.winrt && !config.uikit && !config.integrity && !config.vxworks", "output": [ "publicFeature", "feature" ] }, "temporaryfile": { @@ -470,6 +467,7 @@ "label": "QFileSystemWatcher", "purpose": "Provides an interface for monitoring files and directories for modifications.", "section": "File I/O", + "condition": "!config.winrt", "output": [ "publicFeature", "feature" ] }, "filesystemiterator": { diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index 616a9641a1..0bd7c9b99d 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -93,6 +93,12 @@ ctest_macros_file.CONFIG = verbatim cmake_umbrella_config_file.input = $$PWD/Qt5Config.cmake.in cmake_umbrella_config_file.output = $$DESTDIR/cmake/Qt5/Qt5Config.cmake +cmake_umbrella_config_module_location.input = $$PWD/Qt5ModuleLocation.cmake.in +cmake_umbrella_config_module_location.output = $$DESTDIR/cmake/Qt5/Qt5ModuleLocation.cmake + +cmake_umbrella_config_module_location_for_install.input = $$PWD/Qt5ModuleLocationForInstall.cmake.in +cmake_umbrella_config_module_location_for_install.output = $$DESTDIR/cmake/install/Qt5/Qt5ModuleLocation.cmake + cmake_umbrella_config_version_file.input = $$PWD/../../mkspecs/features/data/cmake/Qt5ConfigVersion.cmake.in cmake_umbrella_config_version_file.output = $$DESTDIR/cmake/Qt5/Qt5ConfigVersion.cmake @@ -119,10 +125,21 @@ contains(CMAKE_INSTALL_DATA_DIR, "^\\.\\./.*"):!isEmpty(CMAKE_INSTALL_DATA_DIR) cmake_extras_mkspec_dir_for_install.input = $$PWD/Qt5CoreConfigExtrasMkspecDirForInstall.cmake.in cmake_extras_mkspec_dir_for_install.output = $$DESTDIR/cmake/install/Qt5Core/Qt5CoreConfigExtrasMkspecDir.cmake -cmake_qt5_umbrella_module_files.files = $$cmake_umbrella_config_file.output $$cmake_umbrella_config_version_file.output +cmake_qt5_umbrella_module_files.files = \ + $$cmake_umbrella_config_file.output \ + $$cmake_umbrella_config_version_file.output \ + $$cmake_umbrella_config_module_location_for_install.output + cmake_qt5_umbrella_module_files.path = $$[QT_INSTALL_LIBS]/cmake/Qt5 -QMAKE_SUBSTITUTES += ctest_macros_file cmake_umbrella_config_file cmake_umbrella_config_version_file cmake_extras_mkspec_dir cmake_extras_mkspec_dir_for_install +QMAKE_SUBSTITUTES += \ + ctest_macros_file \ + cmake_umbrella_config_file \ + cmake_umbrella_config_module_location \ + cmake_umbrella_config_module_location_for_install \ + cmake_umbrella_config_version_file \ + cmake_extras_mkspec_dir \ + cmake_extras_mkspec_dir_for_install ctest_qt5_module_files.files += $$ctest_macros_file.output $$cmake_extras_mkspec_dir_for_install.output diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index bd2e125006..d23706e631 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -53,19 +53,11 @@ if(linux*|hurd*):!cross_compile:!static:!*-armcc* { DEFINES += ELF_INTERPRETER=\\\"$$system(LC_ALL=C readelf -l /bin/ls | perl -n -e \'$$prog\')\\\" } -slog2 { +qtConfig(slog2): \ LIBS_PRIVATE += -lslog2 - DEFINES += QT_USE_SLOG2 -} -journald { +qtConfig(journald): \ QMAKE_USE_PRIVATE += journald - DEFINES += QT_USE_JOURNALD -} - -syslog { - DEFINES += QT_USE_SYSLOG -} gcc:ltcg { versiontagging_compiler.commands = $$QMAKE_CXX -c $(CXXFLAGS) $(INCPATH) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 0b2345f8d4..d978c141a4 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -986,6 +986,9 @@ # define Q_COMPILER_THREADSAFE_STATICS # define Q_COMPILER_UNIFORM_INIT # endif +# if _MSC_VER >= 1910 +# define Q_COMPILER_CONSTEXPR +# endif # endif /* __cplusplus */ #endif /* Q_CC_MSVC */ @@ -1270,6 +1273,7 @@ # define QT_WARNING_DISABLE_INTEL(number) __pragma(warning(disable: number)) # define QT_WARNING_DISABLE_CLANG(text) # define QT_WARNING_DISABLE_GCC(text) +# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_INTEL(1786) #elif defined(Q_CC_INTEL) /* icc: Intel compiler on Linux or OS X */ # define QT_WARNING_PUSH QT_DO_PRAGMA(warning(push)) @@ -1278,6 +1282,7 @@ # define QT_WARNING_DISABLE_MSVC(number) # define QT_WARNING_DISABLE_CLANG(text) # define QT_WARNING_DISABLE_GCC(text) +# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_INTEL(1786) #elif defined(Q_CC_MSVC) && _MSC_VER >= 1500 && !defined(Q_CC_CLANG) # undef QT_DO_PRAGMA /* not needed */ # define QT_WARNING_PUSH __pragma(warning(push)) @@ -1286,6 +1291,7 @@ # define QT_WARNING_DISABLE_INTEL(number) # define QT_WARNING_DISABLE_CLANG(text) # define QT_WARNING_DISABLE_GCC(text) +# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_MSVC(4996) #elif defined(Q_CC_CLANG) # define QT_WARNING_PUSH QT_DO_PRAGMA(clang diagnostic push) # define QT_WARNING_POP QT_DO_PRAGMA(clang diagnostic pop) @@ -1293,6 +1299,7 @@ # define QT_WARNING_DISABLE_GCC(text) # define QT_WARNING_DISABLE_INTEL(number) # define QT_WARNING_DISABLE_MSVC(number) +# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") #elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) # define QT_WARNING_PUSH QT_DO_PRAGMA(GCC diagnostic push) # define QT_WARNING_POP QT_DO_PRAGMA(GCC diagnostic pop) @@ -1300,6 +1307,7 @@ # define QT_WARNING_DISABLE_CLANG(text) # define QT_WARNING_DISABLE_INTEL(number) # define QT_WARNING_DISABLE_MSVC(number) +# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") #else // All other compilers, GCC < 4.6 and MSVC < 2008 # define QT_WARNING_DISABLE_GCC(text) # define QT_WARNING_PUSH @@ -1308,6 +1316,7 @@ # define QT_WARNING_DISABLE_MSVC(number) # define QT_WARNING_DISABLE_CLANG(text) # define QT_WARNING_DISABLE_GCC(text) +# define QT_WARNING_DISABLE_DEPRECATED #endif /* diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index 3b86e94cdd..d0e45478cc 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -68,10 +68,15 @@ #define QT_CRYPTOGRAPHICHASH_ONLY_SHA1 #define QT_NO_DATASTREAM +#define QT_FEATURE_iconv -1 +#define QT_FEATURE_icu -1 +#define QT_FEATURE_journald -1 #define QT_NO_LIBRARY #define QT_FEATURE_library -1 #define QT_NO_QOBJECT #define QT_NO_SYSTEMLOCALE +#define QT_FEATURE_slog2 -1 +#define QT_FEATURE_syslog -1 #define QT_NO_THREAD #define QT_FEATURE_timezone -1 #define QT_FEATURE_topleveldomain -1 diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index e6eee5a1d2..47aca712b7 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1248,6 +1248,12 @@ bool qSharedBuild() Q_DECL_NOTHROW \value MV_TVOS_9_2 tvOS 9.2 \value MV_TVOS_10_0 tvOS 10.0 + \value MV_WATCHOS watchOS (any) + \value MV_WATCHOS_2_0 watchOS 2.0 + \value MV_WATCHOS_2_1 watchOS 2.1 + \value MV_WATCHOS_2_2 watchOS 2.2 + \value MV_WATCHOS_3_0 watchOS 3.0 + \value MV_None Not a Darwin operating system \sa WinVersion diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index f64ab143ef..4354c85bfe 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -621,32 +621,6 @@ private: class QDataStream; -#if defined(Q_OS_VXWORKS) -# define QT_NO_CRASHHANDLER // no popen -# define QT_NO_PROCESS // no exec*, no fork -# define QT_NO_SHAREDMEMORY // only POSIX, no SysV and in the end... -# define QT_NO_SYSTEMSEMAPHORE // not needed at all in a flat address space -#endif - -#if defined(Q_OS_WINRT) -# define QT_NO_FILESYSTEMWATCHER -# define QT_NO_NETWORKPROXY -# define QT_NO_PROCESS -# define QT_NO_SOCKETNOTIFIER -# define QT_NO_SOCKS5 -#endif - -#if defined(QT_PLATFORM_UIKIT) -# define QT_NO_PROCESS -#endif - -#if defined(Q_OS_INTEGRITY) -# define QT_NO_CRASHHANDLER // no popen -# define QT_NO_PROCESS // no exec*, no fork -# define QT_NO_SYSTEMSEMAPHORE // not needed at all in a single AddressSpace -# define QT_NO_MULTIPROCESS // no system -#endif - inline void qt_noop(void) {} /* These wrap try/catch so we can switch off exceptions later. diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 1469f5776b..27fe10a79e 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -318,8 +318,10 @@ QLibraryInfo::buildDate() # define COMPILER_STRING "MSVC 2012" # elif _MSC_VER < 1900 # define COMPILER_STRING "MSVC 2013" -# elif _MSC_VER < 2000 +# elif _MSC_VER < 1910 # define COMPILER_STRING "MSVC 2015" +# elif _MSC_VER < 2000 +# define COMPILER_STRING "MSVC 2017" # else # define COMPILER_STRING "MSVC _MSC_VER " QT_STRINGIFY(_MSC_VER) # endif diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 0ca6829564..0506d372b6 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "qglobal_p.h" #include "qlogging.h" #include "qlist.h" #include "qbytearray.h" @@ -59,7 +60,7 @@ #ifdef Q_OS_WIN #include <qt_windows.h> #endif -#ifdef QT_USE_SLOG2 +#if QT_CONFIG(slog2) #include <slog2.h> #endif @@ -67,12 +68,12 @@ #include <android/log.h> #endif -#if defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) +#if QT_CONFIG(journald) # define SD_JOURNAL_SUPPRESS_LOCATION # include <systemd/sd-journal.h> # include <syslog.h> #endif -#if defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED) +#if QT_CONFIG(syslog) # include <syslog.h> #endif #ifdef Q_OS_UNIX @@ -93,7 +94,7 @@ # endif #endif -#if defined(QT_USE_SLOG2) +#if QT_CONFIG(slog2) extern char *__progname; #endif @@ -1281,7 +1282,7 @@ static QString formatBacktraceForLogMessage(const QMessagePattern::BacktracePara } #endif // QLOGGING_HAVE_BACKTRACE && !QT_BOOTSTRAPPED -#if defined(QT_USE_SLOG2) +#if QT_CONFIG(slog2) #ifndef QT_LOG_CODE #define QT_LOG_CODE 9000 #endif @@ -1330,7 +1331,7 @@ static void slog2_default_handler(QtMsgType msgType, const char *message) //writes to the slog2 buffer slog2c(NULL, QT_LOG_CODE, severity, message); } -#endif // QT_USE_SLOG2 +#endif // slog2 Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) @@ -1479,7 +1480,7 @@ static QBasicAtomicPointer<void (QtMsgType, const char*)> msgHandler = Q_BASIC_A // pointer to QtMessageHandler debug handler (with context) static QBasicAtomicPointer<void (QtMsgType, const QMessageLogContext &, const QString &)> messageHandler = Q_BASIC_ATOMIC_INITIALIZER(qDefaultMessageHandler); -#if defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) +#if QT_CONFIG(journald) static void systemd_default_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &message) @@ -1513,7 +1514,7 @@ static void systemd_default_message_handler(QtMsgType type, } #endif -#ifdef QT_USE_SYSLOG +#if QT_CONFIG(syslog) static void syslog_default_message_handler(QtMsgType type, const char *message) { int priority = LOG_INFO; // Informational @@ -1577,14 +1578,14 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con logMessage.append(QLatin1Char('\n')); OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16())); return; -#elif defined(QT_USE_SLOG2) +#elif QT_CONFIG(slog2) logMessage.append(QLatin1Char('\n')); slog2_default_handler(type, logMessage.toLocal8Bit().constData()); return; -#elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) +#elif QT_CONFIG(journald) systemd_default_message_handler(type, context, logMessage); return; -#elif defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED) +#elif QT_CONFIG(syslog) syslog_default_message_handler(type, logMessage.toUtf8().constData()); return; #elif defined(Q_OS_ANDROID) @@ -1779,7 +1780,7 @@ void qErrnoWarning(int code, const char *msg, ...) \snippet code/src_corelib_global_qglobal.cpp 23 - \sa QtMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), + \sa QtMessageHandler, QtMsgType, qDebug(), qInfo(), qWarning(), qCritical(), qFatal(), {Debugging Techniques} */ diff --git a/src/corelib/io/PSL-LICENSE.txt b/src/corelib/io/PSL-LICENSE.txt new file mode 100644 index 0000000000..d0a1fa1482 --- /dev/null +++ b/src/corelib/io/PSL-LICENSE.txt @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 91953ebf26..437f774547 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -80,6 +80,40 @@ static QString driveSpec(const QString &path) } #endif +enum { +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + OSSupportsUncPaths = true +#else + OSSupportsUncPaths = false +#endif +}; + +// Return the length of the root part of an absolute path, for use by cleanPath(), cd(). +static int rootLength(const QString &name, bool allowUncPaths) +{ + const int len = name.length(); + // starts with double slash + if (allowUncPaths && name.startsWith(QLatin1String("//"))) { + // Server name '//server/path' is part of the prefix. + const int nextSlash = name.indexOf(QLatin1Char('/'), 2); + return nextSlash >= 0 ? nextSlash + 1 : len; + } +#if defined(Q_OS_WINRT) + const QString rootPath = QDir::rootPath(); // rootPath contains the trailing slash + if (name.startsWith(rootPath, Qt::CaseInsensitive)) + return rootPath.size(); +#endif // Q_OS_WINRT +#if defined(Q_OS_WIN) + if (len >= 2 && name.at(1) == QLatin1Char(':')) { + // Handle a possible drive letter + return len > 2 && name.at(2) == QLatin1Char('/') ? 3 : 2; + } +#endif + if (name.at(0) == QLatin1Char('/')) + return 1; + return 0; +} + //************* QDirPrivate QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_) : QSharedData() @@ -859,6 +893,8 @@ QString QDir::fromNativeSeparators(const QString &pathName) return pathName; } +static QString qt_cleanPath(const QString &path, bool *ok = nullptr); + /*! Changes the QDir's directory to \a dirName. @@ -879,32 +915,18 @@ bool QDir::cd(const QString &dirName) return true; QString newPath; if (isAbsolutePath(dirName)) { - newPath = cleanPath(dirName); + newPath = qt_cleanPath(dirName); } else { - if (isRoot()) - newPath = d->dirEntry.filePath(); - else - newPath = d->dirEntry.filePath() % QLatin1Char('/'); + newPath = d->dirEntry.filePath(); + if (!newPath.endsWith(QLatin1Char('/'))) + newPath += QLatin1Char('/'); newPath += dirName; if (dirName.indexOf(QLatin1Char('/')) >= 0 || dirName == QLatin1String("..") || d->dirEntry.filePath() == QLatin1String(".")) { - newPath = cleanPath(newPath); -#if defined (Q_OS_UNIX) - //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. - if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/..")) -#elif defined (Q_OS_WINRT) - const QString rootPath = QDir::rootPath(); - if (newPath.size() < rootPath.size() && rootPath.startsWith(newPath)) -#else - /* - cleanPath() already took care of replacing '\' with '/'. - We can't use startsWith here because the letter of the drive is unknown. - After cleanPath() if path is "[A-Z]:/.." or starts with "[A-Z]:/../" it means trying to cd above root. - */ - - if (newPath.midRef(1, 4) == QLatin1String(":/..") && (newPath.length() == 5 || newPath.at(5) == QLatin1Char('/'))) -#endif + bool ok; + newPath = qt_cleanPath(newPath, &ok); + if (!ok) return false; /* If newPath starts with .., we convert it to absolute to @@ -2051,10 +2073,14 @@ bool QDir::match(const QString &filter, const QString &fileName) This method is shared with QUrl, so it doesn't deal with QDir::separator(), nor does it remove the trailing slash, if any. */ -Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool allowUncPaths) +Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool allowUncPaths, + bool *ok = nullptr) { const int len = name.length(); + if (ok) + *ok = false; + if (len == 0) return name; @@ -2066,19 +2092,7 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all const QChar *prefix = p; int up = 0; - int prefixLength = 0; - - if (allowUncPaths && len >= 2 && p[1].unicode() == '/' && p[0].unicode() == '/') { - // starts with double slash - prefixLength = 2; -#ifdef Q_OS_WIN - } else if (len >= 2 && p[1].unicode() == ':') { - // remember the drive letter - prefixLength = (len > 2 && p[2].unicode() == '/') ? 3 : 2; -#endif - } else if (p[0].unicode() == '/') { - prefixLength = 1; - } + const int prefixLength = rootLength(name, allowUncPaths); p += prefixLength; i -= prefixLength; @@ -2131,6 +2145,10 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all --up; } + // Indicate failure when ".." are left over for an absolute path. + if (ok) + *ok = prefixLength == 0 || up == 0; + // add remaining '..' while (up) { if (used != len && out[used].unicode() != '/') // is not empty and there isn't already a '/' @@ -2168,32 +2186,16 @@ Q_AUTOTEST_EXPORT QString qt_normalizePathSegments(const QString &name, bool all return ret; } -/*! - Returns \a path with directory separators normalized (converted to "/") and - redundant ones removed, and "."s and ".."s resolved (as far as possible). - - Symbolic links are kept. This function does not return the - canonical path, but rather the simplest version of the input. - For example, "./local" becomes "local", "local/../bin" becomes - "bin" and "/local/usr/../bin" becomes "/local/bin". - - \sa absolutePath(), canonicalPath() -*/ -QString QDir::cleanPath(const QString &path) +static QString qt_cleanPath(const QString &path, bool *ok) { if (path.isEmpty()) return path; QString name = path; - QChar dir_separator = separator(); + QChar dir_separator = QDir::separator(); if (dir_separator != QLatin1Char('/')) name.replace(dir_separator, QLatin1Char('/')); - bool allowUncPaths = false; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //allow unc paths - allowUncPaths = true; -#endif - - QString ret = qt_normalizePathSegments(name, allowUncPaths); + QString ret = qt_normalizePathSegments(name, OSSupportsUncPaths, ok); // Strip away last slash except for root directories if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) { @@ -2211,6 +2213,22 @@ QString QDir::cleanPath(const QString &path) } /*! + Returns \a path with directory separators normalized (converted to "/") and + redundant ones removed, and "."s and ".."s resolved (as far as possible). + + Symbolic links are kept. This function does not return the + canonical path, but rather the simplest version of the input. + For example, "./local" becomes "local", "local/../bin" becomes + "bin" and "/local/usr/../bin" becomes "/local/bin". + + \sa absolutePath(), canonicalPath() +*/ +QString QDir::cleanPath(const QString &path) +{ + return qt_cleanPath(path); +} + +/*! Returns \c true if \a path is relative; returns \c false if it is absolute. diff --git a/src/corelib/io/qfile_p.h b/src/corelib/io/qfile_p.h index fd7db3c120..545890c6b3 100644 --- a/src/corelib/io/qfile_p.h +++ b/src/corelib/io/qfile_p.h @@ -70,7 +70,7 @@ protected: bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags); bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags); - virtual QAbstractFileEngine *engine() const; + QAbstractFileEngine *engine() const override; QString fileName; }; diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 5de85f9811..1b908eac55 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -65,6 +65,13 @@ #include <MobileCoreServices/MobileCoreServices.h> #endif +#if defined(Q_OS_DARWIN) +// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but +// we need these declarations: +Q_FORWARD_DECLARE_OBJC_CLASS(NSString); +extern "C" NSString *NSTemporaryDirectory(); +#endif + QT_BEGIN_NAMESPACE #if defined(Q_OS_DARWIN) @@ -703,8 +710,17 @@ QString QFileSystemEngine::tempPath() return QLatin1String(QT_UNIX_TEMP_PATH_OVERRIDE); #else QString temp = QFile::decodeName(qgetenv("TMPDIR")); - if (temp.isEmpty()) - temp = QLatin1String("/tmp"); + if (temp.isEmpty()) { +#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) + if (NSString *nsPath = NSTemporaryDirectory()) { + temp = QString::fromCFString((CFStringRef)nsPath); + } else { +#else + { +#endif + temp = QLatin1String("/tmp"); + } + } return QDir::cleanPath(temp); #endif } diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 7fe3753da4..febf22639c 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -49,6 +49,7 @@ #include "qdatetime.h" #include "qbytearray.h" #include "qstringlist.h" +#include "qendian.h" #include <qshareddata.h> #include <qplatformdefs.h> #include "private/qabstractfileengine_p.h" @@ -101,35 +102,38 @@ class QResourceRoot Directory = 0x02 }; const uchar *tree, *names, *payloads; - inline int findOffset(int node) const { return node * 14; } //sizeof each tree element + int version; + inline int findOffset(int node) const { return node * (14 + (version >= 0x02 ? 8 : 0)); } //sizeof each tree element uint hash(int node) const; QString name(int node) const; short flags(int node) const; public: mutable QAtomicInt ref; - inline QResourceRoot(): tree(0), names(0), payloads(0) {} - inline QResourceRoot(const uchar *t, const uchar *n, const uchar *d) { setSource(t, n, d); } + inline QResourceRoot(): tree(0), names(0), payloads(0), version(0) {} + inline QResourceRoot(int version, const uchar *t, const uchar *n, const uchar *d) { setSource(version, t, n, d); } virtual ~QResourceRoot() { } int findNode(const QString &path, const QLocale &locale=QLocale()) const; inline bool isContainer(int node) const { return flags(node) & Directory; } inline bool isCompressed(int node) const { return flags(node) & Compressed; } const uchar *data(int node, qint64 *size) const; + QDateTime lastModified(int node) const; QStringList children(int node) const; virtual QString mappingRoot() const { return QString(); } bool mappingRootSubdir(const QString &path, QString *match=0) const; inline bool operator==(const QResourceRoot &other) const - { return tree == other.tree && names == other.names && payloads == other.payloads; } + { return tree == other.tree && names == other.names && payloads == other.payloads && version == other.version; } inline bool operator!=(const QResourceRoot &other) const { return !operator==(other); } enum ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer }; virtual ResourceRootType type() const { return Resource_Builtin; } protected: - inline void setSource(const uchar *t, const uchar *n, const uchar *d) { + inline void setSource(int v, const uchar *t, const uchar *n, const uchar *d) { tree = t; names = n; payloads = d; + version = v; } }; @@ -231,6 +235,7 @@ public: mutable qint64 size; mutable const uchar *data; mutable QStringList children; + mutable QDateTime lastModified; QResource *q_ptr; Q_DECLARE_PUBLIC(QResource) @@ -244,6 +249,7 @@ QResourcePrivate::clear() data = 0; size = 0; children.clear(); + lastModified = QDateTime(); container = 0; for(int i = 0; i < related.size(); ++i) { QResourceRoot *root = related.at(i); @@ -274,6 +280,7 @@ QResourcePrivate::load(const QString &file) size = 0; compressed = 0; } + lastModified = res->lastModified(node); } else if(res->isContainer(node) != container) { qWarning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData()); } @@ -284,6 +291,7 @@ QResourcePrivate::load(const QString &file) data = 0; size = 0; compressed = 0; + lastModified = QDateTime(); res->ref.ref(); related.append(res); } @@ -514,6 +522,17 @@ const uchar *QResource::data() const } /*! + Returns the date and time when the file was last modified before + packaging into a resource. +*/ +QDateTime QResource::lastModified() const +{ + Q_D(const QResource); + d->ensureInitialized(); + return d->lastModified; +} + +/*! Returns \c true if the resource represents a directory and thus may have children() in it, false if it represents a file. @@ -588,11 +607,9 @@ inline uint QResourceRoot::hash(int node) const if(!node) //root return 0; const int offset = findOffset(node); - int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + qint32 name_offset = qFromBigEndian<qint32>(tree + offset); name_offset += 2; //jump past name length - return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) + - (names[name_offset+2] << 8) + (names[name_offset+3] << 0); + return qFromBigEndian<quint32>(names + name_offset); } inline QString QResourceRoot::name(int node) const { @@ -601,10 +618,8 @@ inline QString QResourceRoot::name(int node) const const int offset = findOffset(node); QString ret; - int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); - const short name_length = (names[name_offset+0] << 8) + - (names[name_offset+1] << 0); + qint32 name_offset = qFromBigEndian<qint32>(tree + offset); + const qint16 name_length = qFromBigEndian<qint16>(names + name_offset); name_offset += 2; name_offset += 4; //jump past hash @@ -644,10 +659,8 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const return 0; //the root node is always first - int child_count = (tree[6] << 24) + (tree[7] << 16) + - (tree[8] << 8) + (tree[9] << 0); - int child = (tree[10] << 24) + (tree[11] << 16) + - (tree[12] << 8) + (tree[13] << 0); + qint32 child_count = qFromBigEndian<qint32>(tree + 6); + qint32 child = qFromBigEndian<qint32>(tree + 10); //now iterate up the tree int node = -1; @@ -693,18 +706,15 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const #endif offset += 4; //jump past name - const short flags = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; if(!splitter.hasNext()) { if(!(flags & Directory)) { - const short country = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 country = qFromBigEndian<qint16>(tree + offset); offset += 2; - const short language = (tree[offset+0] << 8) + - (tree[offset+1] << 0); + const qint16 language = qFromBigEndian<qint16>(tree + offset); offset += 2; #ifdef DEBUG_RESOURCE_MATCH qDebug() << " " << "LOCALE" << country << language; @@ -731,11 +741,9 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const if(!(flags & Directory)) return -1; - child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + child_count = qFromBigEndian<qint32>(tree + offset); offset += 4; - child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + child = qFromBigEndian<qint32>(tree + offset); break; } } @@ -753,7 +761,7 @@ short QResourceRoot::flags(int node) const if(node == -1) return 0; const int offset = findOffset(node) + 4; //jump past name - return (tree[offset+0] << 8) + (tree[offset+1] << 0); + return qFromBigEndian<qint16>(tree + offset); } const uchar *QResourceRoot::data(int node, qint64 *size) const { @@ -763,16 +771,14 @@ const uchar *QResourceRoot::data(int node, qint64 *size) const } int offset = findOffset(node) + 4; //jump past name - const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; offset += 4; //jump past locale if(!(flags & Directory)) { - const int data_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); - const uint data_length = (payloads[data_offset+0] << 24) + (payloads[data_offset+1] << 16) + - (payloads[data_offset+2] << 8) + (payloads[data_offset+3] << 0); + const qint32 data_offset = qFromBigEndian<qint32>(tree + offset); + const quint32 data_length = qFromBigEndian<quint32>(payloads + data_offset); const uchar *ret = payloads+data_offset+4; *size = data_length; return ret; @@ -780,22 +786,35 @@ const uchar *QResourceRoot::data(int node, qint64 *size) const *size = 0; return 0; } + +QDateTime QResourceRoot::lastModified(int node) const +{ + if (node == -1 || version < 0x02) + return QDateTime(); + + const int offset = findOffset(node) + 14; + + const quint64 timeStamp = qFromBigEndian<quint64>(tree + offset); + if (timeStamp == 0) + return QDateTime(); + + return QDateTime::fromMSecsSinceEpoch(timeStamp); +} + QStringList QResourceRoot::children(int node) const { if(node == -1) return QStringList(); int offset = findOffset(node) + 4; //jump past name - const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); + const qint16 flags = qFromBigEndian<qint16>(tree + offset); offset += 2; QStringList ret; if(flags & Directory) { - const int child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + const qint32 child_count = qFromBigEndian<qint32>(tree + offset); offset += 4; - const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) + - (tree[offset+2] << 8) + (tree[offset+3] << 0); + const qint32 child_off = qFromBigEndian<qint32>(tree + offset); ret.reserve(child_count); for(int i = child_off; i < child_off+child_count; ++i) ret << name(i); @@ -829,9 +848,9 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data) { QMutexLocker lock(resourceMutex()); - if(version == 0x01 && resourceList()) { + if ((version == 0x01 || version == 0x2) && resourceList()) { bool found = false; - QResourceRoot res(tree, name, data); + QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ++i) { if(*resourceList()->at(i) == res) { found = true; @@ -839,7 +858,7 @@ Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, } } if(!found) { - QResourceRoot *root = new QResourceRoot(tree, name, data); + QResourceRoot *root = new QResourceRoot(version, tree, name, data); root->ref.ref(); resourceList()->append(root); } @@ -852,8 +871,8 @@ Q_CORE_EXPORT bool qUnregisterResourceData(int version, const unsigned char *tre const unsigned char *name, const unsigned char *data) { QMutexLocker lock(resourceMutex()); - if(version == 0x01 && resourceList()) { - QResourceRoot res(tree, name, data); + if ((version == 0x01 || version == 0x02) && resourceList()) { + QResourceRoot res(version, tree, name, data); for(int i = 0; i < resourceList()->size(); ) { if(*resourceList()->at(i) == res) { QResourceRoot *root = resourceList()->takeAt(i); @@ -899,29 +918,25 @@ public: } offset += 4; - const int version = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int version = qFromBigEndian<qint32>(b + offset); offset += 4; - const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int tree_offset = qFromBigEndian<qint32>(b + offset); offset += 4; - const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int data_offset = qFromBigEndian<qint32>(b + offset); offset += 4; - const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + - (b[offset+2] << 8) + (b[offset+3] << 0); + const int name_offset = qFromBigEndian<qint32>(b + offset); offset += 4; // Some sanity checking for sizes. This is _not_ a security measure. if (size >= 0 && (tree_offset >= size || data_offset >= size || name_offset >= size)) return false; - if(version == 0x01) { + if (version == 0x01 || version == 0x02) { buffer = b; - setSource(b+tree_offset, b+name_offset, b+data_offset); + setSource(version, b+tree_offset, b+name_offset, b+data_offset); return true; } return false; @@ -1430,8 +1445,11 @@ QString QResourceFileEngine::owner(FileOwner) const return QString(); } -QDateTime QResourceFileEngine::fileTime(FileTime) const +QDateTime QResourceFileEngine::fileTime(FileTime time) const { + Q_D(const QResourceFileEngine); + if (time == ModificationTime) + return d->resource.lastModified(); return QDateTime(); } diff --git a/src/corelib/io/qresource.h b/src/corelib/io/qresource.h index a50bbbdaca..895cf0456e 100644 --- a/src/corelib/io/qresource.h +++ b/src/corelib/io/qresource.h @@ -69,6 +69,7 @@ public: bool isCompressed() const; qint64 size() const; const uchar *data() const; + QDateTime lastModified() const; static void addSearchPath(const QString &path); static QStringList searchPaths(); diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 675b375b22..1a69891d3b 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -97,14 +97,6 @@ using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Storage; #endif -#ifndef CSIDL_COMMON_APPDATA -#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data -#endif - -#ifndef CSIDL_APPDATA -#define CSIDL_APPDATA 0x001a // <username>\Application Data -#endif - #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_ANDROID) #define Q_XDG_PLATFORM #endif @@ -970,31 +962,34 @@ void QConfFileSettingsPrivate::initAccess() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -static QString windowsConfigPath(int type) +static QString windowsConfigPath(const KNOWNFOLDERID &type) { QString result; - wchar_t path[MAX_PATH]; - if (SHGetSpecialFolderPath(0, path, type, false)) + PWSTR path = nullptr; + if (SHGetKnownFolderPath(type, KF_FLAG_DONT_VERIFY, NULL, &path) == S_OK) { result = QString::fromWCharArray(path); + CoTaskMemFree(path); + } if (result.isEmpty()) { - switch (type) { - case CSIDL_COMMON_APPDATA: + if (type == FOLDERID_ProgramData) { result = QLatin1String("C:\\temp\\qt-common"); - break; - case CSIDL_APPDATA: + } else if (type == FOLDERID_RoamingAppData) { result = QLatin1String("C:\\temp\\qt-user"); - break; - default: - ; } } return result; } #elif defined(Q_OS_WINRT) // Q_OS_WIN && !Q_OS_WINRT -static QString windowsConfigPath(int type) + +enum ConfigPathType { + ConfigPath_CommonAppData, + ConfigPath_UserAppData +}; + +static QString windowsConfigPath(ConfigPathType type) { static QString result; while (result.isEmpty()) { @@ -1017,12 +1012,10 @@ static QString windowsConfigPath(int type) } switch (type) { - case CSIDL_COMMON_APPDATA: + case ConfigPath_CommonAppData: return result + QLatin1String("\\qt-common"); - case CSIDL_APPDATA: + case ConfigPath_UserAppData: return result + QLatin1String("\\qt-user"); - default: - break; } return result; } @@ -1079,10 +1072,18 @@ static void initDefaultPaths(QMutexLocker *locker) Windows registry and the Mac CFPreferences.) */ #ifdef Q_OS_WIN + +# ifdef Q_OS_WINRT + const QString roamingAppDataFolder = windowsConfigPath(ConfigPath_UserAppData); + const QString programDataFolder = windowsConfigPath(ConfigPath_CommonAppData); +# else + const QString roamingAppDataFolder = windowsConfigPath(FOLDERID_RoamingAppData); + const QString programDataFolder = windowsConfigPath(FOLDERID_ProgramData); +# endif pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), - Path(windowsConfigPath(CSIDL_APPDATA) + QDir::separator(), false)); + Path(roamingAppDataFolder + QDir::separator(), false)); pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), - Path(windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator(), false)); + Path(programDataFolder + QDir::separator(), false)); #else const QString userPath = make_user_path(); pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), Path(userPath, false)); @@ -2267,20 +2268,20 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, On Windows, the following files are used: \list 1 - \li \c{CSIDL_APPDATA\MySoft\Star Runner.ini} - \li \c{CSIDL_APPDATA\MySoft.ini} - \li \c{CSIDL_COMMON_APPDATA\MySoft\Star Runner.ini} - \li \c{CSIDL_COMMON_APPDATA\MySoft.ini} + \li \c{FOLDERID_RoamingAppData\MySoft\Star Runner.ini} + \li \c{FOLDERID_RoamingAppData\MySoft.ini} + \li \c{FOLDERID_ProgramData\MySoft\Star Runner.ini} + \li \c{FOLDERID_ProgramData\MySoft.ini} \endlist - The identifiers prefixed by \c{CSIDL_} are special item ID lists to be passed - to the Win32 API function \c{SHGetSpecialFolderPath()} to obtain the + The identifiers prefixed by \c{FOLDERID_} are special item ID lists to be passed + to the Win32 API function \c{SHGetKnownFolderPath()} to obtain the corresponding path. - \c{CSIDL_APPDATA} usually points to \tt{C:\\Users\\\e{User Name}\\AppData\\Roaming}, + \c{FOLDERID_RoamingAppData} usually points to \tt{C:\\Users\\\e{User Name}\\AppData\\Roaming}, also shown by the environment variable \c{%APPDATA%}. - \c{CSIDL_COMMON_APPDATA} usually points to \tt{C:\\ProgramData}. + \c{FOLDERID_ProgramData} usually points to \tt{C:\\ProgramData}. If the file format is IniFormat, this is "Settings/MySoft/Star Runner.ini" in the application's home directory. @@ -2740,6 +2741,7 @@ void QSettings::sync() { Q_D(QSettings); d->sync(); + d->pendingChanges = false; } /*! @@ -3384,8 +3386,8 @@ void QSettings::setUserIniPath(const QString &dir) \table \header \li Platform \li Format \li Scope \li Path - \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c CSIDL_APPDATA - \row \li SystemScope \li \c CSIDL_COMMON_APPDATA + \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c FOLDERID_RoamingAppData + \row \li SystemScope \li \c FOLDERID_ProgramData \row \li{1,2} Unix \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/.config \row \li SystemScope \li \c /etc/xdg \row \li{1,2} Qt for Embedded Linux \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/Settings diff --git a/src/corelib/io/qt_attribution.json b/src/corelib/io/qt_attribution.json index 2a616a2819..c64f8cae4b 100644 --- a/src/corelib/io/qt_attribution.json +++ b/src/corelib/io/qt_attribution.json @@ -1,3 +1,4 @@ +[ { "Id": "qtemporaryfile", "Name": "Parts of QTemporaryFile", @@ -10,4 +11,32 @@ "LicenseId": "BSD-3-Clause", "LicenseFile": "QTEMPORARYFILE_LICENSE.txt", "Copyright": "Copyright (c) 1987, 1993 The Regents of the University of California." +}, +{ + "Id": "psl", + "Name": "The Public Suffix List", + "QDocModule": "qtcore", + "Description": "The Public Suffix List is an initiative of the Mozilla Project, +but is maintained as a community resource. It is available for use in any software, +but was originally created to meet the needs of browser manufacturers. +It allows browsers to, for example: + +- Avoid privacy-damaging \"supercookies\" being set for high-level domain name suffixes + +- Highlight the most important part of a domain name in the user interface + +- Accurately sort history entries by site", + + "Files": "qurltlds_p.h", + "QtUsage": "Used in Qt Core to avoid \"supercookies\" being set in the cookie jar +supported by Qt (by the QNetworkCookieJar class).", + + "Homepage": "http://publicsuffix.org/", + "Version": "Generated on 2016-10-20 from revision 915565885d0fbd25caf7d8b339cd3478f558da94", + "License": "Mozilla Public License 2.0", + "LicenseFile": "PSL-LICENSE.txt", + "LicenseId": "MPL-2.0", + "Copyright": "The list was originally provided by Jo Hermans <jo.hermans@gmail.com>. +It is now maintained on github (https://github.com/publicsuffix/list)." } +] diff --git a/src/corelib/io/qtemporaryfile_p.h b/src/corelib/io/qtemporaryfile_p.h index d057603034..7f365f0e8a 100644 --- a/src/corelib/io/qtemporaryfile_p.h +++ b/src/corelib/io/qtemporaryfile_p.h @@ -70,7 +70,7 @@ protected: explicit QTemporaryFilePrivate(const QString &templateNameIn); ~QTemporaryFilePrivate(); - QAbstractFileEngine *engine() const; + QAbstractFileEngine *engine() const override; void resetFileEngine() const; bool autoRemove = true; @@ -99,14 +99,14 @@ public: ~QTemporaryFileEngine(); bool isReallyOpen() const; - void setFileName(const QString &file); + void setFileName(const QString &file) override; void setFileTemplate(const QString &fileTemplate); - bool open(QIODevice::OpenMode flags); - bool remove(); - bool rename(const QString &newName); - bool renameOverwrite(const QString &newName); - bool close(); + bool open(QIODevice::OpenMode flags) override; + bool remove() override; + bool rename(const QString &newName) override; + bool renameOverwrite(const QString &newName) override; + bool close() override; quint32 fileMode; bool filePathIsTemplate; diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 5b34813a71..066052ade9 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -417,7 +417,8 @@ #include "qurlquery.h" QT_BEGIN_NAMESPACE -extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths); // qdir.cpp +extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths, + bool *ok = nullptr); // qdir.cpp inline static bool isHex(char c) { @@ -3690,6 +3691,9 @@ bool QUrl::matches(const QUrl &url, FormattingOptions options) const if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask)) return false; + if (options & QUrl::RemovePath) + return true; + // Compare paths, after applying path-related options QString path1; d->appendPath(path1, options, QUrlPrivate::Path); diff --git a/src/corelib/io/qurltlds_p.h.INFO b/src/corelib/io/qurltlds_p.h.INFO index 3f3d808a21..33ccd458bf 100644 --- a/src/corelib/io/qurltlds_p.h.INFO +++ b/src/corelib/io/qurltlds_p.h.INFO @@ -9,9 +9,6 @@ Those arrays in qurltlds_p.h are derived from the Public Suffix List ([2]), which was originally provided by Jo Hermans <jo.hermans@gmail.com>. -The file qurltlds_p.h was last generated Thursday, -October 20th 8:40 2016. - ---- [1] list: http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat?raw=1 [2] homepage: http://publicsuffix.org/ diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp index 0eb0d21ecf..39738b90a8 100644 --- a/src/corelib/json/qjsonparser.cpp +++ b/src/corelib/json/qjsonparser.cpp @@ -500,9 +500,10 @@ namespace { memcpy(newValues, data, size*sizeof(QJsonPrivate::Value)); data = newValues; } else { - data = static_cast<QJsonPrivate::Value *>(realloc(data, alloc*sizeof(QJsonPrivate::Value))); - if (!data) + void *newValues = realloc(data, alloc * sizeof(QJsonPrivate::Value)); + if (!newValues) return false; + data = static_cast<QJsonPrivate::Value *>(newValues); } return true; } diff --git a/src/corelib/json/qjsonparser_p.h b/src/corelib/json/qjsonparser_p.h index afa2c1a8cf..379256847f 100644 --- a/src/corelib/json/qjsonparser_p.h +++ b/src/corelib/json/qjsonparser_p.h @@ -108,11 +108,12 @@ private: inline int reserveSpace(int space) { if (current + space >= dataLength) { dataLength = 2*dataLength + space; - data = (char *)realloc(data, dataLength); - if (!data) { + char *newData = (char *)realloc(data, dataLength); + if (!newData) { lastError = QJsonParseError::DocumentTooLarge; return -1; } + data = newData; } int pos = current; current += space; diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index 7799113d30..61d0f2bdf1 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -151,9 +151,6 @@ unix|integrity { kernel/qtimerinfo_unix_p.h qtConfig(poll_select): SOURCES += kernel/qpoll.cpp - qtConfig(poll_poll): DEFINES += QT_HAVE_POLL - qtConfig(poll_ppoll): DEFINES += QT_HAVE_POLL QT_HAVE_PPOLL - qtConfig(poll_pollts): DEFINES += QT_HAVE_POLL QT_HAVE_POLLTS qtConfig(glib) { SOURCES += \ diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index 2042964427..686143f8c7 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -38,6 +38,7 @@ ** ****************************************************************************/ +#include <QtCore/private/qglobal_p.h> #include "qcore_unix_p.h" #include "qelapsedtimer.h" @@ -49,9 +50,8 @@ QT_BEGIN_NAMESPACE -#if !defined(QT_HAVE_PPOLL) && defined(QT_HAVE_POLLTS) -# define ppoll pollts -# define QT_HAVE_PPOLL +#if QT_CONFIG(poll_pollts) +# define ppoll pollts #endif static inline bool time_update(struct timespec *tv, const struct timespec &start, @@ -64,7 +64,7 @@ static inline bool time_update(struct timespec *tv, const struct timespec &start return tv->tv_sec >= 0; } -#if !defined(QT_HAVE_PPOLL) && defined(QT_HAVE_POLL) +#if QT_CONFIG(poll_poll) static inline int timespecToMillisecs(const struct timespec *ts) { return (ts == NULL) ? -1 : @@ -77,9 +77,9 @@ int qt_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts); static inline int qt_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts) { -#if defined(QT_HAVE_PPOLL) - return ::ppoll(fds, nfds, timeout_ts, Q_NULLPTR); -#elif defined(QT_HAVE_POLL) +#if QT_CONFIG(poll_ppoll) || QT_CONFIG(poll_pollts) + return ::ppoll(fds, nfds, timeout_ts, nullptr); +#elif QT_CONFIG(poll_poll) return ::poll(fds, nfds, timespecToMillisecs(timeout_ts)); #else return qt_poll(fds, nfds, timeout_ts); diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 3b97b89359..aa0f735fcc 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -62,7 +62,7 @@ public: : t1(std::numeric_limits<qint64>::max()), t2(0), type(type_) {} explicit QDeadlineTimer(qint64 msecs, Qt::TimerType type = Qt::CoarseTimer) Q_DECL_NOTHROW; - void swap(QDeadlineTimer &other) + void swap(QDeadlineTimer &other) Q_DECL_NOTHROW { qSwap(t1, other.t1); qSwap(t2, other.t2); qSwap(type, other.type); } Q_DECL_CONSTEXPR bool isForever() const Q_DECL_NOTHROW @@ -88,17 +88,17 @@ public: static QDeadlineTimer addNSecs(QDeadlineTimer dt, qint64 nsecs) Q_DECL_NOTHROW Q_DECL_PURE_FUNCTION; static QDeadlineTimer current(Qt::TimerType timerType = Qt::CoarseTimer) Q_DECL_NOTHROW; - friend bool operator==(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator==(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return d1.t1 == d2.t1 && d1.t2 == d2.t2; } - friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator!=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return !(d1 == d2); } - friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator<(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return d1.t1 < d2.t1 || (d1.t1 == d2.t1 && d1.t2 < d2.t2); } - friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator<=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return d1 == d2 || d1 < d2; } - friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator>(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return d2 < d1; } - friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) + friend bool operator>=(QDeadlineTimer d1, QDeadlineTimer d2) Q_DECL_NOTHROW { return !(d1 < d2); } friend QDeadlineTimer operator+(QDeadlineTimer dt, qint64 msecs) diff --git a/src/corelib/kernel/qelapsedtimer.cpp b/src/corelib/kernel/qelapsedtimer.cpp index 5e9d1317ac..e578b5b8b3 100644 --- a/src/corelib/kernel/qelapsedtimer.cpp +++ b/src/corelib/kernel/qelapsedtimer.cpp @@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE \snippet qelapsedtimer/main.cpp 2 - It is often more convenient to use \ref{QDeadlineTimer} in this case, which + It is often more convenient to use \l{QDeadlineTimer} in this case, which counts towards a timeout in the future instead of tracking elapsed time. \section1 Reference Clocks diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index ff397fc750..33753ed507 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -166,7 +166,7 @@ private: timerIdToHandle.insert(id, handle); timerIdToCancelHandle.insert(id, cancelHandle); } - timerIdToObject.insert(id, obj); + const quint64 targetTime = qt_msectime() + interval; const WinRTTimerInfo info(id, interval, type, obj, targetTime); QMutexLocker locker(&timerInfoLock); @@ -587,15 +587,18 @@ bool QEventDispatcherWinRT::event(QEvent *e) break; info.inEvent = true; + QObject *timerObj = d->timerIdToObject.value(id); locker.unlock(); QTimerEvent te(id); - QCoreApplication::sendEvent(d->timerIdToObject.value(id), &te); + QCoreApplication::sendEvent(timerObj, &te); locker.relock(); - // The timer might have been removed in the meanwhile - if (id >= d->timerInfos.size()) + // The timer might have been removed in the meanwhile. If the timer was + // the last one in the list, id is bigger than the list's size. + // Otherwise, the id will just be set to INVALID_TIMER_ID. + if (id >= d->timerInfos.size() || info.timerId == INVALID_TIMER_ID) break; if (info.interval == 0 && info.inEvent) { diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index e94e713e1f..79c9c8303e 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -229,8 +229,14 @@ namespace QtPrivate { (std::is_floating_point<From>::value && std::is_integral<To>::value) || (std::is_floating_point<From>::value && std::is_floating_point<To>::value && sizeof(From) > sizeof(To)) || ((std::is_integral<From>::value || std::is_enum<From>::value) && std::is_floating_point<To>::value) || - (std::is_integral<From>::value && std::is_integral<To>::value && (sizeof(From) > sizeof(To) || std::is_signed<From>::value != std::is_signed<To>::value)) || - (std::is_enum<From>::value && std::is_integral<To>::value && (sizeof(From) > sizeof(To) || IsEnumUnderlyingTypeSigned<From>::value != std::is_signed<To>::value)) + (std::is_integral<From>::value && std::is_integral<To>::value + && (sizeof(From) > sizeof(To) + || (std::is_signed<From>::value ? !std::is_signed<To>::value + : (std::is_signed<To>::value && sizeof(From) == sizeof(To))))) || + (std::is_enum<From>::value && std::is_integral<To>::value + && (sizeof(From) > sizeof(To) + || (IsEnumUnderlyingTypeSigned<From>::value ? !std::is_signed<To>::value + : (std::is_signed<To>::value && sizeof(From) == sizeof(To))))) > { }; diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 06a57a94a6..4a4d5b9294 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -319,7 +319,7 @@ template<typename TInput, typename LiteralWrapper> inline bool qt_convertToBool(const QVariant::Private *const d) { TInput str = v_cast<TInput>(d)->toLower(); - return !(str == LiteralWrapper("0") || str == LiteralWrapper("false") || str.isEmpty()); + return !(str.isEmpty() || str == LiteralWrapper("0") || str == LiteralWrapper("false")); } /*! @@ -700,7 +700,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) bool *b = static_cast<bool *>(result); switch(d->type) { case QVariant::ByteArray: - *b = qt_convertToBool<QByteArray, QByteArray>(d); + *b = qt_convertToBool<QByteArray, const char*>(d); break; case QVariant::String: *b = qt_convertToBool<QString, QLatin1String>(d); diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp index f786b2ae03..448e6117b1 100644 --- a/src/corelib/mimetypes/qmimedatabase.cpp +++ b/src/corelib/mimetypes/qmimedatabase.cpp @@ -264,7 +264,7 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent) \code <?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> - <mime-type type="application/vnd.nokia.qt.qmakeprofile"> + <mime-type type="application/vnd.qt.qmakeprofile"> <comment xml:lang="en">Qt qmake Profile</comment> <glob pattern="*.pro" weight="50"/> </mime-type> diff --git a/src/corelib/mimetypes/qmimetypeparser_p.h b/src/corelib/mimetypes/qmimetypeparser_p.h index a502439419..0ce39e701c 100644 --- a/src/corelib/mimetypes/qmimetypeparser_p.h +++ b/src/corelib/mimetypes/qmimetypeparser_p.h @@ -108,19 +108,19 @@ public: explicit QMimeTypeParser(QMimeXMLProvider &provider) : m_provider(provider) {} protected: - inline bool process(const QMimeType &t, QString *) + inline bool process(const QMimeType &t, QString *) override { m_provider.addMimeType(t); return true; } - inline bool process(const QMimeGlobPattern &glob, QString *) + inline bool process(const QMimeGlobPattern &glob, QString *) override { m_provider.addGlobPattern(glob); return true; } - inline void processParent(const QString &child, const QString &parent) + inline void processParent(const QString &child, const QString &parent) override { m_provider.addParent(child, parent); } - inline void processAlias(const QString &alias, const QString &name) + inline void processAlias(const QString &alias, const QString &name) override { m_provider.addAlias(alias, name); } - inline void processMagicMatcher(const QMimeMagicRuleMatcher &matcher) + inline void processMagicMatcher(const QMimeMagicRuleMatcher &matcher) override { m_provider.addMagicMatcher(matcher); } private: diff --git a/src/corelib/statemachine/qhistorystate_p.h b/src/corelib/statemachine/qhistorystate_p.h index 4a4442d7dd..d22e5c4aaf 100644 --- a/src/corelib/statemachine/qhistorystate_p.h +++ b/src/corelib/statemachine/qhistorystate_p.h @@ -88,8 +88,8 @@ protected: // state, it will handle this transition as a special case. The history state itself is never // entered either: either the stored configuration will be used, or the target(s) of this // transition are used. - virtual bool eventTest(QEvent *event) { Q_UNUSED(event); return false; } - virtual void onTransition(QEvent *event) { Q_UNUSED(event); } + bool eventTest(QEvent *event) override { Q_UNUSED(event); return false; } + void onTransition(QEvent *event) override { Q_UNUSED(event); } }; QT_END_NAMESPACE diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 447fca44c0..24218e833a 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -61,6 +61,9 @@ # error "Qt requires C++11 support" #endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_MSVC(4522) + QT_BEGIN_NAMESPACE #if 0 @@ -323,4 +326,6 @@ public: QT_END_NAMESPACE +QT_WARNING_POP + #endif // QBASICATOMIC_H diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index ce31fe9270..c62b8fd36b 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -83,13 +83,33 @@ QFutureInterfaceBase::~QFutureInterfaceBase() delete d; } +static inline int switch_on(QAtomicInt &a, int which) +{ + return a.fetchAndOrRelaxed(which) | which; +} + +static inline int switch_off(QAtomicInt &a, int which) +{ + return a.fetchAndAndRelaxed(~which) & ~which; +} + +static inline int switch_from_to(QAtomicInt &a, int from, int to) +{ + int newValue; + int expected = a.load(); + do { + newValue = (expected & ~from) | to; + } while (!a.testAndSetRelaxed(expected, newValue, expected)); + return newValue; +} + void QFutureInterfaceBase::cancel() { QMutexLocker locker(&d->m_mutex); - if (d->state & Canceled) + if (d->state.load() & Canceled) return; - d->state = State((d->state & ~Paused) | Canceled); + switch_from_to(d->state, Paused, Canceled); d->waitCondition.wakeAll(); d->pausedWaitCondition.wakeAll(); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); @@ -99,10 +119,10 @@ void QFutureInterfaceBase::setPaused(bool paused) { QMutexLocker locker(&d->m_mutex); if (paused) { - d->state = State(d->state | Paused); + switch_on(d->state, Paused); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); } else { - d->state = State(d->state & ~Paused); + switch_off(d->state, Paused); d->pausedWaitCondition.wakeAll(); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); } @@ -111,29 +131,24 @@ void QFutureInterfaceBase::setPaused(bool paused) void QFutureInterfaceBase::togglePaused() { QMutexLocker locker(&d->m_mutex); - if (d->state & Paused) { - d->state = State(d->state & ~Paused); + if (d->state.load() & Paused) { + switch_off(d->state, Paused); d->pausedWaitCondition.wakeAll(); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); } else { - d->state = State(d->state | Paused); + switch_on(d->state, Paused); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); } } void QFutureInterfaceBase::setThrottled(bool enable) { - // bail out if we are not changing the state - if ((enable && (d->state & Throttled)) || (!enable && !(d->state & Throttled))) - return; - - // lock and change the state QMutexLocker lock(&d->m_mutex); if (enable) { - d->state = State(d->state | Throttled); + switch_on(d->state, Throttled); } else { - d->state = State(d->state & ~Throttled); - if (!(d->state & Paused)) + switch_off(d->state, Throttled); + if (!(d->state.load() & Paused)) d->pausedWaitCondition.wakeAll(); } } @@ -184,11 +199,15 @@ bool QFutureInterfaceBase::waitForNextResult() void QFutureInterfaceBase::waitForResume() { // return early if possible to avoid taking the mutex lock. - if ((d->state & Paused) == false || (d->state & Canceled)) - return; + { + const int state = d->state.load(); + if (!(state & Paused) || (state & Canceled)) + return; + } QMutexLocker lock(&d->m_mutex); - if ((d->state & Paused) == false || (d->state & Canceled)) + const int state = d->state.load(); + if (!(state & Paused) || (state & Canceled)) return; // decrease active thread count since this thread will wait. @@ -236,7 +255,7 @@ bool QFutureInterfaceBase::isProgressUpdateNeeded() const void QFutureInterfaceBase::reportStarted() { QMutexLocker locker(&d->m_mutex); - if ((d->state & Started) || (d->state & Canceled) || (d->state & Finished)) + if (d->state.load() & (Started|Canceled|Finished)) return; d->setState(State(Started | Running)); @@ -252,11 +271,11 @@ void QFutureInterfaceBase::reportCanceled() void QFutureInterfaceBase::reportException(const QException &exception) { QMutexLocker locker(&d->m_mutex); - if ((d->state & Canceled) || (d->state & Finished)) + if (d->state.load() & (Canceled|Finished)) return; d->m_exceptionStore.setException(exception); - d->state = State(d->state | Canceled); + switch_on(d->state, Canceled); d->waitCondition.wakeAll(); d->pausedWaitCondition.wakeAll(); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); @@ -266,8 +285,8 @@ void QFutureInterfaceBase::reportException(const QException &exception) void QFutureInterfaceBase::reportFinished() { QMutexLocker locker(&d->m_mutex); - if (!(d->state & Finished)) { - d->state = State((d->state & ~Running) | Finished); + if (!isFinished()) { + switch_from_to(d->state, Running, Finished); d->waitCondition.wakeAll(); d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); } @@ -287,7 +306,7 @@ int QFutureInterfaceBase::expectedResultCount() bool QFutureInterfaceBase::queryState(State state) const { - return (d->state & state); + return d->state.load() & state; } void QFutureInterfaceBase::waitForResult(int resultIndex) @@ -295,7 +314,7 @@ void QFutureInterfaceBase::waitForResult(int resultIndex) d->m_exceptionStore.throwPossibleException(); QMutexLocker lock(&d->m_mutex); - if (!(d->state & Running)) + if (!isRunning()) return; lock.unlock(); @@ -305,11 +324,9 @@ void QFutureInterfaceBase::waitForResult(int resultIndex) lock.relock(); - if (d->state & Running) { - const int waitIndex = (resultIndex == -1) ? INT_MAX : resultIndex; - while ((d->state & Running) && d->internal_isResultReadyAt(waitIndex) == false) - d->waitCondition.wait(&d->m_mutex); - } + const int waitIndex = (resultIndex == -1) ? INT_MAX : resultIndex; + while (isRunning() && !d->internal_isResultReadyAt(waitIndex)) + d->waitCondition.wait(&d->m_mutex); d->m_exceptionStore.throwPossibleException(); } @@ -317,7 +334,7 @@ void QFutureInterfaceBase::waitForResult(int resultIndex) void QFutureInterfaceBase::waitForFinished() { QMutexLocker lock(&d->m_mutex); - const bool alreadyFinished = !(d->state & Running); + const bool alreadyFinished = !isRunning(); lock.unlock(); if (!alreadyFinished) { @@ -325,7 +342,7 @@ void QFutureInterfaceBase::waitForFinished() lock.relock(); - while (d->state & Running) + while (isRunning()) d->waitCondition.wait(&d->m_mutex); } @@ -334,7 +351,7 @@ void QFutureInterfaceBase::waitForFinished() void QFutureInterfaceBase::reportResultsReady(int beginIndex, int endIndex) { - if ((d->state & Canceled) || (d->state & Finished) || beginIndex == endIndex) + if (beginIndex == endIndex || (d->state.load() & (Canceled|Finished))) return; d->waitCondition.wakeAll(); @@ -396,7 +413,7 @@ void QFutureInterfaceBase::setProgressValueAndText(int progressValue, if (d->m_progressValue >= progressValue) return; - if ((d->state & Canceled) || (d->state & Finished)) + if (d->state.load() & (Canceled|Finished)) return; if (d->internal_updateProgress(progressValue, progressText)) { @@ -468,10 +485,10 @@ bool QFutureInterfaceBasePrivate::internal_waitForNextResult() if (m_results.hasNextResult()) return true; - while ((state & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false) + while ((state.load() & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false) waitCondition.wait(&m_mutex); - return (!(state & QFutureInterfaceBase::Canceled) && m_results.hasNextResult()); + return !(state.load() & QFutureInterfaceBase::Canceled) && m_results.hasNextResult(); } bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress, @@ -494,16 +511,16 @@ bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress, void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable) { // bail out if we are not changing the state - if ((enable && (state & QFutureInterfaceBase::Throttled)) - || (!enable && !(state & QFutureInterfaceBase::Throttled))) + if ((enable && (state.load() & QFutureInterfaceBase::Throttled)) + || (!enable && !(state.load() & QFutureInterfaceBase::Throttled))) return; // change the state if (enable) { - state = QFutureInterfaceBase::State(state | QFutureInterfaceBase::Throttled); + switch_on(state, QFutureInterfaceBase::Throttled); } else { - state = QFutureInterfaceBase::State(state & ~QFutureInterfaceBase::Throttled); - if (!(state & QFutureInterfaceBase::Paused)) + switch_off(state, QFutureInterfaceBase::Throttled); + if (!(state.load() & QFutureInterfaceBase::Paused)) pausedWaitCondition.wakeAll(); } } @@ -538,7 +555,7 @@ void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface { QMutexLocker locker(&m_mutex); - if (state & QFutureInterfaceBase::Started) { + if (state.load() & QFutureInterfaceBase::Started) { interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started)); interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, m_progressMinimum, @@ -558,13 +575,13 @@ void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface it.batchedAdvance(); } - if (state & QFutureInterfaceBase::Paused) + if (state.load() & QFutureInterfaceBase::Paused) interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); - if (state & QFutureInterfaceBase::Canceled) + if (state.load() & QFutureInterfaceBase::Canceled) interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); - if (state & QFutureInterfaceBase::Finished) + if (state.load() & QFutureInterfaceBase::Finished) interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); outputConnections.append(interface); @@ -583,7 +600,7 @@ void QFutureInterfaceBasePrivate::disconnectOutputInterface(QFutureCallOutInterf void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState) { - state = newState; + state.store(newState); } QT_END_NAMESPACE diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h index ee8dfe1354..cf882dd9b4 100644 --- a/src/corelib/thread/qfutureinterface_p.h +++ b/src/corelib/thread/qfutureinterface_p.h @@ -162,7 +162,7 @@ public: int m_progressValue; // TQ int m_progressMinimum; // TQ int m_progressMaximum; // TQ - QFutureInterfaceBase::State state; + QAtomicInt state; // reads and writes can happen unprotected, both must be atomic QElapsedTimer progressTime; QWaitCondition pausedWaitCondition; QtPrivate::ResultStoreBase m_results; diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 6e0fa4eedb..0aee4aeda4 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -275,7 +275,7 @@ bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT Attempts to lock the mutex. This function returns \c true if the lock was obtained; otherwise it returns \c false. If another thread has - locked the mutex, this function will wait for at most \a duration + locked the mutex, this function will wait for at least \a duration for the mutex to become available. Note: Passing a negative duration as the \a duration is equivalent to @@ -299,7 +299,7 @@ bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT Attempts to lock the mutex. This function returns \c true if the lock was obtained; otherwise it returns \c false. If another thread has - locked the mutex, this function will wait at most until \a timePoint + locked the mutex, this function will wait at least until \a timePoint for the mutex to become available. Note: Passing a \a timePoint which has already passed is equivalent diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 3a0e22e3bd..056ebdeaa5 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -46,8 +46,11 @@ #if QT_HAS_INCLUDE(<chrono>) # include <chrono> +# include <limits> #endif +class tst_QMutex; + QT_BEGIN_NAMESPACE @@ -135,14 +138,7 @@ public: template <class Rep, class Period> bool try_lock_for(std::chrono::duration<Rep, Period> duration) { - // N4606 § 30.4.1.3 [thread.timedmutex.requirements]/5 specifies that - // a duration less than or equal to duration.zero() shall result in a - // try_lock, unlike QMutex's tryLock with a negative duration which - // results in a lock. - - if (duration <= duration.zero()) - return tryLock(0); - return tryLock(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()); + return tryLock(convertToMilliseconds(duration)); } // TimedLockable concept @@ -162,6 +158,32 @@ public: private: Q_DISABLE_COPY(QMutex) friend class QMutexLocker; + friend class ::tst_QMutex; + +#if QT_HAS_INCLUDE(<chrono>) + template<class Rep, class Period> + static int convertToMilliseconds(std::chrono::duration<Rep, Period> duration) + { + // N4606 § 30.4.1.3.5 [thread.timedmutex.requirements] specifies that a + // duration less than or equal to duration.zero() shall result in a + // try_lock, unlike QMutex's tryLock with a negative duration which + // results in a lock. + + if (duration <= duration.zero()) + return 0; + + // when converting from 'duration' to milliseconds, make sure that + // the result is not shorter than 'duration': + std::chrono::milliseconds wait = std::chrono::duration_cast<std::chrono::milliseconds>(duration); + if (wait < duration) + wait += std::chrono::milliseconds(1); + Q_ASSERT(wait >= duration); + const auto ms = wait.count(); + const auto maxInt = (std::numeric_limits<int>::max)(); + + return ms < maxInt ? int(ms) : maxInt; + } +#endif }; class Q_CORE_EXPORT QMutexLocker diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 38753a6726..7e846956f5 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -48,8 +48,7 @@ QT_BEGIN_NAMESPACE QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") -QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") +QT_WARNING_DISABLE_DEPRECATED /* Warning: The contents of QAlgorithmsPrivate is not a part of the public Qt API @@ -590,15 +589,16 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NO return __builtin_popcountll(v); } #elif defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM) +#define QT_POPCOUNT_CONSTEXPR #define QT_HAS_BUILTIN_CTZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val) { unsigned long result; _BitScanForward(&result, val); return result; } #define QT_HAS_BUILTIN_CLZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) { unsigned long result; _BitScanReverse(&result, val); @@ -611,7 +611,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) #if Q_PROCESSOR_WORDSIZE == 8 // These are only defined for 64bit builds. #define QT_HAS_BUILTIN_CTZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) { unsigned long result; _BitScanForward64(&result, val); @@ -619,7 +619,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) } // MSVC calls it _BitScanReverse and returns the carry flag, which we don't need #define QT_HAS_BUILTIN_CLZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) { unsigned long result; _BitScanReverse64(&result, val); @@ -629,31 +629,31 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) } #endif // MSVC 64bit # define QT_HAS_BUILTIN_CTZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW { return qt_builtin_ctz(v); } #define QT_HAS_BUILTIN_CLZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW { return qt_builtin_clz(v) - 16U; } #define QALGORITHMS_USE_BUILTIN_POPCOUNT -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW { return __popcnt(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW { return __popcnt16(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW { return __popcnt16(v); } #if Q_PROCESSOR_WORDSIZE == 8 #define QALGORITHMS_USE_BUILTIN_POPCOUNTLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW { return __popcnt64(v); } @@ -661,9 +661,13 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NO #endif // MSVC #endif // QT_HAS_CONSTEXPR_BUILTINS +#ifndef QT_POPCOUNT_CONSTEXPR +#define QT_POPCOUNT_CONSTEXPR Q_DECL_CONSTEXPR +#endif + } //namespace QAlgorithmsPrivate -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -676,7 +680,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -686,7 +690,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_ #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -697,7 +701,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNTLL return QAlgorithmsPrivate::qt_builtin_popcountll(v); @@ -712,7 +716,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigned int v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(long unsigned int v) Q_DECL_NOTHROW { return qPopulationCount(static_cast<quint64>(v)); } @@ -720,6 +724,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigne #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) #undef QALGORITHMS_USE_BUILTIN_POPCOUNT #endif +#undef QT_POPCOUNT_CONSTEXPR Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NOTHROW { diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/tools/qcollator_p.h index fbbce00676..423ba0325a 100644 --- a/src/corelib/tools/qcollator_p.h +++ b/src/corelib/tools/qcollator_p.h @@ -55,7 +55,7 @@ #include <QtCore/private/qglobal_p.h> #include "qcollator.h" #include <QVector> -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) #include <unicode/ucol.h> #elif defined(Q_OS_OSX) #include <CoreServices/CoreServices.h> @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) typedef UCollator *CollatorType; typedef QByteArray CollatorKeyType; @@ -90,7 +90,7 @@ class Q_CORE_EXPORT QCollatorPrivate public: QAtomicInt ref; QLocale locale; -#if defined(Q_OS_WIN) && !defined(QT_USE_ICU) +#if defined(Q_OS_WIN) && !QT_CONFIG(icu) #ifdef USE_COMPARESTRINGEX QString localeName; #else diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h index 4dcae03ad9..276be042de 100644 --- a/src/corelib/tools/qcommandlineoption.h +++ b/src/corelib/tools/qcommandlineoption.h @@ -94,7 +94,7 @@ public: void setFlags(Flags aflags); #if QT_DEPRECATED_SINCE(5, 8) - QT_DEPRECATED_X("Use setFlags() with HiddenFromHelp)") + QT_DEPRECATED_X("Use setFlags() with HiddenFromHelp") void setHidden(bool hidden); QT_DEPRECATED_X("Use flags() and HiddenFromHelp") bool isHidden() const; diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index f81c578bc8..d52f03acae 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3846,7 +3846,7 @@ QString QDateTime::toString(Qt::DateFormat format) const \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li dddd - \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). + \li the long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li M \li the month as number without a leading zero (1-12) \row \li MM \li the month as number with a leading zero (01-12) diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 3271e2a8c4..621c877174 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -888,12 +888,12 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos State state = Acceptable; QDateTime newCurrentValue; - int pos = 0; bool conflicts = false; const int sectionNodesCount = sectionNodes.size(); QDTPDEBUG << "parse" << input; { + int pos = 0; int year, month, day; const QDate currentDate = currentValue.date(); const QTime currentTime = currentValue.time(); diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index 6f381965a9..bc088a5f4c 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -104,14 +104,6 @@ public: none.zeroesAdded = 0; } virtual ~QDateTimeParser() {} - enum AmPmFinder { - Neither = -1, - AM = 0, - PM = 1, - PossibleAM = 2, - PossiblePM = 3, - PossibleBoth = 4 - }; enum Section { NoSection = 0x00000, @@ -187,33 +179,44 @@ public: #ifndef QT_NO_DATESTRING StateNode parse(QString &input, int &cursorPosition, const QDateTime ¤tValue, bool fixup) const; #endif - int sectionMaxSize(int index) const; - int sectionSize(int index) const; - int sectionMaxSize(Section s, int count) const; - int sectionPos(int index) const; - int sectionPos(const SectionNode &sn) const; - - const SectionNode §ionNode(int index) const; - Section sectionType(int index) const; - QString sectionText(int sectionIndex) const; - QString sectionText(const QString &text, int sectionIndex, int index) const; - int getDigit(const QDateTime &dt, int index) const; - bool setDigit(QDateTime &t, int index, int newval) const; - int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, - int index, QDateTimeParser::State &state, int *used = 0) const; - int absoluteMax(int index, const QDateTime &value = QDateTime()) const; - int absoluteMin(int index) const; bool parseFormat(const QString &format); #ifndef QT_NO_DATESTRING bool fromString(const QString &text, QDate *date, QTime *time) const; #endif + enum FieldInfoFlag { + Numeric = 0x01, + FixedWidth = 0x02, + AllowPartial = 0x04, + Fraction = 0x08 + }; + Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) + + FieldInfo fieldInfo(int index) const; + + void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } + virtual QString displayText() const { return text; } + +private: + int sectionMaxSize(Section s, int count) const; + QString sectionText(const QString &text, int sectionIndex, int index) const; + int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, + int index, QDateTimeParser::State &state, int *used = 0) const; #ifndef QT_NO_TEXTDATE int findMonth(const QString &str1, int monthstart, int sectionIndex, QString *monthName = 0, int *used = 0) const; int findDay(const QString &str1, int intDaystart, int sectionIndex, QString *dayName = 0, int *used = 0) const; #endif + + enum AmPmFinder { + Neither = -1, + AM = 0, + PM = 1, + PossibleAM = 2, + PossiblePM = 3, + PossibleBoth = 4 + }; AmPmFinder findAmPm(QString &str, int index, int *used = 0) const; bool potentialValue(const QStringRef &str, int min, int max, int index, const QDateTime ¤tValue, int insert) const; @@ -223,36 +226,37 @@ public: return potentialValue(QStringRef(&str), min, max, index, currentValue, insert); } +protected: // for the benefit of QDateTimeEditPrivate + int sectionSize(int index) const; + int sectionMaxSize(int index) const; + int sectionPos(int index) const; + int sectionPos(const SectionNode &sn) const; + + const SectionNode §ionNode(int index) const; + Section sectionType(int index) const; + QString sectionText(int sectionIndex) const; + int getDigit(const QDateTime &dt, int index) const; + bool setDigit(QDateTime &t, int index, int newval) const; + + int absoluteMax(int index, const QDateTime &value = QDateTime()) const; + int absoluteMin(int index) const; + bool skipToNextSection(int section, const QDateTime ¤t, const QStringRef §ionText) const; bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const { return skipToNextSection(section, current, QStringRef(§ionText)); } - QString stateName(State s) const; - - enum FieldInfoFlag { - Numeric = 0x01, - FixedWidth = 0x02, - AllowPartial = 0x04, - Fraction = 0x08 - }; - Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) - - FieldInfo fieldInfo(int index) const; - - void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } virtual QDateTime getMinimum() const; virtual QDateTime getMaximum() const; virtual int cursorPosition() const { return -1; } - virtual QString displayText() const { return text; } virtual QString getAmPmText(AmPm ap, Case cs) const; virtual QLocale locale() const { return defaultLocale; } mutable int currentSectionIndex; Sections display; /* - This stores the stores the most recently selected day. + This stores the most recently selected day. It is useful when considering the following scenario: 1. Date is: 31/01/2000 @@ -272,9 +276,7 @@ public: QString displayFormat; QLocale defaultLocale; QVariant::Type parserType; - bool fixday; - Qt::TimeSpec spec; // spec if used by QDateTimeEdit Context context; }; diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index ca04c2bd44..77f7ba963b 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2433,7 +2433,7 @@ Qt::LayoutDirection QLocale::textDirection() const */ QString QLocale::toUpper(const QString &str) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) bool ok = true; QString result = QIcu::toUpper(d->bcp47Name('_'), str, &ok); if (ok) @@ -2457,7 +2457,7 @@ QString QLocale::toUpper(const QString &str) const */ QString QLocale::toLower(const QString &str) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) bool ok = true; const QString result = QIcu::toLower(d->bcp47Name('_'), str, &ok); if (ok) diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 74d8e5f381..7749f66b8e 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -134,7 +134,7 @@ Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_MOVABLE_TYPE); #endif -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) namespace QIcu { QString toUpper(const QByteArray &localeId, const QString &str, bool *ok); QString toLower(const QByteArray &localeId, const QString &str, bool *ok); diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 406eb31923..94ed47f898 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -399,7 +399,9 @@ void QMapDataBase::freeData(QMapDataBase *d) With QMap, the items are always sorted by key. \li The key type of a QHash must provide operator==() and a global qHash(Key) function. The key type of a QMap must provide - operator<() specifying a total order. + operator<() specifying a total order. Since Qt 5.8.1 it is also safe + to use a pointer type as key, even if the underlying operator<() + does not provide a total order. \endlist Here's an example QMap with QString keys and \c int values: diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 96ce787446..3f4f034b4e 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -51,6 +51,7 @@ #include <map> #include <new> +#include <functional> #ifdef Q_COMPILER_INITIALIZER_LISTS #include <initializer_list> @@ -61,11 +62,8 @@ QT_BEGIN_NAMESPACE /* QMap uses qMapLessThanKey() to compare keys. The default implementation uses operator<(). For pointer types, - qMapLessThanKey() casts the pointers to integers before it - compares them, because operator<() is undefined on pointers - that come from different memory blocks. (In practice, this - is only a problem when running a program such as - BoundsChecker.) + qMapLessThanKey() uses std::less (because operator<() on + pointers can be used only between pointers in the same array). */ template <class Key> inline bool qMapLessThanKey(const Key &key1, const Key &key2) @@ -75,8 +73,7 @@ template <class Key> inline bool qMapLessThanKey(const Key &key1, const Key &key template <class Ptr> inline bool qMapLessThanKey(const Ptr *key1, const Ptr *key2) { - Q_STATIC_ASSERT(sizeof(quintptr) == sizeof(const Ptr *)); - return quintptr(key1) < quintptr(key2); + return std::less<const Ptr *>()(key1, key2); } struct QMapDataBase; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index be6f8af8d7..8cf058f035 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2316,21 +2316,20 @@ QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) */ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) { - int i = 0; - ushort c = ch.unicode(); - if (cs == Qt::CaseSensitive) { - while (i < d->size) - if (d->data()[i] == ch) - remove(i, 1); - else - i++; - } else { - c = foldCase(c); - while (i < d->size) - if (foldCase(d->data()[i]) == c) - remove(i, 1); - else - i++; + const int idx = indexOf(ch, 0, cs); + if (idx != -1) { + const auto first = begin(); // implicit detach() + auto last = end(); + if (cs == Qt::CaseSensitive) { + last = std::remove(first + idx, last, ch); + } else { + const QChar c = ch.toCaseFolded(); + auto caseInsensEqual = [c](QChar x) { + return c == x.toCaseFolded(); + }; + last = std::remove_if(first + idx, last, caseInsensEqual); + } + resize(last - first); } return *this; } @@ -3277,6 +3276,23 @@ static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *nee return -1; } +static inline int lastIndexOfHelper( + const QStringRef &haystack, int from, const QStringRef &needle, Qt::CaseSensitivity cs) +{ + return lastIndexOfHelper(reinterpret_cast<const ushort*>(haystack.unicode()), from, + reinterpret_cast<const ushort*>(needle.unicode()), needle.size(), cs); +} + +static inline int lastIndexOfHelper( + const QStringRef &haystack, int from, QLatin1String needle, Qt::CaseSensitivity cs) +{ + const int size = needle.size(); + QVarLengthArray<ushort> s(size); + qt_from_latin1(s.data(), needle.latin1(), size); + return lastIndexOfHelper(reinterpret_cast<const ushort*>(haystack.unicode()), from, + s.data(), size, cs); +} + /*! Returns the index position of the last occurrence of the string \a str in this string, searching backward from index position \a @@ -5576,7 +5592,7 @@ int QString::localeAwareCompare(const QString &other) const return localeAwareCompare_helper(constData(), length(), other.constData(), other.length()); } -#if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_DARWIN) +#if QT_CONFIG(icu) && !defined(Q_OS_WIN32) && !defined(Q_OS_DARWIN) Q_GLOBAL_STATIC(QThreadStorage<QCollator>, defaultCollator) #endif @@ -5622,7 +5638,7 @@ int QString::localeAwareCompare_helper(const QChar *data1, int length1, CFRelease(thisString); CFRelease(otherString); return result; -#elif defined(QT_USE_ICU) +#elif QT_CONFIG(icu) if (!defaultCollator()->hasLocalData()) defaultCollator()->setLocalData(QCollator()); return defaultCollator()->localData().compare(data1, length1, data2, length2); @@ -9836,6 +9852,27 @@ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const return qt_last_index_of(unicode(), size(), ch, from, cs); } +template<typename T> +static int last_index_of_impl(const QStringRef &haystack, int from, const T &needle, Qt::CaseSensitivity cs) +{ + const int sl = needle.size(); + if (sl == 1) + return haystack.lastIndexOf(needle.at(0), from, cs); + + const int l = haystack.size(); + if (from < 0) + from += l; + int delta = l - sl; + if (from == l && sl == 0) + return from; + if (uint(from) >= uint(l) || delta < 0) + return -1; + if (from > delta) + from = delta; + + return lastIndexOfHelper(haystack, from, needle, cs); +} + /*! \since 4.8 \overload lastIndexOf() @@ -9853,25 +9890,7 @@ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - const int sl = str.size(); - if (sl == 1) - return lastIndexOf(str.at(0), from, cs); - - const int l = size(); - if (from < 0) - from += l; - int delta = l - sl; - if (from == l && sl == 0) - return from; - if (uint(from) >= uint(l) || delta < 0) - return -1; - if (from > delta) - from = delta; - - QVarLengthArray<ushort> s(sl); - qt_from_latin1(s.data(), str.latin1(), sl); - - return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, s.data(), sl, cs); + return last_index_of_impl(*this, from, str, cs); } /*! @@ -9891,24 +9910,7 @@ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) */ int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - const int sl = str.size(); - if (sl == 1) - return lastIndexOf(str.at(0), from, cs); - - const int l = size(); - if (from < 0) - from += l; - int delta = l - sl; - if (from == l && sl == 0) - return from; - if (uint(from) >= uint(l) || delta < 0) - return -1; - if (from > delta) - from = delta; - - return lastIndexOfHelper(reinterpret_cast<const ushort*>(unicode()), from, - reinterpret_cast<const ushort*>(str.unicode()), - str.size(), cs); + return last_index_of_impl(*this, from, str, cs); } /*! diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index e423d9af0c..359c2d0bdb 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -54,11 +54,11 @@ QT_BEGIN_NAMESPACE static QTimeZonePrivate *newBackendTimeZone() { #ifdef QT_NO_SYSTEMLOCALE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return new QIcuTimeZonePrivate(); #else return new QUtcTimeZonePrivate(); -#endif // QT_USE_ICU +#endif #else #if defined Q_OS_MAC return new QMacTimeZonePrivate(); @@ -69,7 +69,7 @@ static QTimeZonePrivate *newBackendTimeZone() // Registry based timezone backend not available on WinRT #elif defined Q_OS_WIN return new QWinTimeZonePrivate(); -#elif defined QT_USE_ICU +#elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(); #else return new QUtcTimeZonePrivate(); @@ -81,11 +81,11 @@ static QTimeZonePrivate *newBackendTimeZone() static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) { #ifdef QT_NO_SYSTEMLOCALE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return new QIcuTimeZonePrivate(ianaId); #else return new QUtcTimeZonePrivate(ianaId); -#endif // QT_USE_ICU +#endif #else #if defined Q_OS_MAC return new QMacTimeZonePrivate(ianaId); @@ -96,7 +96,7 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) // Registry based timezone backend not available on WinRT #elif defined Q_OS_WIN return new QWinTimeZonePrivate(ianaId); -#elif defined QT_USE_ICU +#elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(ianaId); #else return new QUtcTimeZonePrivate(ianaId); diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp index 8ec675a696..ea8f6d1438 100644 --- a/src/corelib/tools/qtimezoneprivate.cpp +++ b/src/corelib/tools/qtimezoneprivate.cpp @@ -725,7 +725,7 @@ template<> QTimeZonePrivate *QSharedDataPointer<QTimeZonePrivate>::clone() } /* - UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and QT_USE_ICU not set, + UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and ICU is not being used, or for QDateTimes with a Qt:Spec of Qt::OffsetFromUtc. */ diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h index 21f1f38fa8..c397c18aac 100644 --- a/src/corelib/tools/qtimezoneprivate_p.h +++ b/src/corelib/tools/qtimezoneprivate_p.h @@ -56,9 +56,9 @@ #include "qlocale_p.h" #include "qvector.h" -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) #include <unicode/ucal.h> -#endif // QT_USE_ICU +#endif #ifdef Q_OS_MAC #ifdef __OBJC__ @@ -227,7 +227,7 @@ private: int m_offsetFromUtc; }; -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) class Q_AUTOTEST_EXPORT QIcuTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate { public: @@ -268,7 +268,7 @@ private: UCalendar *m_ucal; }; -#endif // QT_USE_ICU +#endif #if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined Q_OS_ANDROID struct QTzTransitionTime @@ -337,9 +337,9 @@ private: QVector<QTzTransitionTime> m_tranTimes; QVector<QTzTransitionRule> m_tranRules; QList<QByteArray> m_abbreviations; -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) mutable QSharedDataPointer<QTimeZonePrivate> m_icu; -#endif // QT_USE_ICU +#endif QByteArray m_posixRule; }; #endif // Q_OS_UNIX diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 747c0042dd..38dff88919 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -598,18 +598,18 @@ static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArra // Create the system default time zone QTzTimeZonePrivate::QTzTimeZonePrivate() -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) : m_icu(0) -#endif // QT_USE_ICU +#endif { init(systemTimeZoneId()); } // Create a named time zone QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) : m_icu(0) -#endif // QT_USE_ICU +#endif { init(ianaId); } @@ -617,9 +617,9 @@ QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) QTzTimeZonePrivate::QTzTimeZonePrivate(const QTzTimeZonePrivate &other) : QTimeZonePrivate(other), m_tranTimes(other.m_tranTimes), m_tranRules(other.m_tranRules), m_abbreviations(other.m_abbreviations), -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) m_icu(other.m_icu), -#endif // QT_USE_ICU +#endif m_posixRule(other.m_posixRule) { } @@ -820,7 +820,7 @@ QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, QTimeZone::NameType nameType, const QLocale &locale) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files @@ -830,7 +830,7 @@ QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, #else Q_UNUSED(nameType) Q_UNUSED(locale) -#endif // QT_USE_ICU +#endif return abbreviation(atMSecsSinceEpoch); } @@ -838,7 +838,7 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType, const QLocale &locale) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files @@ -849,7 +849,7 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, Q_UNUSED(timeType) Q_UNUSED(nameType) Q_UNUSED(locale) -#endif // QT_USE_ICU +#endif // If no ICU available then have to use abbreviations instead // Abbreviations don't have GenericTime if (timeType == QTimeZone::GenericTime) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index c3ac104399..1530299303 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -76,7 +76,8 @@ public: QVarLengthArray(std::initializer_list<T> args) : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array)) { - append(args.begin(), args.size()); + if (args.size()) + append(args.begin(), args.size()); } #endif diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index ad41630978..ab5997635a 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -144,7 +144,6 @@ qtConfig(icu) { SOURCES += tools/qlocale_icu.cpp \ tools/qcollator_icu.cpp - DEFINES += QT_USE_ICU } else: win32 { SOURCES += tools/qcollator_win.cpp } else: macx { |