From 952efd732fc99f743592f8f13cb04dec727d8b2e Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Mon, 29 Jul 2024 14:58:03 +0500 Subject: [PATCH] Fix clazy non-POD static warnings --- core/tools/messagehandler/messagehandler.cpp | 8 ++-- launcher/ui/processlist_unix.cpp | 6 +-- plugins/quickinspector/quickscreengrabber.cpp | 10 ++-- plugins/sysinfo/sysinfomodel.cpp | 47 +++++++++++-------- plugins/timertop/timermodel.cpp | 22 +++++---- probe/entry_unix.cpp | 2 +- 6 files changed, 52 insertions(+), 43 deletions(-) diff --git a/core/tools/messagehandler/messagehandler.cpp b/core/tools/messagehandler/messagehandler.cpp index d998869044..26a5f4a265 100644 --- a/core/tools/messagehandler/messagehandler.cpp +++ b/core/tools/messagehandler/messagehandler.cpp @@ -40,7 +40,7 @@ static MessageHandlerCallback (*const installMessageHandler)(MessageHandlerCallb static MessageModel *s_model = nullptr; static MessageHandlerCallback s_handler = nullptr; static bool s_handlerDisabled = false; -static QRecursiveMutex s_mutex; +Q_GLOBAL_STATIC(QRecursiveMutex, s_mutex) static void handleMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) { @@ -86,7 +86,7 @@ static void handleMessage(QtMsgType type, const QMessageLogContext &context, con // reset msg handler so the app still works as usual // but make sure we don't let other threads bypass our // handler during that time - QMutexLocker lock(&s_mutex); + QMutexLocker lock(s_mutex()); s_handlerDisabled = true; if (s_handler) { // try a direct call to the previous handler first, that avoids triggering the recursion detection in Qt5 s_handler(type, context, msg); @@ -139,7 +139,7 @@ MessageHandler::MessageHandler(Probe *probe, QObject *parent) MessageHandler::~MessageHandler() { - QMutexLocker lock(&s_mutex); + QMutexLocker lock(s_mutex()); s_model = nullptr; MessageHandlerCallback oldHandler = installMessageHandler(s_handler); @@ -157,7 +157,7 @@ void MessageHandler::generateFullTrace() void MessageHandler::ensureHandlerInstalled() { - QMutexLocker lock(&s_mutex); + QMutexLocker lock(s_mutex()); if (s_handlerDisabled) return; diff --git a/launcher/ui/processlist_unix.cpp b/launcher/ui/processlist_unix.cpp index ee759962cc..647345bae1 100644 --- a/launcher/ui/processlist_unix.cpp +++ b/launcher/ui/processlist_unix.cpp @@ -40,7 +40,7 @@ #include -static GammaRay::ProbeABIDetector s_abiDetector; +Q_GLOBAL_STATIC(GammaRay::ProbeABIDetector, s_abiDetector) static bool isUnixProcessId(const QString &procname) { @@ -108,7 +108,7 @@ static ProcDataList unixProcessListPS(const ProcDataList &previous) if (it != previous.constEnd()) procData.abi = it->abi; else - procData.abi = s_abiDetector.abiForProcess(procData.ppid.toLongLong()); + procData.abi = s_abiDetector->abiForProcess(procData.ppid.toLongLong()); rc.push_back(procData); } } @@ -164,7 +164,7 @@ struct ProcIdToProcData if (it != previous.constEnd()) proc.abi = it->abi; else - proc.abi = s_abiDetector.abiForProcess(proc.ppid.toLongLong()); + proc.abi = s_abiDetector->abiForProcess(proc.ppid.toLongLong()); return proc; } diff --git a/plugins/quickinspector/quickscreengrabber.cpp b/plugins/quickinspector/quickscreengrabber.cpp index c48033a5e9..b6eda4965f 100644 --- a/plugins/quickinspector/quickscreengrabber.cpp +++ b/plugins/quickinspector/quickscreengrabber.cpp @@ -87,13 +87,13 @@ class QQuickItemPropertyCache } }; -// We need random colors, but we also want the item -// to keep its random color during scene changes to avoid -// flickering due to color change. -static QHash s_itemsColor; - static QColor colorForItem(QQuickItem *item) { + // We need random colors, but we also want the item + // to keep its random color during scene changes to avoid + // flickering due to color change. + static QHash s_itemsColor; + QColor color = s_itemsColor.value(item, QColor()); if (!color.isValid()) { diff --git a/plugins/sysinfo/sysinfomodel.cpp b/plugins/sysinfo/sysinfomodel.cpp index eafbb7ab80..f987695293 100644 --- a/plugins/sysinfo/sysinfomodel.cpp +++ b/plugins/sysinfo/sysinfomodel.cpp @@ -15,35 +15,42 @@ #include #include +#include using namespace GammaRay; struct sysinfo_t { QString (*func)(); - const char *name; + const QString name; }; -#define S(x) \ - { \ - QSysInfo::x, #x \ +#define S(x) \ + sysinfo_t \ + { \ + \ + QSysInfo::x, QString::fromLatin1(#x) \ } -static const sysinfo_t sysInfoTable[] = { + +static const std::array &sysInfoTable() +{ + static const std::array t = { #if !defined(Q_CC_MSVC) || _MSC_VER > 1600 // krazy:exclude=cpp to deal with older MS compilers - { []() { return QString::fromLatin1(QLibraryInfo::build()); }, "build" }, + sysinfo_t { []() { return QString::fromLatin1(QLibraryInfo::build()); }, "build" }, #endif - S(buildAbi), - S(buildCpuArchitecture), - S(currentCpuArchitecture), - S(kernelType), - S(kernelVersion), - S(machineHostName), - S(prettyProductName), - S(productType), - S(productVersion) -}; + S(buildAbi), + S(buildCpuArchitecture), + S(currentCpuArchitecture), + S(kernelType), + S(kernelVersion), + S(machineHostName), + S(prettyProductName), + S(productType), + S(productVersion) + }; + return t; +} #undef S -static const auto sysInfoTableSize = sizeof(sysInfoTable) / sizeof(sysinfo_t); SysInfoModel::SysInfoModel(QObject *parent) : QAbstractTableModel(parent) @@ -60,7 +67,7 @@ int SysInfoModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; - return sysInfoTableSize; + return ( int )sysInfoTable().size(); } QVariant SysInfoModel::data(const QModelIndex &index, int role) const @@ -71,9 +78,9 @@ QVariant SysInfoModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { switch (index.column()) { case 0: - return sysInfoTable[index.row()].name; + return sysInfoTable()[index.row()].name; case 1: - return sysInfoTable[index.row()].func(); + return sysInfoTable()[index.row()].func(); } } diff --git a/plugins/timertop/timermodel.cpp b/plugins/timertop/timermodel.cpp index bdf142a01b..41b0bee74d 100644 --- a/plugins/timertop/timermodel.cpp +++ b/plugins/timertop/timermodel.cpp @@ -38,7 +38,7 @@ using namespace GammaRay; using namespace std; -static QPointer s_timerModel; +Q_GLOBAL_STATIC(QPointer, s_timerModel) static const char s_qmlTimerClassName[] = "QQmlTimer"; static const int s_maxTimeoutEvents = 1000; static const int s_maxTimeSpan = 10000; @@ -300,12 +300,13 @@ bool TimerModel::eventNotifyCallback(void *data[]) } { - QMutexLocker locker(&s_timerModel->m_mutex); + auto timerModel = s_timerModel->data(); + QMutexLocker locker(&timerModel->m_mutex); const TimerId id(timerEvent->timerId(), receiver); - auto it = s_timerModel->m_gatheredTimersData.find(id); + auto it = timerModel->m_gatheredTimersData.find(id); - if (it == s_timerModel->m_gatheredTimersData.end()) { - it = s_timerModel->m_gatheredTimersData.insert(id, TimerIdData()); + if (it == timerModel->m_gatheredTimersData.end()) { + it = timerModel->m_gatheredTimersData.insert(id, TimerIdData()); } const TimeoutEvent timeoutEvent(QTime::currentTime(), -1); @@ -313,8 +314,8 @@ bool TimerModel::eventNotifyCallback(void *data[]) it.value().update(id, receiver); it.value().addEvent(timeoutEvent); - s_timerModel->checkDispatcherStatus(receiver); - s_timerModel->m_triggerPushChangesMethod.invoke(s_timerModel, Qt::QueuedConnection); + timerModel->checkDispatcherStatus(receiver); + timerModel->m_triggerPushChangesMethod.invoke(timerModel, Qt::QueuedConnection); } } @@ -337,11 +338,12 @@ bool TimerModel::isInitialized() TimerModel *TimerModel::instance() { - if (!s_timerModel) - s_timerModel = new TimerModel; + if (s_timerModel->isNull()) { + *s_timerModel = new TimerModel; + } Q_ASSERT(s_timerModel); - return s_timerModel; + return s_timerModel->data(); } void TimerModel::preSignalActivate(QObject *caller, int methodIndex) diff --git a/probe/entry_unix.cpp b/probe/entry_unix.cpp index 39aab9a6f5..2b5921e874 100644 --- a/probe/entry_unix.cpp +++ b/probe/entry_unix.cpp @@ -26,4 +26,4 @@ class HitMeBabyOneMoreTime } }; -static HitMeBabyOneMoreTime britney; +static HitMeBabyOneMoreTime britney; // clazy:exclude=non-pod-global-static