diff options
Diffstat (limited to 'src/corelib')
24 files changed, 339 insertions, 223 deletions
diff --git a/src/corelib/arch/macosx/arch.pri b/src/corelib/arch/macosx/arch.pri index e42a962..a2b1bf7 100644 --- a/src/corelib/arch/macosx/arch.pri +++ b/src/corelib/arch/macosx/arch.pri @@ -1,7 +1,6 @@ # # Mac OS X architecture # -!*-icc*:!*-g++* { - contains($$list($$system(uname -m)), .*86):SOURCES += $$QT_ARCH_CPP/../i386/qatomic.s - else:SOURCES += $$QT_ARCH_CPP/../powerpc/qatomic32.s -} + +# Left blank intentionally since all the current compilers that we support can +# handle in-line assembly. diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 32c6aef..d4e5d44 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1560,7 +1560,7 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba) */ QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec) { - const uint arraySize = ba.size(); + const int arraySize = ba.size(); if (arraySize > 3) { if ((uchar)ba[0] == 0x00 diff --git a/src/corelib/concurrent/qtconcurrentthreadengine.cpp b/src/corelib/concurrent/qtconcurrentthreadengine.cpp index 5356e82..c6bde85 100644 --- a/src/corelib/concurrent/qtconcurrentthreadengine.cpp +++ b/src/corelib/concurrent/qtconcurrentthreadengine.cpp @@ -47,6 +47,81 @@ QT_BEGIN_NAMESPACE namespace QtConcurrent { +ThreadEngineBarrier::ThreadEngineBarrier() +:count(0) { } + +void ThreadEngineBarrier::acquire() +{ + forever { + int localCount = int(count); + if (localCount < 0) { + if (count.testAndSetOrdered(localCount, localCount -1)) + return; + } else { + if (count.testAndSetOrdered(localCount, localCount + 1)) + return; + } + } +} + +int ThreadEngineBarrier::release() +{ + forever { + int localCount = int(count); + if (localCount == -1) { + if (count.testAndSetOrdered(-1, 0)) { + semaphore.release(); + return 0; + } + } else if (localCount < 0) { + if (count.testAndSetOrdered(localCount, localCount + 1)) + return qAbs(localCount + 1); + } else { + if (count.testAndSetOrdered(localCount, localCount - 1)) + return localCount - 1; + } + } +} + +// Wait until all threads have been released +void ThreadEngineBarrier::wait() +{ + forever { + int localCount = int(count); + if (localCount == 0) + return; + + Q_ASSERT(localCount > 0); // multiple waiters are not allowed. + if (count.testAndSetOrdered(localCount, -localCount)) { + semaphore.acquire(); + return; + } + } +} + +int ThreadEngineBarrier::currentCount() +{ + return int(count); +} + +// releases a thread, unless this is the last thread. +// returns true if the thread was released. +bool ThreadEngineBarrier::releaseUnlessLast() +{ + forever { + int localCount = int(count); + if (qAbs(localCount) == 1) { + return false; + } else if (localCount < 0) { + if (count.testAndSetOrdered(localCount, localCount + 1)) + return true; + } else { + if (count.testAndSetOrdered(localCount, localCount - 1)) + return true; + } + } +} + ThreadEngineBase::ThreadEngineBase() :futureInterface(0), threadPool(QThreadPool::globalInstance()) { @@ -66,7 +141,7 @@ void ThreadEngineBase::startSingleThreaded() void ThreadEngineBase::startBlocking() { start(); - semaphore.acquire(); + barrier.acquire(); startThreads(); bool throttled = false; @@ -88,10 +163,10 @@ void ThreadEngineBase::startBlocking() #endif if (throttled == false) { - semaphore.release(); + barrier.release(); } - semaphore.wait(); + barrier.wait(); finish(); exceptionStore.throwPossibleException(); } @@ -101,6 +176,11 @@ void ThreadEngineBase::startThread() startThreadInternal(); } +void ThreadEngineBase::acquireBarrierSemaphore() +{ + barrier.acquire(); +} + bool ThreadEngineBase::isCanceled() { if (futureInterface) @@ -138,9 +218,9 @@ bool ThreadEngineBase::startThreadInternal() if (this->isCanceled()) return false; - semaphore.acquire(); + barrier.acquire(); if (!threadPool->tryStart(this)) { - semaphore.release(); + barrier.release(); return false; } return true; @@ -155,7 +235,7 @@ void ThreadEngineBase::startThreads() void ThreadEngineBase::threadExit() { const bool asynchronous = futureInterface != 0; - const int lastThread = (semaphore.release() == 0); + const int lastThread = (barrier.release() == 0); if (lastThread && asynchronous) this->asynchronousFinish(); @@ -166,7 +246,7 @@ void ThreadEngineBase::threadExit() // this function returns one. bool ThreadEngineBase::threadThrottleExit() { - return semaphore.releaseUnlessLast(); + return barrier.releaseUnlessLast(); } void ThreadEngineBase::run() // implements QRunnable. diff --git a/src/corelib/concurrent/qtconcurrentthreadengine.h b/src/corelib/concurrent/qtconcurrentthreadengine.h index 6f1c7e7..1f359fc 100644 --- a/src/corelib/concurrent/qtconcurrentthreadengine.h +++ b/src/corelib/concurrent/qtconcurrentthreadengine.h @@ -51,6 +51,8 @@ #include <QtCore/qdebug.h> #include <QtCore/qtconcurrentexception.h> #include <QtCore/qwaitcondition.h> +#include <QtCore/qatomic.h> +#include <QtCore/qsemaphore.h> QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -61,55 +63,29 @@ QT_MODULE(Core) namespace QtConcurrent { -// A Semaphore that can wait until all resources are returned. -class ThreadEngineSemaphore +// The ThreadEngineBarrier counts worker threads, and allows one +// thread to wait for all others to finish. Tested for its use in +// QtConcurrent, requires more testing for use as a general class. +class ThreadEngineBarrier { -public: - ThreadEngineSemaphore() - :count(0) { } - - void acquire() - { - QMutexLocker lock(&mutex); - ++count; - } - - int release() - { - QMutexLocker lock(&mutex); - if (--count == 0) - waitCondition.wakeAll(); - return count; - } - - // Wait until all resources are released. - void wait() - { - QMutexLocker lock(&mutex); - if (count != 0) - waitCondition.wait(&mutex); - } - - int currentCount() - { - return count; - } - - // releases a resource, unless this is the last resource. - // returns true if a resource was released. - bool releaseUnlessLast() - { - QMutexLocker lock(&mutex); - if (count == 1) - return false; - --count; - return true; - } - private: + // The thread count is maintained as an integer in the count atomic + // variable. The count can be either positive or negative - a negative + // count signals that a thread is waiting on the barrier. + + // BC note: inlined code from Qt < 4.6 will expect to find the QMutex + // and QAtomicInt here. ### Qt 5: remove. QMutex mutex; - int count; - QWaitCondition waitCondition; + QAtomicInt count; + + QSemaphore semaphore; +public: + ThreadEngineBarrier(); + void acquire(); + int release(); + void wait(); + int currentCount(); + bool releaseUnlessLast(); }; enum ThreadFunctionResult { ThrottleThread, ThreadFinished }; @@ -132,6 +108,7 @@ public: bool isProgressReportingEnabled(); void setProgressValue(int progress); void setProgressRange(int minimum, int maximum); + void acquireBarrierSemaphore(); protected: // The user overrides these: virtual void start() {} @@ -152,7 +129,7 @@ private: protected: QFutureInterfaceBase *futureInterface; QThreadPool *threadPool; - ThreadEngineSemaphore semaphore; + ThreadEngineBarrier barrier; QtConcurrent::internal::ExceptionStore exceptionStore; }; @@ -199,7 +176,7 @@ public: QFuture<T> future = QFuture<T>(futureInterfaceTyped()); start(); - semaphore.acquire(); + acquireBarrierSemaphore(); threadPool->start(this); return future; } diff --git a/src/corelib/concurrent/qthreadpool.cpp b/src/corelib/concurrent/qthreadpool.cpp index 83374da..9c53b7e 100644 --- a/src/corelib/concurrent/qthreadpool.cpp +++ b/src/corelib/concurrent/qthreadpool.cpp @@ -222,6 +222,8 @@ void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority) int QThreadPoolPrivate::activeThreadCount() const { + // To improve scalability this function is called without holding + // the mutex lock -- keep it thread-safe. return (allThreads.count() - expiredThreads.count() - waitingThreads @@ -481,6 +483,12 @@ bool QThreadPool::tryStart(QRunnable *runnable) return false; Q_D(QThreadPool); + + // To improve scalability perform a check on the thread count + // before locking the mutex. + if (d->allThreads.isEmpty() == false && d->activeThreadCount() >= d->maxThreadCount) + return false; + QMutexLocker locker(&d->mutex); return d->tryStart(runnable); } @@ -527,7 +535,6 @@ void QThreadPool::setExpiryTimeout(int expiryTimeout) int QThreadPool::maxThreadCount() const { Q_D(const QThreadPool); - QMutexLocker locker(&d->mutex); return d->maxThreadCount; } @@ -556,7 +563,6 @@ void QThreadPool::setMaxThreadCount(int maxThreadCount) int QThreadPool::activeThreadCount() const { Q_D(const QThreadPool); - QMutexLocker locker(&d->mutex); return d->activeThreadCount(); } diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri index 8991379..0fe757d 100644 --- a/src/corelib/global/global.pri +++ b/src/corelib/global/global.pri @@ -1,5 +1,4 @@ # Qt kernel library base module -linux-g++*:QMAKE_LFLAGS += -Wl,-e,qt_core_init_boilerplate HEADERS += \ global/qglobal.h \ @@ -19,3 +18,9 @@ INCLUDEPATH += $$QT_BUILD_TREE/src/corelib/global # Only used on platforms with CONFIG += precompile_header PRECOMPILED_HEADER = global/qt_pch.h + +linux-g++*:!static { + QMAKE_LFLAGS += -Wl,-e,qt_core_boilerplate + prog=$$quote(if (/program interpreter: (.*)]/) { print $1; }) + DEFINES += ELF_INTERPRETER=\\\"$$system(readelf -l /bin/ls | perl -n -e \'$$prog\')\\\" +} diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 0721c39..afc3f58 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -279,6 +279,10 @@ namespace QT_NAMESPACE {} # endif #endif +#if defined(Q_OS_MAC64) && !defined(QT_MAC_USE_COCOA) +#error "You are building a 64-bit application, but using a 32-bit version of Qt. Check your build configuration." +#endif + #if defined(Q_OS_MSDOS) || defined(Q_OS_OS2) || defined(Q_OS_WIN) # undef Q_OS_UNIX #elif !defined(Q_OS_UNIX) @@ -381,6 +385,9 @@ namespace QT_NAMESPACE {} # define Q_OUTOFLINE_TEMPLATE inline # define Q_NO_TEMPLATE_FRIENDS # define QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION +# define Q_ALIGNOF(type) __alignof(type) +# define Q_DECL_ALIGN(n) __declspec(align(n)) + /* Visual C++.Net issues for _MSC_VER >= 1300 */ # if _MSC_VER >= 1300 # define Q_CC_MSVC_NET @@ -467,6 +474,11 @@ namespace QT_NAMESPACE {} # define Q_NO_USING_KEYWORD # define QT_NO_STL_WCHAR # endif +# if __GNUC__ >= 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) +# define Q_ALIGNOF(type) __alignof__(type) +# define Q_TYPEOF(expr) __typeof__(expr) +# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) +# endif /* GCC 3.1 and GCC 3.2 wrongly define _SB_CTYPE_MACROS on HP-UX */ # if defined(Q_OS_HPUX) && __GNUC__ == 3 && __GNUC_MINOR__ >= 1 # define Q_WRONG_SB_CTYPE_MACROS @@ -520,6 +532,11 @@ namespace QT_NAMESPACE {} # define Q_OUTOFLINE_TEMPLATE inline # define Q_BROKEN_TEMPLATE_SPECIALIZATION # define Q_CANNOT_DELETE_CONSTANT +# elif __xlC__ >= 0x0600 +# define Q_ALIGNOF(type) __alignof__(type) +# define Q_TYPEOF(expr) __typeof__(expr) +# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) +# define Q_PACKED __attribute__((__packed__)) # endif /* Older versions of DEC C++ do not define __EDG__ or __EDG - observed @@ -643,6 +660,13 @@ namespace QT_NAMESPACE {} # if __SUNPRO_CC < 0x570 # define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS # endif + /* see http://developers.sun.com/sunstudio/support/Ccompare.html */ +# if __SUNPRO_CC >= 0x590 +# define Q_ALIGNOF(type) __alignof__(type) +# define Q_TYPEOF(expr) __typeof__(expr) +# define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) +# define Q_DECL_EXPORT __attribute__((__visibility__("default"))) +# endif # if !defined(_BOOL) # define Q_NO_BOOL_TYPE # endif @@ -672,8 +696,17 @@ namespace QT_NAMESPACE {} # if defined(__HP_aCC) || __cplusplus >= 199707L # define Q_NO_TEMPLATE_FRIENDS # define Q_CC_HPACC -# ifdef QT_ARCH_PARISC +# if __HP_aCC-0 < 060000 # define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS +# define Q_DECL_EXPORT __declspec(dllexport) +# define Q_DECL_IMPORT __declspec(dllimport) +# endif +# if __HP_aCC-0 >= 061200 +# define Q_DECL_ALIGNED(n) __attribute__((aligned(n))) +# endif +# if __HP_aCC-0 >= 062000 +# define Q_DECL_EXPORT __attribute__((visibility("default")) +# define Q_DECL_IMPORT Q_DECL_EXPORT # endif # else # define Q_CC_HP diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index b53eba8..2ce9229 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -483,16 +483,15 @@ QLibraryInfo::location(LibraryLocation loc) QT_END_NAMESPACE -#if defined(Q_CC_GNU) && defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) && !defined(QT_BOOTSTRAPPED) - +#if defined(Q_CC_GNU) && defined(ELF_INTERPRETER) # include <stdio.h> # include <stdlib.h> extern const char qt_core_interpreter[] __attribute__((section(".interp"))) - = "/lib/ld-linux.so.2"; + = ELF_INTERPRETER; extern "C" -void qt_core_init_boilerplate() +void qt_core_boilerplate() { printf("This is the QtCore library version " QT_VERSION_STR "\n" "Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 2023327..0006026 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -491,6 +491,10 @@ public: WA_WState_WindowOpacitySet = 119, // internal WA_TranslucentBackground = 120, + WA_AcceptTouchEvents = 121, + WA_WState_AcceptedTouchBeginEvent = 122, + WA_TouchPadAcceptSingleTouchEvents = 123, + // Add new attributes before this line WA_AttributeCount }; @@ -1546,6 +1550,55 @@ public: enum Initialization { Uninitialized }; + + enum TouchPointState { + TouchPointPressed = 0x01, + TouchPointMoved = 0x02, + TouchPointStationary = 0x04, + TouchPointReleased = 0x08, + TouchPointStateMask = 0x0f, + + TouchPointPrimary = 0x10 + }; + Q_DECLARE_FLAGS(TouchPointStates, TouchPointState) + + enum GestureType + { + UnknownGesture, + TapGesture, + DoubleTapGesture, + TrippleTapGesture, + TapAndHoldGesture, + PanGesture, + PinchGesture + }; + + + enum GestureState + { + NoGesture, + GestureStarted = 1, + GestureUpdated = 2, + GestureFinished = 3 + }; + + enum DirectionType + { + NoDirection = 0, + LeftDownDirection = 1, + DownLeftDirection = LeftDownDirection, + DownDirection = 2, + RightDownDirection = 3, + DownRightDirection = RightDownDirection, + LeftDirection = 4, + RightDirection = 6, + LeftUpDirection = 7, + UpLeftDirection = LeftUpDirection, + UpDirection = 8, + RightUpDirection = 9, + UpRightDirection = RightUpDirection + }; + } #ifdef Q_MOC_RUN ; @@ -1565,6 +1618,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::DropActions) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::ItemFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MatchFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TextInteractionFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TouchPointStates) typedef bool (*qInternalCallback)(void **); diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 144436c..4743a47 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -558,24 +558,8 @@ static bool _q_isMacHidden(const QString &path) FSRef fsRef; -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - err = FSPathMakeRefWithOptions(reinterpret_cast<const UInt8 *>(QFile::encodeName(QDir::cleanPath(path)).constData()), - kFSPathMakeRefDoNotFollowLeafSymlink, &fsRef, 0); - } else -#endif - { - QFileInfo fi(path); - FSRef parentRef; - err = FSPathMakeRef(reinterpret_cast<const UInt8 *>(fi.absoluteDir().absolutePath().toUtf8().constData()), - &parentRef, 0); - if (err == noErr) { - QString fileName = fi.fileName(); - err = FSMakeFSRefUnicode(&parentRef, fileName.length(), - reinterpret_cast<const UniChar *>(fileName.unicode()), - kTextEncodingUnknown, &fsRef); - } - } + err = FSPathMakeRefWithOptions(reinterpret_cast<const UInt8 *>(QFile::encodeName(QDir::cleanPath(path)).constData()), + kFSPathMakeRefDoNotFollowLeafSymlink, &fsRef, 0); if (err != noErr) return false; diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 1b2f777..62ab0c4 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -341,6 +341,8 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) Q_D(QFSFileEngine); Q_ASSERT(!isReallyOpen()); + openMode |= QIODevice::ReadWrite; + if (!filePathIsTemplate) return QFSFileEngine::open(openMode); @@ -758,7 +760,6 @@ bool QTemporaryFile::open(OpenMode flags) } } - flags |= QIODevice::ReadWrite; if (QFile::open(flags)) { d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName); return true; diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 7916e23..504ae84 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -222,6 +222,11 @@ QT_BEGIN_NAMESPACE \value ZOrderChange The widget's z-order has changed. This event is never sent to top level windows. \value KeyboardLayoutChange The keyboard layout has changed. \value DynamicPropertyChange A dynamic property was added, changed or removed from the object. + \value TouchBegin Beginning of a sequence of touch-screen and/or track-pad events (QTouchEvent) + \value TouchUpdate Touch-screen event (QTouchEvent) + \value TouchEnd End of touch-event sequence (QTouchEvent) + \value Gesture A gesture has occured. + \value GraphicsSceneGesture A gesture has occured on a graphics scene. User events should have values between \c User and \c{MaxUser}: diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index be61139..4929c51 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -272,7 +272,14 @@ public: Signal = 192, Wrapped = 193, - // 512 reserved for Qt Jambi's MetaCall event + TouchBegin = 194, + TouchUpdate = 195, + TouchEnd = 196, + + Gesture = 197, + GraphicsSceneGesture = 198, + + // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event User = 1000, // first user event id @@ -310,6 +317,9 @@ private: friend class Q3AccelManager; friend class QShortcutMap; friend class QETWidget; + friend class QGraphicsView; + friend class QGraphicsViewPrivate; + friend class QGraphicsScenePrivate; }; class Q_CORE_EXPORT QTimerEvent : public QEvent diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 260be26..215f6ae 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -218,8 +218,14 @@ QObject *QMetaObject::newInstance(QGenericArgument val0, QGenericArgument val8, QGenericArgument val9) const { + QByteArray constructorName = className(); + { + int idx = constructorName.lastIndexOf(':'); + if (idx != -1) + constructorName.remove(0, idx+1); // remove qualified part + } QVarLengthArray<char, 512> sig; - sig.append(className(), qstrlen(className())); + sig.append(constructorName.constData(), constructorName.length()); sig.append('('); enum { MaximumParamCount = 10 }; diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 6844d3e..e923844 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -448,7 +448,7 @@ inline void qVariantSetValue(QVariant &v, const T &t) //if possible we reuse the current QVariant private const int type = qMetaTypeId<T>(reinterpret_cast<T *>(0)); QVariant::Private &d = v.data_ptr(); - if (type <= int(QVariant::Char) || (type == d.type && v.isDetached())) { + if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) { d.type = type; T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo<T>::isComplex) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 09cc47f..6674717 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -1848,8 +1848,7 @@ QTime QTime::currentTime() #else time_t ltime; // no millisecond resolution ::time(<ime); - tm *t = 0; - localtime(<ime); + const tm *const t = localtime(<ime); ct.mds = MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + 1000 * t->tm_sec; #endif return ct; @@ -4398,6 +4397,13 @@ int QDateTimeParser::sectionMaxSize(Section s, int count) const case DateSectionMask: qWarning("QDateTimeParser::sectionMaxSize: Invalid section %s", sectionName(s).toLatin1().constData()); + + case NoSectionIndex: + case FirstSectionIndex: + case LastSectionIndex: + case CalendarPopupIndex: + // these cases can't happen + break; } return -1; } diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index ec931d3..3201958 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -138,13 +138,6 @@ public: PossibleBoth = 4 }; - enum { - NoSectionIndex = -1, - FirstSectionIndex = -2, - LastSectionIndex = -3, - CalendarPopupIndex = -4 - }; - enum Section { NoSection = 0x00000, AmPmSection = 0x00001, @@ -163,7 +156,12 @@ public: DateSectionMask = (DaySection|MonthSection|YearSection|YearSection2Digits|DayOfWeekSection), FirstSection = 0x02000|Internal, LastSection = 0x04000|Internal, - CalendarPopupSection = 0x08000|Internal + CalendarPopupSection = 0x08000|Internal, + + NoSectionIndex = -1, + FirstSectionIndex = -2, + LastSectionIndex = -3, + CalendarPopupIndex = -4 }; // duplicated from qdatetimeedit.h Q_DECLARE_FLAGS(Sections, Section) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index cbdd32c..8c1a0ff 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -1011,21 +1011,17 @@ static QString macMonthName(int month, bool short_format) if (month < 0 || month > 11) return QString(); -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - QCFType<CFDateFormatterRef> formatter - = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), - kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); - QCFType<CFArrayRef> values - = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, - short_format ? kCFDateFormatterShortMonthSymbols - : kCFDateFormatterMonthSymbols)); - if (values != 0) { - CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month)); - return QCFString::toQString(cfstring); - } + QCFType<CFDateFormatterRef> formatter + = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), + kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); + QCFType<CFArrayRef> values + = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, + short_format ? kCFDateFormatterShortMonthSymbols + : kCFDateFormatterMonthSymbols)); + if (values != 0) { + CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, month)); + return QCFString::toQString(cfstring); } -#endif return QString(); } @@ -1035,20 +1031,16 @@ static QString macDayName(int day, bool short_format) if (day < 1 || day > 7) return QString(); -#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { - QCFType<CFDateFormatterRef> formatter - = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), - kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); - QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, - short_format ? kCFDateFormatterShortWeekdaySymbols - : kCFDateFormatterWeekdaySymbols)); - if (values != 0) { - CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7)); - return QCFString::toQString(cfstring); - } + QCFType<CFDateFormatterRef> formatter + = CFDateFormatterCreate(0, QCFType<CFLocaleRef>(CFLocaleCopyCurrent()), + kCFDateFormatterNoStyle, kCFDateFormatterNoStyle); + QCFType<CFArrayRef> values = static_cast<CFArrayRef>(CFDateFormatterCopyProperty(formatter, + short_format ? kCFDateFormatterShortWeekdaySymbols + : kCFDateFormatterWeekdaySymbols)); + if (values != 0) { + CFStringRef cfstring = static_cast<CFStringRef>(CFArrayGetValueAtIndex(values, day % 7)); + return QCFString::toQString(cfstring); } -#endif return QString(); } diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 2082794..b4fe070 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -2154,48 +2154,42 @@ bool QRectF::contains(const QRectF &r) const QRectF QRectF::operator|(const QRectF &r) const { - qreal l1 = xp; - qreal r1 = xp; - if (w < 0) - l1 += w; - else - r1 += w; - if (l1 == r1) // null rect + if (isNull()) return r; + if (r.isNull()) + return *this; - qreal l2 = r.xp; - qreal r2 = r.xp; - if (r.w < 0) - l2 += r.w; + qreal left = xp; + qreal right = xp; + if (w < 0) + left += w; else - r2 += r.w; - if (l2 == r2) // null rect - return *this; + right += w; - qreal t1 = yp; - qreal b1 = yp; + if (r.w < 0) { + left = qMin(left, r.xp + r.w); + right = qMax(right, r.xp); + } else { + left = qMin(left, r.xp); + right = qMax(right, r.xp + r.w); + } + + qreal top = yp; + qreal bottom = yp; if (h < 0) - t1 += h; + top += h; else - b1 += h; - if (t1 == b1) // null rect - return r; + bottom += h; - qreal t2 = r.yp; - qreal b2 = r.yp; - if (r.h < 0) - t2 += r.h; - else - b2 += r.h; - if (t2 == b2) // null rect - return *this; + if (r.h < 0) { + top = qMin(top, r.yp + r.h); + bottom = qMax(bottom, r.yp); + } else { + top = qMin(top, r.yp); + bottom = qMax(bottom, r.yp + r.h); + } - QRectF tmp; - tmp.xp = qMin(l1, l2); - tmp.yp = qMin(t1, t2); - tmp.w = qMax(r1, r2) - tmp.xp; - tmp.h = qMax(b1, b2) - tmp.yp; - return tmp; + return QRectF(left, top, right - left, bottom - top); } /*! diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 0740fe5..efdc24d 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -653,7 +653,7 @@ inline QRectF::QRectF(const QRect &r) } inline bool QRectF::isNull() const -{ return qIsNull(w) && qIsNull(h); } +{ return w == 0. && h == 0.; } inline bool QRectF::isEmpty() const { return w <= 0. || h <= 0.; } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 928805a..2797622 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -48,6 +48,8 @@ #pragma qt_sync_stop_processing #endif +#include <QtCore/qatomic.h> + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -85,9 +87,8 @@ namespace QtSharedPointer { template <class T> class InternalRefCount; template <class T> class ExternalRefCount; - template <class X, class T> QSharedPointer<X> qStrongRefFromWeakHelper(const QWeakPointer<T> &, X*); - template <class X, class T> QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<T> &src, X *); - template <class X, class T> QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<T> &src, X *); + template <class X, class T> QSharedPointer<X> strongRefFromWeakHelper(const QWeakPointer<T> &, X*); + template <class X, class Y> QSharedPointer<X> copyAndSetPointer(X * ptr, const QSharedPointer<Y> &src); // used in debug mode to verify the reuse of pointers Q_CORE_EXPORT void internalSafetyCheckAdd(const volatile void *); @@ -138,14 +139,14 @@ namespace QtSharedPointer { inline void internalConstruct(T *ptr) { -#ifndef QT_NO_DEBUG +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS if (ptr) internalSafetyCheckAdd(ptr); #endif value = ptr; } inline void internalDestroy() { -#ifndef QT_NO_DEBUG +#ifdef QT_SHAREDPOINTER_TRACK_POINTERS if (value) internalSafetyCheckRemove(value); #endif } @@ -237,10 +238,8 @@ namespace QtSharedPointer { #else template <class X> friend class ExternalRefCount; template <class X> friend class QWeakPointer; - template <class X, class Y> friend QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<Y> &src, X *); - template <class X, class Y> friend QSharedPointer<X> qSharedPointerDynamicCastHelper(const QSharedPointer<Y> &src, X *); - template <class X, class Y> friend QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<Y> &src, X *); - template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::qStrongRefFromWeakHelper(const QWeakPointer<Y> &src, X *); + template <class X, class Y> friend QSharedPointer<X> copyAndSetPointer(X * ptr, const QSharedPointer<Y> &src); + template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::strongRefFromWeakHelper(const QWeakPointer<Y> &src, X *); #endif inline void internalSet(Data *o, T *actual) @@ -290,9 +289,9 @@ public: } inline QSharedPointer(const QWeakPointer<T> &other) - { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T*>(0)); } + { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T*>(0)); } inline QSharedPointer<T> &operator=(const QWeakPointer<T> &other) - { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T*>(0)); return *this; } + { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T*>(0)); return *this; } template <class X> inline QSharedPointer(const QSharedPointer<X> &other) { *this = other; } @@ -307,11 +306,11 @@ public: template <class X> inline QSharedPointer(const QWeakPointer<X> &other) - { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T *>(0)); } + { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T *>(0)); } template <class X> inline QSharedPointer<T> &operator=(const QWeakPointer<X> &other) - { *this = qStrongRefFromWeakHelper(other, static_cast<T *>(0)); return *this; } + { *this = strongRefFromWeakHelper(other, static_cast<T *>(0)); return *this; } template <class X> QSharedPointer<X> staticCast() const @@ -415,7 +414,7 @@ private: #if defined(Q_NO_TEMPLATE_FRIENDS) public: #else - template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::qStrongRefFromWeakHelper(const QWeakPointer<Y> &src, X *); + template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::strongRefFromWeakHelper(const QWeakPointer<Y> &src, X *); #endif inline void internalSet(Data *o, T *actual) @@ -486,47 +485,14 @@ Q_INLINE_TEMPLATE QWeakPointer<T> QSharedPointer<T>::toWeakRef() const namespace QtSharedPointer { // helper functions: template <class X, class T> - Q_INLINE_TEMPLATE X *qVerifyStaticCast(T *src, X *) - { - return static_cast<X *>(src); // if you get an error in this line, the cast is invalid - } - template <class X, class T> - Q_INLINE_TEMPLATE X *qVerifyDynamicCast(T *src, X *) - { - return dynamic_cast<X *>(src); // if you get an error in this line, the cast is invalid - } - template <class X, class T> - Q_INLINE_TEMPLATE X *qVerifyConstCast(T *src, X *) - { - return const_cast<X *>(src); // if you get an error in this line, the cast is invalid - } - - template <class X, class T> - Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<T> &src, X *) - { - QSharedPointer<X> result; - register T *ptr = src.data(); - result.internalSet(src.d, static_cast<X *>(ptr)); - return result; - } - template <class X, class T> - Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCastHelper(const QSharedPointer<T> &src, X *) - { - QSharedPointer<X> result; - register T *ptr = src.data(); - result.internalSet(src.d, dynamic_cast<X *>(ptr)); - return result; - } - template <class X, class T> - Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<T> &src, X *) + Q_INLINE_TEMPLATE QSharedPointer<X> copyAndSetPointer(X *ptr, const QSharedPointer<T> &src) { QSharedPointer<X> result; - register T *ptr = src.data(); - result.internalSet(src.d, const_cast<X *>(ptr)); + result.internalSet(src.d, ptr); return result; } template <class X, class T> - Q_INLINE_TEMPLATE QSharedPointer<X> qStrongRefFromWeakHelper + Q_INLINE_TEMPLATE QSharedPointer<X> strongRefFromWeakHelper (const QT_PREPEND_NAMESPACE(QWeakPointer<T>) &src, X *) { QSharedPointer<X> result; @@ -539,9 +505,8 @@ namespace QtSharedPointer { template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &src) { - X *x = 0; - QtSharedPointer::qVerifyStaticCast(src.data(), x); - return QtSharedPointer::qSharedPointerCastHelper(src, x); + register X *ptr = static_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid + return QtSharedPointer::copyAndSetPointer(ptr, src); } template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &src) @@ -552,8 +517,8 @@ Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &sr template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src) { - X *x = 0; - return QtSharedPointer::qSharedPointerDynamicCastHelper(src, x); + register X *ptr = dynamic_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid + return QtSharedPointer::copyAndSetPointer(ptr, src); } template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src) @@ -564,14 +529,13 @@ Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src) { - X *x = 0; - return QtSharedPointer::qSharedPointerConstCastHelper(src, x); + register X *ptr = const_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid + return QtSharedPointer::copyAndSetPointer(ptr, src); } template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src) { - X *x = 0; - return QtSharedPointer::qSharedPointerConstCastHelper(src, x); + return qSharedPointerConstCast<X, T>(src.toStrongRef()); } template <class X, class T> diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3ff263d..71482f5 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -169,7 +169,7 @@ static int ucstricmp(const ushort *a, const ushort *ae, const uchar *b) // Unicode case-insensitive comparison static int ucstrcmp(const QChar *a, int alen, const QChar *b, int blen) { - if (a == b) + if (a == b && alen == blen) return 0; int l = qMin(alen, blen); while (l-- && *a == *b) diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index aea0c6c..c93a065 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -28,6 +28,8 @@ HEADERS += \ tools/qregexp.h \ tools/qringbuffer_p.h \ tools/qshareddata.h \ + tools/qsharedpointer.h \ + tools/qsharedpointer_impl.h \ tools/qset.h \ tools/qsize.h \ tools/qstack.h \ diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index f1487f7..1fc2a9f 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -3410,11 +3410,12 @@ void QXmlStreamWriter::writeComment(const QString &text) { Q_D(QXmlStreamWriter); Q_ASSERT(!text.contains(QLatin1String("--")) && !text.endsWith(QLatin1Char('-'))); - if (!d->finishStartElement() && d->autoFormatting) + if (!d->finishStartElement(false) && d->autoFormatting) d->indent(d->tagStack.size()); d->write("<!--"); d->write(text); d->write("-->"); + d->inStartElement = d->lastWasStartElement = false; } |