From 4e0d5498eb7ba401e6697182ce74b34d439ecf76 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 9 Nov 2019 17:48:01 +0200 Subject: QEventDispatcherWin32: unify input checks in {un}register...() The event manager has a family of the functions for registering sockets notifiers, event notifiers, and timers. To ensure efficient debugging, it would be useful to have one approach regarding input parameters validation for the entire set of that functions. Based on registerSocketNotifier() implementation, this patch offers the same debugging principles for QWinEventNotifier and QTimer. Some debug messages have also been refined. Change-Id: I1418ef43c51f7b794462b5e9c8a849633e0c60f9 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qeventdispatcher_win.cpp | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 87623f304a..517ba17fb2 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -636,11 +636,11 @@ void QEventDispatcherWin32::registerSocketNotifier(QSocketNotifier *notifier) int type = notifier->type(); #ifndef QT_NO_DEBUG if (sockfd < 0) { - qWarning("QSocketNotifier: Internal error"); + qWarning("QEventDispatcherWin32::registerSocketNotifier: invalid socket identifier"); return; } if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); + qWarning("QEventDispatcherWin32: socket notifiers cannot be enabled from another thread"); return; } #endif @@ -697,11 +697,11 @@ void QEventDispatcherWin32::unregisterSocketNotifier(QSocketNotifier *notifier) #ifndef QT_NO_DEBUG int sockfd = notifier->socket(); if (sockfd < 0) { - qWarning("QSocketNotifier: Internal error"); + qWarning("QEventDispatcherWin32::unregisterSocketNotifier: invalid socket identifier"); return; } if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); + qWarning("QEventDispatcherWin32: socket notifiers cannot be disabled from another thread"); return; } #endif @@ -783,8 +783,7 @@ bool QEventDispatcherWin32::unregisterTimer(int timerId) qWarning("QEventDispatcherWin32::unregisterTimer: invalid argument"); return false; } - QThread *currentThread = QThread::currentThread(); - if (thread() != currentThread) { + if (thread() != QThread::currentThread()) { qWarning("QEventDispatcherWin32::unregisterTimer: timers cannot be stopped from another thread"); return false; } @@ -811,8 +810,7 @@ bool QEventDispatcherWin32::unregisterTimers(QObject *object) qWarning("QEventDispatcherWin32::unregisterTimers: invalid argument"); return false; } - QThread *currentThread = QThread::currentThread(); - if (object->thread() != thread() || thread() != currentThread) { + if (object->thread() != thread() || thread() != QThread::currentThread()) { qWarning("QEventDispatcherWin32::unregisterTimers: timers cannot be stopped from another thread"); return false; } @@ -837,10 +835,12 @@ bool QEventDispatcherWin32::unregisterTimers(QObject *object) QList QEventDispatcherWin32::registeredTimers(QObject *object) const { +#ifndef QT_NO_DEBUG if (!object) { qWarning("QEventDispatcherWin32:registeredTimers: invalid argument"); return QList(); } +#endif Q_D(const QEventDispatcherWin32); QList list; @@ -853,13 +853,13 @@ QEventDispatcherWin32::registeredTimers(QObject *object) const bool QEventDispatcherWin32::registerEventNotifier(QWinEventNotifier *notifier) { - if (!notifier) { - qWarning("QWinEventNotifier: Internal error"); - return false; - } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QWinEventNotifier: event notifiers cannot be enabled from another thread"); + Q_ASSERT(notifier); +#ifndef QT_NO_DEBUG + if (notifier->thread() != thread() || thread() != QThread::currentThread()) { + qWarning("QEventDispatcherWin32: event notifiers cannot be enabled from another thread"); return false; } +#endif Q_D(QEventDispatcherWin32); @@ -877,13 +877,13 @@ bool QEventDispatcherWin32::registerEventNotifier(QWinEventNotifier *notifier) void QEventDispatcherWin32::unregisterEventNotifier(QWinEventNotifier *notifier) { - if (!notifier) { - qWarning("QWinEventNotifier: Internal error"); - return; - } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QWinEventNotifier: event notifiers cannot be disabled from another thread"); + Q_ASSERT(notifier); +#ifndef QT_NO_DEBUG + if (notifier->thread() != thread() || thread() != QThread::currentThread()) { + qWarning("QEventDispatcherWin32: event notifiers cannot be disabled from another thread"); return; } +#endif Q_D(QEventDispatcherWin32); -- cgit v1.2.3