diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-14 15:04:18 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-06-07 17:19:16 +0200 |
commit | b4ead572501179244aa036e7a590fa7536929f2b (patch) | |
tree | f1e706b221e78e294b3169965c005df768730203 /src/corelib/kernel | |
parent | 327bfdb671e0e263c6fb027133a54985a65194c4 (diff) |
Move away from using 0 as a pointer constant
Cleans up most of corelib to use nullptr or default enums
where appropriate.
Change-Id: Ifcaac14ecdaaee730f87f10941db3ce407d71ef9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 22 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreglobaldata.cpp | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 66 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype_p.h | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatypeswitcher_p.h | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemerror.cpp | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 44 |
7 files changed, 82 insertions, 74 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 72aaac44a6..a48a7c80f2 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -216,11 +216,11 @@ QString QCoreApplicationPrivate::appVersion() const } #endif -QString *QCoreApplicationPrivate::cachedApplicationFilePath = 0; +QString *QCoreApplicationPrivate::cachedApplicationFilePath = nullptr; bool QCoreApplicationPrivate::checkInstance(const char *function) { - bool b = (QCoreApplication::self != 0); + bool b = (QCoreApplication::self != nullptr); if (!b) qWarning("QApplication::%s: Please instantiate the QApplication object first", function); return b; @@ -257,7 +257,7 @@ void QCoreApplicationPrivate::processCommandLineArguments() } if (j < argc) { - argv[j] = 0; + argv[j] = nullptr; argc = j; } } @@ -367,11 +367,11 @@ Q_CORE_EXPORT uint qGlobalPostedEventsCount() return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset; } -QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0; +QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = nullptr; #endif // QT_NO_QOBJECT -QCoreApplication *QCoreApplication::self = 0; +QCoreApplication *QCoreApplication::self = nullptr; uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents) | (1 << Qt::AA_SynthesizeMouseForUnhandledTabletEvents); @@ -455,12 +455,12 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint , aboutToQuitEmitted(false) , threadData_clean(false) #else - , q_ptr(0) + , q_ptr(nullptr) #endif { app_compile_version = flags & 0xffffff; static const char *const empty = ""; - if (argc == 0 || argv == 0) { + if (argc == 0 || argv == nullptr) { argc = 0; argv = const_cast<char **>(&empty); } @@ -886,7 +886,7 @@ QCoreApplication::~QCoreApplication() { qt_call_post_routines(); - self = 0; + self = nullptr; #ifndef QT_NO_QOBJECT QCoreApplicationPrivate::is_app_closing = true; QCoreApplicationPrivate::is_app_running = false; @@ -894,7 +894,7 @@ QCoreApplication::~QCoreApplication() #if QT_CONFIG(thread) // Synchronize and stop the global thread pool threads. - QThreadPool *globalThreadPool = 0; + QThreadPool *globalThreadPool = nullptr; QT_TRY { globalThreadPool = QThreadPool::globalInstance(); } QT_CATCH (...) { @@ -905,10 +905,10 @@ QCoreApplication::~QCoreApplication() #endif #ifndef QT_NO_QOBJECT - d_func()->threadData->eventDispatcher = 0; + d_func()->threadData->eventDispatcher = nullptr; if (QCoreApplicationPrivate::eventDispatcher) QCoreApplicationPrivate::eventDispatcher->closingDown(); - QCoreApplicationPrivate::eventDispatcher = 0; + QCoreApplicationPrivate::eventDispatcher = nullptr; #endif #if QT_CONFIG(library) diff --git a/src/corelib/kernel/qcoreglobaldata.cpp b/src/corelib/kernel/qcoreglobaldata.cpp index 104be1b87b..7ff222f170 100644 --- a/src/corelib/kernel/qcoreglobaldata.cpp +++ b/src/corelib/kernel/qcoreglobaldata.cpp @@ -48,7 +48,7 @@ Q_GLOBAL_STATIC(QCoreGlobalData, globalInstance) QCoreGlobalData::QCoreGlobalData() #if QT_CONFIG(textcodec) - : codecForLocale(0) + : codecForLocale(nullptr) #endif { } @@ -56,7 +56,7 @@ QCoreGlobalData::QCoreGlobalData() QCoreGlobalData::~QCoreGlobalData() { #if QT_CONFIG(textcodec) - codecForLocale = 0; + codecForLocale = nullptr; QList<QTextCodec *> tmp = allCodecs; allCodecs.clear(); codecCache.clear(); diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 855d36794d..311fb01fd0 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -517,12 +517,12 @@ static const struct { const char * typeName; int typeNameLength; int type; } typ QT_FOR_EACH_STATIC_TYPE(QT_ADD_STATIC_METATYPE) QT_FOR_EACH_STATIC_ALIAS_TYPE(QT_ADD_STATIC_METATYPE_ALIASES_ITER) QT_FOR_EACH_STATIC_HACKS_TYPE(QT_ADD_STATIC_METATYPE_HACKS_ITER) - {0, 0, QMetaType::UnknownType} + {nullptr, 0, QMetaType::UnknownType} }; -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = 0; -Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = 0; -Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = 0; +Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper = nullptr; +Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper = nullptr; +Q_CORE_EXPORT const QMetaObject *qMetaObjectWidgetsHelper = nullptr; class QCustomTypeInfo : public QMetaTypeInterface { @@ -557,7 +557,7 @@ public: { const QWriteLocker locker(&lock); const T* &fun = map[k]; - if (fun != 0) + if (fun) return false; fun = f; return true; @@ -566,7 +566,7 @@ public: const T *function(Key k) const { const QReadLocker locker(&lock); - return map.value(k, 0); + return map.value(k, nullptr); } void remove(int from, int to) @@ -973,7 +973,7 @@ static inline int qMetaTypeStaticType(const char *typeName, int length) The extra \a firstInvalidIndex parameter is an easy way to avoid iterating over customTypes() a second time in registerNormalizedType(). */ -static int qMetaTypeCustomType_unlocked(const char *typeName, int length, int *firstInvalidIndex = 0) +static int qMetaTypeCustomType_unlocked(const char *typeName, int length, int *firstInvalidIndex = nullptr) { const QVector<QCustomTypeInfo> * const ct = customTypes(); if (!ct) @@ -1006,7 +1006,7 @@ int QMetaType::registerType(const char *typeName, Deleter deleter, { return registerType(typeName, deleter, creator, QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct, - QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), 0); + QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct, 0, TypeFlags(), nullptr); } /*! @@ -1613,7 +1613,7 @@ void *QMetaType::create(int type, const void *copy) QMetaType info(type); if (int size = info.sizeOf()) return info.construct(operator new(size), copy); - return 0; + return nullptr; } /*! @@ -1639,14 +1639,18 @@ class TypeConstructor { static void *Construct(const int type, void *where, const void *copy) { if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; + return Q_LIKELY(qMetaTypeGuiHelper) + ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) + : nullptr; if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; + return Q_LIKELY(qMetaTypeWidgetsHelper) + ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) + : nullptr; // This point can be reached only for known types that definition is not available, for example // in bootstrap mode. We have no other choice then ignore it. - return 0; + return nullptr; } }; public: @@ -1670,7 +1674,7 @@ private: { QReadLocker locker(customTypesLock()); if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)) - return 0; + return nullptr; const auto &typeInfo = ct->at(type - QMetaType::User); ctor = typeInfo.constructor; tctor = typeInfo.typedConstructor; @@ -1715,7 +1719,7 @@ private: void *QMetaType::construct(int type, void *where, const void *copy) { if (!where) - return 0; + return nullptr; TypeConstructor constructor(type, where); return QMetaTypeSwitcher::switcher<void*>(constructor, type, copy); } @@ -1861,7 +1865,7 @@ private: int QMetaType::sizeOf(int type) { SizeOf sizeOf(type); - return QMetaTypeSwitcher::switcher<int>(sizeOf, type, 0); + return QMetaTypeSwitcher::switcher<int>(sizeOf, type); } namespace { @@ -1925,7 +1929,7 @@ private: QMetaType::TypeFlags QMetaType::typeFlags(int type) { Flags flags(type); - return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type, 0)); + return static_cast<QMetaType::TypeFlags>(QMetaTypeSwitcher::switcher<quint32>(flags, type)); } #ifndef QT_BOOTSTRAPPED @@ -1948,17 +1952,21 @@ public: { static const QMetaObject *MetaObject(int type) { if (QModulesPrivate::QTypeModuleInfo<T>::IsGui) - return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject : 0; + return Q_LIKELY(qMetaTypeGuiHelper) + ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].metaObject + : nullptr; if (QModulesPrivate::QTypeModuleInfo<T>::IsWidget) - return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject : 0; + return Q_LIKELY(qMetaTypeWidgetsHelper) + ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].metaObject + : nullptr; return 0; } }; template <typename T> const QMetaObject *delegate(const T *) { return MetaObjectImpl<T>::MetaObject(m_type); } - const QMetaObject *delegate(const void*) { return 0; } - const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return 0; } + const QMetaObject *delegate(const void*) { return nullptr; } + const QMetaObject *delegate(const QMetaTypeSwitcher::UnknownType*) { return nullptr; } const QMetaObject *delegate(const QMetaTypeSwitcher::NotBuiltinType*) { return customMetaObject(m_type); } private: const int m_type; @@ -1966,10 +1974,10 @@ private: { const QVector<QCustomTypeInfo> * const ct = customTypes(); if (Q_UNLIKELY(!ct || type < QMetaType::User)) - return 0; + return nullptr; QReadLocker locker(customTypesLock()); if (Q_UNLIKELY(ct->count() <= type - QMetaType::User)) - return 0; + return nullptr; return ct->at(type - QMetaType::User).metaObject; } }; @@ -1987,10 +1995,10 @@ const QMetaObject *QMetaType::metaObjectForType(int type) { #ifndef QT_BOOTSTRAPPED MetaObject mo(type); - return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type, 0); + return QMetaTypeSwitcher::switcher<const QMetaObject*>(mo, type); #else Q_UNUSED(type); - return 0; + return nullptr; #endif } @@ -2187,7 +2195,7 @@ private: QMetaType QMetaType::typeInfo(const int type) { TypeInfo typeInfo(type); - QMetaTypeSwitcher::switcher<void>(typeInfo, type, 0); + QMetaTypeSwitcher::switcher<void>(typeInfo, type); return (typeInfo.info.constructor || typeInfo.info.typedConstructor) ? QMetaType(static_cast<ExtensionFlag>(QMetaType::CreateEx | QMetaType::DestroyEx | (typeInfo.info.typedConstructor ? QMetaType::ConstructEx | QMetaType::DestructEx : 0)) @@ -2307,7 +2315,7 @@ void QMetaType::dtor() void *QMetaType::createExtended(const void *copy) const { if (m_typeId == QMetaType::UnknownType) - return 0; + return nullptr; if (Q_UNLIKELY(m_typedConstructor && !m_constructor)) return m_typedConstructor(m_typeId, operator new(m_size), copy); return m_constructor(operator new(m_size), copy); @@ -2387,7 +2395,7 @@ uint QMetaType::sizeExtended() const */ QMetaType::TypeFlags QMetaType::flagsExtended() const { - return 0; + return { }; } /*! @@ -2400,7 +2408,7 @@ QMetaType::TypeFlags QMetaType::flagsExtended() const */ const QMetaObject *QMetaType::metaObjectExtended() const { - return 0; + return nullptr; } @@ -2409,7 +2417,7 @@ namespace QtPrivate const QMetaObject *metaObjectForQWidget() { if (!qMetaTypeWidgetsHelper) - return 0; + return nullptr; return qMetaObjectWidgetsHelper; } } diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 0846193e66..97d6001937 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -140,12 +140,12 @@ public: /*saveOp*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Save), \ /*loadOp*/(QtMetaTypePrivate::QMetaTypeFunctionHelper<Type, QtMetaTypePrivate::TypeDefinition<Type>::IsAvailable>::Load), # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \ - /*saveOp*/ 0, \ - /*loadOp*/ 0, + /*saveOp*/ nullptr, \ + /*loadOp*/ nullptr, #else # define QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) \ - /*saveOp*/ 0, \ - /*loadOp*/ 0, + /*saveOp*/ nullptr, \ + /*loadOp*/ nullptr, # define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \ QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(Type) #endif @@ -153,7 +153,7 @@ public: #ifndef QT_BOOTSTRAPPED #define METAOBJECT_DELEGATE(Type) (QtPrivate::MetaObjectForType<Type>::value()) #else -#define METAOBJECT_DELEGATE(Type) 0 +#define METAOBJECT_DELEGATE(Type) nullptr #endif #define QT_METATYPE_INTERFACE_INIT_IMPL(Type, DATASTREAM_DELEGATE) \ @@ -184,11 +184,11 @@ public: #define QT_METATYPE_INTERFACE_INIT_EMPTY() \ { \ QT_METATYPE_INTERFACE_INIT_EMPTY_DATASTREAM_IMPL(void) \ - /*constructor*/ 0, \ - /*destructor*/ 0, \ + /*constructor*/ nullptr, \ + /*destructor*/ nullptr, \ /*size*/ 0, \ /*flags*/ 0, \ - /*metaObject*/ 0 , \ + /*metaObject*/ nullptr , \ /*typedConstructor*/ nullptr, \ /*typedDestructor*/ nullptr \ } diff --git a/src/corelib/kernel/qmetatypeswitcher_p.h b/src/corelib/kernel/qmetatypeswitcher_p.h index 154fb8ab7f..dabc70f4b0 100644 --- a/src/corelib/kernel/qmetatypeswitcher_p.h +++ b/src/corelib/kernel/qmetatypeswitcher_p.h @@ -60,7 +60,7 @@ public: class NotBuiltinType; // type is not a built-in type, but it may be a custom type or an unknown type class UnknownType; // type not known to QMetaType system template<class ReturnType, class DelegateObject> - static ReturnType switcher(DelegateObject &logic, int type, const void *data); + static ReturnType switcher(DelegateObject &logic, int type, const void *data = nullptr); }; diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp index 9d0394e4a5..a735e12925 100644 --- a/src/corelib/kernel/qsystemerror.cpp +++ b/src/corelib/kernel/qsystemerror.cpp @@ -112,7 +112,7 @@ static QString windowsErrorString(int errorCode) static QString standardLibraryErrorString(int errorCode) { - const char *s = 0; + const char *s = nullptr; QString ret; switch (errorCode) { case 0: diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 1ac47f3972..b9563b8395 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -119,19 +119,19 @@ namespace { // annonymous used to hide QVariant handlers static void construct(QVariant::Private *x, const void *copy) { QVariantConstructor<CoreTypesFilter> constructor(x, copy); - QMetaTypeSwitcher::switcher<void>(constructor, x->type, 0); + QMetaTypeSwitcher::switcher<void>(constructor, x->type); } static void clear(QVariant::Private *d) { QVariantDestructor<CoreTypesFilter> cleaner(d); - QMetaTypeSwitcher::switcher<void>(cleaner, d->type, 0); + QMetaTypeSwitcher::switcher<void>(cleaner, d->type); } static bool isNull(const QVariant::Private *d) { QVariantIsNull<CoreTypesFilter> isNull(d); - return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, 0); + return QMetaTypeSwitcher::switcher<bool>(isNull, d->type); } /*! @@ -143,7 +143,7 @@ static bool isNull(const QVariant::Private *d) static bool compare(const QVariant::Private *a, const QVariant::Private *b) { QVariantComparator<CoreTypesFilter> comparator(a, b); - return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0); + return QMetaTypeSwitcher::switcher<bool>(comparator, a->type); } /*! @@ -1401,7 +1401,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr()); QVariantDebugStream<CoreTypesFilter> stream(dbg, d); - QMetaTypeSwitcher::switcher<void>(stream, d->type, 0); + QMetaTypeSwitcher::switcher<void>(stream, d->type); } #endif @@ -1410,16 +1410,16 @@ const QVariant::Handler qt_kernel_variant_handler = { clear, isNull, #ifndef QT_NO_DATASTREAM - 0, - 0, + nullptr, + nullptr, #endif compare, convert, - 0, + nullptr, #if !defined(QT_NO_DEBUG_STREAM) streamDebug #else - 0 + nullptr #endif }; @@ -1436,16 +1436,16 @@ const QVariant::Handler qt_dummy_variant_handler = { dummyClear, dummyIsNull, #ifndef QT_NO_DATASTREAM - 0, - 0, + nullptr, + nullptr, #endif dummyCompare, dummyConvert, - 0, + nullptr, #if !defined(QT_NO_DEBUG_STREAM) dummyStreamDebug #else - 0 + nullptr #endif }; @@ -1555,16 +1555,16 @@ const QVariant::Handler qt_custom_variant_handler = { customClear, customIsNull, #ifndef QT_NO_DATASTREAM - 0, - 0, + nullptr, + nullptr, #endif customCompare, customConvert, - 0, + nullptr, #if !defined(QT_NO_DEBUG_STREAM) customStreamDebug #else - 0 + nullptr #endif }; @@ -2125,7 +2125,7 @@ QVariant::QVariant(const char *val) */ QVariant::QVariant(Type type) -{ create(type, 0); } +{ create(type, nullptr); } QVariant::QVariant(int typeId, const void *copy) { create(typeId, copy); d.is_null = false; } @@ -2667,7 +2667,7 @@ inline T qVariantToHelper(const QVariant::Private &d, const HandlersManager &han return ret; } - handlerManager[d.type]->convert(&d, targetType, &ret, 0); + handlerManager[d.type]->convert(&d, targetType, &ret, nullptr); return ret; } @@ -3217,7 +3217,7 @@ bool QVariant::toBool() const return d.data.b; bool res = false; - handlerManager[d.type]->convert(&d, Bool, &res, 0); + handlerManager[d.type]->convert(&d, Bool, &res, nullptr); return res; } @@ -3735,7 +3735,7 @@ bool QVariant::convert(int targetTypeId) if (!oldValue.canConvert(targetTypeId)) return false; - create(targetTypeId, 0); + create(targetTypeId, nullptr); // Fail if the value is not initialized or was forced null by a previous failed convert. if (oldValue.d.is_null && oldValue.d.type != QMetaType::Nullptr) return false; @@ -3760,7 +3760,7 @@ bool QVariant::convert(int targetTypeId) */ bool QVariant::convert(const int type, void *ptr) const { - return handlerManager[type]->convert(&d, type, ptr, 0); + return handlerManager[type]->convert(&d, type, ptr, nullptr); } |