From b404cd930e32520f8ad62088c9ed31f33ce95933 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Thu, 4 Apr 2019 17:17:59 +0300 Subject: Make qt_is_ascii work properly on big endian systems Change-Id: Ia053fbc854a77e333edadb0be6c2e04826b8fbdb Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index d8bfb69a8b..4852d20082 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -501,7 +501,11 @@ bool qt_is_ascii(const char *&ptr, const char *end) Q_DECL_NOTHROW while (ptr + 4 <= end) { quint32 data = qFromUnaligned(ptr); if (data &= 0x80808080U) { +#if Q_BYTE_ORDER == Q_BIG_ENDIAN + uint idx = qCountLeadingZeroBits(data); +#else uint idx = qCountTrailingZeroBits(data); +#endif ptr += idx / 8; return false; } -- cgit v1.2.3 From 6d049ad63d1044da2287f5736b9863323be2be0c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 4 Apr 2019 16:33:59 +0200 Subject: Remove unused static method The only use of this method got removed already in commit bebae3737624. Change-Id: I9757cbe34710efd9a9d31c74f81e01da40453ff9 Reviewed-by: Thiago Macieira Reviewed-by: Joerg Bornemann --- src/corelib/io/qstandardpaths_win.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 1809861fc6..c2c3b2702b 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -86,15 +86,6 @@ static void appendOrganizationAndApp(QString &path) // Courtesy qstandardpaths_u #endif } -static inline QString displayName(QStandardPaths::StandardLocation type) -{ -#ifndef QT_BOOTSTRAPPED - return QStandardPaths::displayName(type); -#else - return QString::number(type); -#endif -} - static inline void appendTestMode(QString &path) { if (QStandardPaths::isTestModeEnabled()) -- cgit v1.2.3 From 6ce2a87c23bbaacece7d32df276f64a0058e447d Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 26 Mar 2019 14:07:03 +0100 Subject: Forward declare all types required for compilation with `-trace` This patch fixes compilation with `-trace lttng` or `-trace etw`. We need to forward declare QEvent, QImageReader etc., otherwise the types will be unknown while compiling the trace points. In order to handle this generically, the tracegen utility is extended to support a 'prefix text' in the `*.tracepoints` input files. Any text within curly braces will be embedded as-is in the generated file. This can then be used to add forward declarations for the types we need, including potential namespaces and such. Change-Id: I5cb16763ce0fcb48ce3ea4577578d468ff3a4f4b Reviewed-by: Konstantin Tokarev --- src/corelib/qtcore.tracepoints | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/qtcore.tracepoints b/src/corelib/qtcore.tracepoints index 33734a4274..a9a08071f3 100644 --- a/src/corelib/qtcore.tracepoints +++ b/src/corelib/qtcore.tracepoints @@ -1,3 +1,9 @@ +{ +QT_BEGIN_NAMESPACE +class QEvent; +QT_END_NAMESPACE +} + QCoreApplicationPrivate_init_entry() QCoreApplicationPrivate_init_exit() -- cgit v1.2.3 From 5f62202e6c89269da3e9faaea4c88d0f19416cc1 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 26 Mar 2019 15:23:48 +0100 Subject: Add tracepoint to qt_message_print This allows us to deduce a lot about what a Qt application is doing, since the debug output usually contains a lot of information. Change-Id: I28a18afd151a1640a44ba8c7c9cd87d5d66c99b0 Reviewed-by: Christoph Sterz Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 3 +++ src/corelib/qtcore.tracepoints | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 168934c202..30232170fb 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -57,6 +57,7 @@ #include "private/qloggingregistry_p.h" #include "private/qcoreapplication_p.h" #include "private/qsimd_p.h" +#include #endif #ifdef Q_OS_WIN #include @@ -1811,6 +1812,8 @@ static void ungrabMessageHandler() { } static void qt_message_print(QtMsgType msgType, const QMessageLogContext &context, const QString &message) { #ifndef QT_BOOTSTRAPPED + Q_TRACE(qt_message_print, msgType, context.category, context.function, context.file, context.line, message); + // qDebug, qWarning, ... macros do not check whether category is enabled if (isDefaultCategory(context.category)) { if (QLoggingCategory *defaultCategory = QLoggingCategory::defaultCategory()) { diff --git a/src/corelib/qtcore.tracepoints b/src/corelib/qtcore.tracepoints index a9a08071f3..f9018acdbf 100644 --- a/src/corelib/qtcore.tracepoints +++ b/src/corelib/qtcore.tracepoints @@ -38,3 +38,5 @@ QMetaObject_activate_begin_slot_functor(void *slotObject) QMetaObject_activate_end_slot_functor(void *slotObject) QMetaObject_activate_begin_declarative_signal(QObject *sender, int signalIndex) QMetaObject_activate_end_declarative_signal(QObject *sender, int signalIndex) + +qt_message_print(int type, const char *category, const char *function, const char *file, int line, const QString &message) -- cgit v1.2.3 From 127518deda5a05fda2ce24be98aaaeb7b975f163 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 27 Mar 2019 13:56:57 +0100 Subject: Introduce Q_TRACE_SCOPE to simplify tracing of a function entry/exit Additionally, we also add a Q_TRACE_EXIT which runs a trace point when the scope is exited, leveraging qScopeGuard behind the scenes. Q_TRACE_SCOPE uses Q_TRACE_EXIT internally - the difference is that the _SCOPE version enforces the naming scheme of _entry / _exit for the tracepoints, whereas Q_TRACE_EXIT can be used generically. Change-Id: I4a2f5ea09f451fcf664d07fd493b679f7527ac06 Reviewed-by: Thiago Macieira --- src/corelib/global/qtrace_p.h | 17 ++++++++++++++++- src/corelib/kernel/qcoreapplication.cpp | 4 +--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qtrace_p.h b/src/corelib/global/qtrace_p.h index 3d04a7311d..20f2beac98 100644 --- a/src/corelib/global/qtrace_p.h +++ b/src/corelib/global/qtrace_p.h @@ -52,11 +52,18 @@ // /* - * The Qt tracepoints API consists of only three macros: + * The Qt tracepoints API consists of only five macros: * * - Q_TRACE(tracepoint, args...) * Fires 'tracepoint' if it is enabled. * + * - Q_TRACE_EXIT(tracepoint, args...) + * Fires 'tracepoint' if it is enabled when the current scope exists. + * + * - Q_TRACE_SCOPE(tracepoint, args...) + * Wrapper around Q_TRACE/_EXIT to trace entry and exit. First it traces + * `${tracepoint}_entry` and then `${tracepoint}_exit` on scope exit. + * * - Q_UNCONDITIONAL_TRACE(tracepoint, args...) * Fires 'tracepoint' unconditionally: no check is performed to query * whether 'tracepoint' is enabled. @@ -110,15 +117,23 @@ */ #include +#include QT_BEGIN_NAMESPACE #if defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED) # define Q_TRACE(x, ...) QtPrivate::trace_ ## x(__VA_ARGS__) +# define Q_TRACE_EXIT(x, ...) \ + const auto qTraceExit_ ## x ## __COUNTER__ = qScopeGuard([&]() { Q_TRACE(x, __VA_ARGS__); }); +# define Q_TRACE_SCOPE(x, ...) \ + Q_TRACE(x ## _entry, __VA_ARGS__); \ + Q_TRACE_EXIT(x ## _exit, __VA_ARGS__); # define Q_UNCONDITIONAL_TRACE(x, ...) QtPrivate::do_trace_ ## x(__VA_ARGS__) # define Q_TRACE_ENABLED(x) QtPrivate::trace_ ## x ## _enabled() #else # define Q_TRACE(x, ...) +# define Q_TRACE_EXIT(x, ...) +# define Q_TRACE_SCOPE(x, ...) # define Q_UNCONDITIONAL_TRACE(x, ...) # define Q_TRACE_ENABLED(x) false #endif // defined(Q_TRACEPOINT) && !defined(QT_BOOTSTRAPPED) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 6d7985c91b..d173ec029b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -778,7 +778,7 @@ QCoreApplication::QCoreApplication(int &argc, char **argv void QCoreApplicationPrivate::init() { - Q_TRACE(QCoreApplicationPrivate_init_entry); + Q_TRACE_SCOPE(QCoreApplicationPrivate_init); #if defined(Q_OS_MACOS) QMacAutoReleasePool pool; @@ -883,8 +883,6 @@ void QCoreApplicationPrivate::init() #ifndef QT_NO_QOBJECT is_app_running = true; // No longer starting up. #endif - - Q_TRACE(QCoreApplicationPrivate_init_exit); } /*! -- cgit v1.2.3 From f4c41b9797f08f173049502fa7bd465cf5bde938 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 27 Mar 2019 14:00:21 +0100 Subject: Add missing _exit tracepoints for event handling This allows tools that look for matching `foo_entry/exit` pairs in the trace data to work properly. An unmatched `_entry` would otherwise confuse them, making them think that the call stack is continuously increasing. Change-Id: Idff7f587ea25c46ec86ad623cc82d503db34a194 Reviewed-by: Christoph Sterz Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 4 ++-- src/corelib/qtcore.tracepoints | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index d173ec029b..596941b5a9 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1197,7 +1197,7 @@ bool QCoreApplicationPrivate::notify_helper(QObject *receiver, QEvent * event) { // Note: when adjusting the tracepoints in here // consider adjusting QApplicationPrivate::notify_helper too. - Q_TRACE(QCoreApplication_notify_entry, receiver, event, event->type()); + Q_TRACE_SCOPE(QCoreApplication_notify, receiver, event, event->type()); // send to all application event filters (only does anything in the main thread) if (QCoreApplication::self @@ -1489,7 +1489,7 @@ bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event) */ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) { - Q_TRACE(QCoreApplication_postEvent_entry, receiver, event, event->type()); + Q_TRACE_SCOPE(QCoreApplication_postEvent, receiver, event, event->type()); if (receiver == 0) { qWarning("QCoreApplication::postEvent: Unexpected null receiver"); diff --git a/src/corelib/qtcore.tracepoints b/src/corelib/qtcore.tracepoints index f9018acdbf..3a70136741 100644 --- a/src/corelib/qtcore.tracepoints +++ b/src/corelib/qtcore.tracepoints @@ -16,6 +16,7 @@ QEvent_ctor(QEvent *event, int type) QEvent_dtor(QEvent *event, int type) QCoreApplication_postEvent_entry(QObject *receiver, QEvent *event, int type) +QCoreApplication_postEvent_exit(QObject *receiver, QEvent *event, int type) QCoreApplication_postEvent_event_compressed(QObject *receiver, QEvent *event) QCoreApplication_postEvent_event_posted(QObject *receiver, QEvent *event, int type) @@ -23,6 +24,7 @@ QCoreApplication_sendEvent(QObject *receiver, QEvent *event, int type) QCoreApplication_sendSpontaneousEvent(QObject *receiver, QEvent *event, int type) QCoreApplication_notify_entry(QObject *receiver, QEvent *event, int type) +QCoreApplication_notify_exit(QObject *receiver, QEvent *event, int type) QCoreApplication_notify_event_filtered(QObject *receiver, QEvent *event, int type) QCoreApplication_notify_before_delivery(QObject *receiver, QEvent *event, int type) QCoreApplication_notify_after_delivery(QObject *receiver, QEvent *event, int type, bool consumed) -- cgit v1.2.3 From 82ad4be4a2e0c2bccb6cd8ea2440aefee4ec48ec Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 27 Mar 2019 17:01:40 +0000 Subject: Fix various uncommon cases in QTzTimeZonePrivate backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Includes a fixup for 03fadc26e7617aece89949bc7d0acf50f6f050a9, which removed the check on empty transition list, needed when no data are available. Ensured that such a data-free zone would in fact be noticed as invalid during init(). Fixed handling of times before the epoch (we still want to consult a POSIX rule, if that's all that's available) while ensuring we (as documented) ignore DST for such times. Fixed handling of large times (milliseconds since epoch outside int range) when looking up POSIX rules. Gave QTimeZonePrivate a YearRange enum (to be moved to QTimeZone once this merges up to dev) so as to eliminate a magic number (and avoid adding another). Moved year-munging in POSIX rules after the one early return, which doesn't need the year range. Added test-cases for the distant past/future (just checking UTC's offsets; SLES has a minimal version of the UTC data-file that triggers the bugs fixed here for them). Fixes: QTBUG-74666 Fixes: QTBUG-74550 Change-Id: Ief7b7e55c62cf11064700934f404b2fc283614e1 Reviewed-by: Tony Sarajärvi Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime_p.h | 4 +++ src/corelib/tools/qtimezoneprivate_tz.cpp | 55 ++++++++++++++++++------------- 2 files changed, 37 insertions(+), 22 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 4d30d4192b..b3d00745d0 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -140,6 +140,10 @@ public: // Inlined for its one caller in qdatetime.cpp inline void setUtcOffsetByTZ(qint64 atMSecsSinceEpoch); #endif // timezone + + // ### Qt 5.14: expose publicly in QDateTime + // The first and last years of which QDateTime can represent some part: + enum class YearRange : qint32 { First = -292275056, Last = +292278994 }; }; QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index f75a61977d..7d85bc077d 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -39,6 +39,7 @@ #include "qtimezone.h" #include "qtimezoneprivate_p.h" +#include "qdatetime_p.h" // ### Qt 5.14: remove once YearRange is on QDateTime #include #include @@ -520,19 +521,14 @@ PosixZone PosixZone::parse(const char *&pos, const char *end) static QVector calculatePosixTransitions(const QByteArray &posixRule, int startYear, int endYear, - int lastTranMSecs) + qint64 lastTranMSecs) { QVector result; - // Limit year by qint64 max size for msecs - if (startYear > 292278994) - startYear = 292278994; - if (endYear > 292278994) - endYear = 292278994; - // POSIX Format is like "TZ=CST6CDT,M3.2.0/2:00:00,M11.1.0/2:00:00" // i.e. "std offset dst [offset],start[/time],end[/time]" - // See the section about TZ at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html + // See the section about TZ at + // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html QList parts = posixRule.split(','); PosixZone stdZone, dstZone = PosixZone::invalid(); @@ -583,6 +579,13 @@ static QVector calculatePosixTransitions(const QByteArra else stdTime = QTime(2, 0, 0); + // Limit year to the range QDateTime can represent: + const int minYear = int(QDateTimePrivate::YearRange::First); + const int maxYear = int(QDateTimePrivate::YearRange::Last); + startYear = qBound(minYear, startYear, maxYear); + endYear = qBound(minYear, endYear, maxYear); + Q_ASSERT(startYear <= endYear); + for (int year = startYear; year <= endYear; ++year) { QTimeZonePrivate::Data dstData; QDateTime dst(calculatePosixDate(dstDateRule, year), dstTime, Qt::UTC); @@ -598,13 +601,16 @@ static QVector calculatePosixTransitions(const QByteArra stdData.standardTimeOffset = stdZone.offset; stdData.daylightTimeOffset = 0; stdData.abbreviation = stdZone.name; - // Part of the high year will overflow - if (year == 292278994 && (dstData.atMSecsSinceEpoch < 0 || stdData.atMSecsSinceEpoch < 0)) { + // Part of maxYear will overflow (likewise for minYear, below): + if (year == maxYear && (dstData.atMSecsSinceEpoch < 0 || stdData.atMSecsSinceEpoch < 0)) { if (dstData.atMSecsSinceEpoch > 0) { result << dstData; } else if (stdData.atMSecsSinceEpoch > 0) { result << stdData; } + } else if (year < 1970) { // We ignore DST before the epoch. + if (year > minYear || stdData.atMSecsSinceEpoch != QTimeZonePrivate::invalidMSecs()) + result << stdData; } else if (dst < std) { result << dstData << stdData; } else { @@ -794,6 +800,8 @@ void QTzTimeZonePrivate::init(const QByteArray &ianaId) tran.atMSecsSinceEpoch = tz_tran.tz_time * 1000; m_tranTimes.append(tran); } + if (m_tranTimes.isEmpty() && m_posixRule.isEmpty()) + return; // Invalid after all ! if (ianaId.isEmpty()) m_id = systemTimeZoneId(); @@ -954,22 +962,25 @@ QVector QTzTimeZonePrivate::getPosixTransitions(qint64 m QTimeZonePrivate::Data QTzTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const { // If the required time is after the last transition (or there were none) - // and we have a POSIX rule then use it: - if ((m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < forMSecsSinceEpoch) - && !m_posixRule.isEmpty() && forMSecsSinceEpoch >= 0) { + // and we have a POSIX rule, then use it: + if (!m_posixRule.isEmpty() + && (m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < forMSecsSinceEpoch)) { QVector posixTrans = getPosixTransitions(forMSecsSinceEpoch); auto it = std::partition_point(posixTrans.cbegin(), posixTrans.cend(), [forMSecsSinceEpoch] (const QTimeZonePrivate::Data &at) { return at.atMSecsSinceEpoch <= forMSecsSinceEpoch; }); - if (it > posixTrans.cbegin()) { - QTimeZonePrivate::Data data = *--it; + // Use most recent, if any in the past; or the first if we have no other rules: + if (it > posixTrans.cbegin() || (m_tranTimes.isEmpty() && it < posixTrans.cend())) { + QTimeZonePrivate::Data data = *(it > posixTrans.cbegin() ? it - 1 : it); data.atMSecsSinceEpoch = forMSecsSinceEpoch; return data; } } + if (m_tranTimes.isEmpty()) // Only possible if !isValid() + return invalidData(); - // Otherwise, if we can find a valid tran, then use its rule: + // Otherwise, use the rule for the most recent or first transition: auto last = std::partition_point(m_tranTimes.cbegin(), m_tranTimes.cend(), [forMSecsSinceEpoch] (const QTzTransitionTime &at) { return at.atMSecsSinceEpoch <= forMSecsSinceEpoch; @@ -989,9 +1000,9 @@ bool QTzTimeZonePrivate::hasTransitions() const QTimeZonePrivate::Data QTzTimeZonePrivate::nextTransition(qint64 afterMSecsSinceEpoch) const { // If the required time is after the last transition (or there were none) - // and we have a POSIX rule then use it: - if ((m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < afterMSecsSinceEpoch) - && !m_posixRule.isEmpty() && afterMSecsSinceEpoch >= 0) { + // and we have a POSIX rule, then use it: + if (!m_posixRule.isEmpty() + && (m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < afterMSecsSinceEpoch)) { QVector posixTrans = getPosixTransitions(afterMSecsSinceEpoch); auto it = std::partition_point(posixTrans.cbegin(), posixTrans.cend(), [afterMSecsSinceEpoch] (const QTimeZonePrivate::Data &at) { @@ -1012,9 +1023,9 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::nextTransition(qint64 afterMSecsSince QTimeZonePrivate::Data QTzTimeZonePrivate::previousTransition(qint64 beforeMSecsSinceEpoch) const { // If the required time is after the last transition (or there were none) - // and we have a POSIX rule then use it: - if ((m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < beforeMSecsSinceEpoch) - && !m_posixRule.isEmpty() && beforeMSecsSinceEpoch > 0) { + // and we have a POSIX rule, then use it: + if (!m_posixRule.isEmpty() + && (m_tranTimes.isEmpty() || m_tranTimes.last().atMSecsSinceEpoch < beforeMSecsSinceEpoch)) { QVector posixTrans = getPosixTransitions(beforeMSecsSinceEpoch); auto it = std::partition_point(posixTrans.cbegin(), posixTrans.cend(), [beforeMSecsSinceEpoch] (const QTimeZonePrivate::Data &at) { -- cgit v1.2.3 From fe7a8d61d1428f4d316c2a6884d8dfb8190520f0 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 3 Apr 2019 14:14:32 +0200 Subject: Update precompiled headers Include many headers that are commonly used now, and avoid listing them twice. Change-Id: I679dc24cff2cb3a3c9c18585ec78007ab3550743 Reviewed-by: Thiago Macieira --- src/corelib/global/qt_pch.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/global/qt_pch.h b/src/corelib/global/qt_pch.h index 76e46374c3..3972991618 100644 --- a/src/corelib/global/qt_pch.h +++ b/src/corelib/global/qt_pch.h @@ -60,12 +60,18 @@ # undef _POSIX_ #endif #include +#include +#include #include #include /* All moc genereated code has this include */ #include #include +#include +#include #include #include +#include +#include #if QT_CONFIG(textcodec) #include #endif -- cgit v1.2.3