From ece0c0a5e7e0b18beb58ccd868bde54c7be64f78 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 22 Nov 2019 14:46:58 +0100 Subject: Tidy nullptr usage Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/corelib/thread/qexception.cpp | 2 +- src/corelib/thread/qfutureinterface.cpp | 2 +- src/corelib/thread/qmutex.cpp | 6 +++--- src/corelib/thread/qmutex_linux.cpp | 4 ++-- src/corelib/thread/qorderedmutexlocker_p.h | 2 +- src/corelib/thread/qreadwritelock.cpp | 6 +++--- src/corelib/thread/qresultstore.cpp | 2 +- src/corelib/thread/qthread.cpp | 6 +++--- src/corelib/thread/qthread_unix.cpp | 24 ++++++++++++------------ src/corelib/thread/qthreadstorage.cpp | 12 ++++++------ src/corelib/thread/qwaitcondition_unix.cpp | 2 +- 11 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/corelib/thread') diff --git a/src/corelib/thread/qexception.cpp b/src/corelib/thread/qexception.cpp index a3e30d5a7a..f9c63085b7 100644 --- a/src/corelib/thread/qexception.cpp +++ b/src/corelib/thread/qexception.cpp @@ -199,7 +199,7 @@ void ExceptionStore::setException(const QException &e) bool ExceptionStore::hasException() const { - return (exceptionHolder.exception() != 0); + return (exceptionHolder.exception() != nullptr); } ExceptionHolder ExceptionStore::exception() diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 6430f38a3b..f1fd40e7b6 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -471,7 +471,7 @@ bool QFutureInterfaceBase::derefT() const QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState) : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0), state(initialState), - manualProgress(false), m_expectedResultCount(0), runnable(0), m_pool(0) + manualProgress(false), m_expectedResultCount(0), runnable(nullptr), m_pool(nullptr) { progressTime.invalidate(); } diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index 9e52f286ee..f3883278e3 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -70,7 +70,7 @@ class QRecursiveMutexPrivate : public QMutexData { public: QRecursiveMutexPrivate() - : QMutexData(QMutex::Recursive), owner(0), count(0) {} + : QMutexData(QMutex::Recursive), owner(nullptr), count(0) {} // written to by the thread that first owns 'mutex'; // read during attempts to acquire ownership of 'mutex' from any other thread: @@ -186,7 +186,7 @@ public: */ QMutex::QMutex(RecursionMode mode) { - d_ptr.storeRelaxed(mode == Recursive ? new QRecursiveMutexPrivate : 0); + d_ptr.storeRelaxed(mode == Recursive ? new QRecursiveMutexPrivate : nullptr); } /*! @@ -799,7 +799,7 @@ inline void QRecursiveMutexPrivate::unlock() noexcept if (count > 0) { count--; } else { - owner.storeRelaxed(0); + owner.storeRelaxed(nullptr); mutex.QBasicMutex::unlock(); } } diff --git a/src/corelib/thread/qmutex_linux.cpp b/src/corelib/thread/qmutex_linux.cpp index 3270875471..72002838cf 100644 --- a/src/corelib/thread/qmutex_linux.cpp +++ b/src/corelib/thread/qmutex_linux.cpp @@ -106,7 +106,7 @@ static inline QMutexData *dummyFutexValue() } template static inline -bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = 0) noexcept +bool lockInternal_helper(QBasicAtomicPointer &d_ptr, int timeout = -1, QElapsedTimer *elapsedTimer = nullptr) noexcept { if (!IsTimed) timeout = -1; @@ -175,7 +175,7 @@ void QBasicMutex::unlockInternal() noexcept Q_UNUSED(d); Q_ASSERT(!isRecursive()); - d_ptr.storeRelease(0); + d_ptr.storeRelease(nullptr); futexWakeOne(d_ptr); } diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index 570c526225..83edfd5879 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -69,7 +69,7 @@ class QOrderedMutexLocker public: QOrderedMutexLocker(QBasicMutex *m1, QBasicMutex *m2) : mtx1((m1 == m2) ? m1 : (std::less()(m1, m2) ? m1 : m2)), - mtx2((m1 == m2) ? 0 : (std::less()(m1, m2) ? m2 : m1)), + mtx2((m1 == m2) ? nullptr : (std::less()(m1, m2) ? m2 : m1)), locked(false) { relock(); diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp index c8463de402..8c28507d5a 100644 --- a/src/corelib/thread/qreadwritelock.cpp +++ b/src/corelib/thread/qreadwritelock.cpp @@ -227,7 +227,7 @@ bool QReadWriteLock::tryLockForRead(int timeout) return true; while (true) { - if (d == 0) { + if (d == nullptr) { if (!d_ptr.testAndSetAcquire(nullptr, dummyLockedForRead, d)) continue; return true; @@ -341,7 +341,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout) return true; while (true) { - if (d == 0) { + if (d == nullptr) { if (!d_ptr.testAndSetAcquire(d, dummyLockedForWrite, d)) continue; return true; @@ -581,7 +581,7 @@ void QReadWriteLockPrivate::recursiveUnlock() if (self == currentWriter) { if (--writerCount > 0) return; - currentWriter = 0; + currentWriter = nullptr; } else { auto it = currentReaders.find(self); if (it == currentReaders.end()) { diff --git a/src/corelib/thread/qresultstore.cpp b/src/corelib/thread/qresultstore.cpp index 1b3bc20eca..0b82b938e1 100644 --- a/src/corelib/thread/qresultstore.cpp +++ b/src/corelib/thread/qresultstore.cpp @@ -192,7 +192,7 @@ int ResultStoreBase::addResults(int index, const void *results, int vectorSize, ResultItem filteredIn(results, vectorSize); insertResultItem(index, filteredIn); } - ResultItem filteredAway(0, totalCount - vectorSize); + ResultItem filteredAway(nullptr, totalCount - vectorSize); return insertResultItem(index + vectorSize, filteredAway); } } diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 791b765880..d3bb372b00 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE QThreadData::QThreadData(int initialRefCount) : _ref(initialRefCount), loopLevel(0), scopeLevel(0), - eventDispatcher(0), + eventDispatcher(nullptr), quitNow(false), canWait(true), isAdopted(false), requiresCoreApplication(true) { // fprintf(stderr, "QThreadData %p created\n", this); @@ -399,7 +399,7 @@ QThreadPrivate::~QThreadPrivate() QThread *QThread::currentThread() { QThreadData *data = QThreadData::current(); - Q_ASSERT(data != 0); + Q_ASSERT(data != nullptr); return data->thread.loadAcquire(); } @@ -451,7 +451,7 @@ QThread::~QThread() if (d->running && !d->finished && !d->data->isAdopted) qFatal("QThread: Destroyed while thread is still running"); - d->data->thread = 0; + d->data->thread = nullptr; } } diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 62f0179802..1da68b3130 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -109,7 +109,7 @@ Q_STATIC_ASSERT(sizeof(pthread_t) <= sizeof(Qt::HANDLE)); enum { ThreadPriorityResetFlag = 0x80000000 }; -static thread_local QThreadData *currentThreadData = 0; +static thread_local QThreadData *currentThreadData = nullptr; static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT; static pthread_key_t current_thread_data_key; @@ -144,7 +144,7 @@ static void destroy_current_thread_data(void *p) #if defined(Q_OS_VXWORKS) (void *)1); #else - 0); + nullptr); #endif } @@ -182,8 +182,8 @@ static void set_thread_data(QThreadData *data) static void clear_thread_data() { - currentThreadData = 0; - pthread_setspecific(current_thread_data_key, 0); + currentThreadData = nullptr; + pthread_setspecific(current_thread_data_key, nullptr); } template @@ -226,7 +226,7 @@ QThreadData *QThreadData::current(bool createIfNecessary) } QT_CATCH(...) { clear_thread_data(); data->deref(); - data = 0; + data = nullptr; QT_RETHROW; } data->deref(); @@ -294,7 +294,7 @@ static void setCurrentThreadName(const char *name) void *QThreadPrivate::start(void *arg) { #if !defined(Q_OS_ANDROID) - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr); #endif pthread_cleanup_push(QThreadPrivate::finish, arg); @@ -336,7 +336,7 @@ void *QThreadPrivate::start(void *arg) emit thr->started(QThread::QPrivateSignal()); #if !defined(Q_OS_ANDROID) - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); pthread_testcancel(); #endif thr->run(); @@ -360,7 +360,7 @@ void *QThreadPrivate::start(void *arg) // thrown. pthread_cleanup_pop(1); - return 0; + return nullptr; } void QThreadPrivate::finish(void *arg) @@ -379,13 +379,13 @@ void QThreadPrivate::finish(void *arg) void *data = &d->data->tls; locker.unlock(); emit thr->finished(QThread::QPrivateSignal()); - QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QThreadStorageData::finish((void **)data); locker.relock(); QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher.loadRelaxed(); if (eventDispatcher) { - d->data->eventDispatcher = 0; + d->data->eventDispatcher = nullptr; locker.unlock(); eventDispatcher->closingDown(); delete eventDispatcher; @@ -774,14 +774,14 @@ bool QThread::wait(QDeadlineTimer deadline) void QThread::setTerminationEnabled(bool enabled) { QThread *thr = currentThread(); - Q_ASSERT_X(thr != 0, "QThread::setTerminationEnabled()", + Q_ASSERT_X(thr != nullptr, "QThread::setTerminationEnabled()", "Current thread was not started with QThread."); Q_UNUSED(thr) #if defined(Q_OS_ANDROID) Q_UNUSED(enabled); #else - pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, NULL); + pthread_setcancelstate(enabled ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE, nullptr); if (enabled) pthread_testcancel(); #endif diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index fdc484d2d2..464559ffa5 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -116,7 +116,7 @@ void **QThreadStorageData::get() const QThreadData *data = QThreadData::current(); if (!data) { qWarning("QThreadStorage::get: QThreadStorage can only be used with threads started with QThread"); - return 0; + return nullptr; } QVector &tls = data->tls; if (tls.size() <= id) @@ -128,7 +128,7 @@ void **QThreadStorageData::get() const *v, data->thread.loadRelaxed()); - return *v ? v : 0; + return *v ? v : nullptr; } void **QThreadStorageData::set(void *p) @@ -136,7 +136,7 @@ void **QThreadStorageData::set(void *p) QThreadData *data = QThreadData::current(); if (!data) { qWarning("QThreadStorage::set: QThreadStorage can only be used with threads started with QThread"); - return 0; + return nullptr; } QVector &tls = data->tls; if (tls.size() <= id) @@ -144,7 +144,7 @@ void **QThreadStorageData::set(void *p) void *&value = tls[id]; // delete any previous data - if (value != 0) { + if (value != nullptr) { DEBUG_MSG("QThreadStorageData: Deleting previous storage %d, data %p, for thread %p", id, value, @@ -156,7 +156,7 @@ void **QThreadStorageData::set(void *p) locker.unlock(); void *q = value; - value = 0; + value = nullptr; if (destructor) destructor(q); @@ -178,7 +178,7 @@ void QThreadStorageData::finish(void **p) while (!tls->isEmpty()) { void *&value = tls->last(); void *q = value; - value = 0; + value = nullptr; int i = tls->size() - 1; tls->resize(i); diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp index a8dfb9999c..80f9e780e7 100644 --- a/src/corelib/thread/qwaitcondition_unix.cpp +++ b/src/corelib/thread/qwaitcondition_unix.cpp @@ -173,7 +173,7 @@ public: QWaitCondition::QWaitCondition() { d = new QWaitConditionPrivate; - report_error(pthread_mutex_init(&d->mutex, NULL), "QWaitCondition", "mutex init"); + report_error(pthread_mutex_init(&d->mutex, nullptr), "QWaitCondition", "mutex init"); qt_initialize_pthread_cond(&d->cond, "QWaitCondition"); d->waiters = d->wakeups = 0; } -- cgit v1.2.3