From 3d442b86ae59b07bd0064e3a3ca9fc613545d3f3 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:06 +0100 Subject: QKqueueFileSystemWatcherEngine: Use EV_CLEAR instead of EV_ONESHOT. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using EV_ONESHOT and re-enabling the kevent after emitting the signal allows for a window in which file system changes can go undetected. By using EV_CLEAR instead the kevent can stay enabled. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 378ad20..45aea73 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -157,7 +157,7 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, EV_SET(&kev, fd, EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, + EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, 0, 0); @@ -315,24 +315,12 @@ void QKqueueFileSystemWatcherEngine::run() else emit fileChanged(path, true); } else { - DEBUG() << path << "changed, re-enabling watch"; + DEBUG() << path << "changed"; if (id < 0) emit directoryChanged(path, false); else emit fileChanged(path, false); - - // renable the watch - EV_SET(&kev, - fd, - EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_ONESHOT, - NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, - 0, - 0); - if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) { - perror("QKqueueFileSystemWatcherEngine::processKqueueEvents: kevent EV_ADD"); - } } } -- cgit v0.12 From 42e861407a9977d3fa8daae5abe54e98ba6b05da Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:07 +0100 Subject: QKqueueFileSystemWatcherEngine: Deleting kevent is handled by close(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 45aea73..f66231a 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -203,19 +203,7 @@ QStringList QKqueueFileSystemWatcherEngine::removePaths(const QStringList &paths if (x.isEmpty() || x != path) continue; - int fd = id < 0 ? -id : id; - struct kevent kev; - EV_SET(&kev, - fd, - EVFILT_VNODE, - EV_DELETE, - NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, - 0, - 0); - if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) { - perror("QKqueueFileSystemWatcherEngine::removeWatch: kevent"); - } - ::close(fd); + ::close(id < 0 ? -id : id); it.remove(); if (id < 0) -- cgit v0.12 From 4ff80e53a306b1727b78b49e2de6fdafd1fb5ada Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:08 +0100 Subject: QKqueueFileSystemWatcherEngine: Handle kevent(2) returning EINTR. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The worker thread exits whenever the kevent call returns an error, but in the case of EINTR (interrupted by signal) it should just call kevent again. Otherwise for instance, attaching a debugger to the process causes the worker thread to exit because of the SIGSTOP it receives. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index f66231a..4d15519 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -234,9 +234,10 @@ void QKqueueFileSystemWatcherEngine::run() static const struct timespec ZeroTimeout = { 0, 0 }; forever { + int r; struct kevent kev; DEBUG() << "QKqueueFileSystemWatcherEngine: waiting for kevents..."; - int r = kevent(kqfd, 0, 0, &kev, 1, 0); + EINTR_LOOP(r, kevent(kqfd, 0, 0, &kev, 1, 0)); if (r < 0) { perror("QKqueueFileSystemWatcherEngine: error during kevent wait"); return; -- cgit v0.12 From 03c82dc0d4b4bbbe17e9d91bef6a112d512ca002 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:09 +0100 Subject: QKqueueFileSystemWatcherEngine: Unlock mutex before calling write(2). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calls to write(2) potentially block, so make sure the application thread unlocks the mutex before it writes to the pipe between itself and the worker thread, so the latter can continue to process events and eventually unblock the write call (if needed) by emptying the pipe. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 134 ++++++++++++++------------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 4d15519..8fba091 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -117,67 +117,69 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QMutexLocker locker(&mutex); - QStringList p = paths; - QMutableListIterator it(p); - while (it.hasNext()) { - QString path = it.next(); - int fd; + { + QMutexLocker locker(&mutex); + + QMutableListIterator it(p); + while (it.hasNext()) { + QString path = it.next(); + int fd; #if defined(O_EVTONLY) - fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY); + fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY); #else - fd = qt_safe_open(QFile::encodeName(path), O_RDONLY); + fd = qt_safe_open(QFile::encodeName(path), O_RDONLY); #endif - if (fd == -1) { - perror("QKqueueFileSystemWatcherEngine::addPaths: open"); - continue; - } + if (fd == -1) { + perror("QKqueueFileSystemWatcherEngine::addPaths: open"); + continue; + } - QT_STATBUF st; - if (QT_FSTAT(fd, &st) == -1) { - perror("QKqueueFileSystemWatcherEngine::addPaths: fstat"); - ::close(fd); - continue; - } - int id = (S_ISDIR(st.st_mode)) ? -fd : fd; - if (id < 0) { - if (directories->contains(path)) { + QT_STATBUF st; + if (QT_FSTAT(fd, &st) == -1) { + perror("QKqueueFileSystemWatcherEngine::addPaths: fstat"); ::close(fd); continue; } - } else { - if (files->contains(path)) { + int id = (S_ISDIR(st.st_mode)) ? -fd : fd; + if (id < 0) { + if (directories->contains(path)) { + ::close(fd); + continue; + } + } else { + if (files->contains(path)) { + ::close(fd); + continue; + } + } + + struct kevent kev; + EV_SET(&kev, + fd, + EVFILT_VNODE, + EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, + 0, + 0); + if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) { + perror("QKqueueFileSystemWatcherEngine::addPaths: kevent"); ::close(fd); continue; } - } - struct kevent kev; - EV_SET(&kev, - fd, - EVFILT_VNODE, - EV_ADD | EV_ENABLE | EV_CLEAR, - NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE, - 0, - 0); - if (kevent(kqfd, &kev, 1, 0, 0, 0) == -1) { - perror("QKqueueFileSystemWatcherEngine::addPaths: kevent"); - ::close(fd); - continue; - } + it.remove(); + if (id < 0) { + DEBUG() << "QKqueueFileSystemWatcherEngine: added directory path" << path; + directories->append(path); + } else { + DEBUG() << "QKqueueFileSystemWatcherEngine: added file path" << path; + files->append(path); + } - it.remove(); - if (id < 0) { - DEBUG() << "QKqueueFileSystemWatcherEngine: added directory path" << path; - directories->append(path); - } else { - DEBUG() << "QKqueueFileSystemWatcherEngine: added file path" << path; - files->append(path); + pathToID.insert(path, id); + idToPath.insert(id, path); } - - pathToID.insert(path, id); - idToPath.insert(id, path); } if (!isRunning()) @@ -192,31 +194,33 @@ QStringList QKqueueFileSystemWatcherEngine::removePaths(const QStringList &paths QStringList *files, QStringList *directories) { - QMutexLocker locker(&mutex); - + bool isEmpty; QStringList p = paths; - QMutableListIterator it(p); - while (it.hasNext()) { - QString path = it.next(); - int id = pathToID.take(path); - QString x = idToPath.take(id); - if (x.isEmpty() || x != path) - continue; + { + QMutexLocker locker(&mutex); - ::close(id < 0 ? -id : id); + QMutableListIterator it(p); + while (it.hasNext()) { + QString path = it.next(); + int id = pathToID.take(path); + QString x = idToPath.take(id); + if (x.isEmpty() || x != path) + continue; + + ::close(id < 0 ? -id : id); - it.remove(); - if (id < 0) - directories->removeAll(path); - else - files->removeAll(path); + it.remove(); + if (id < 0) + directories->removeAll(path); + else + files->removeAll(path); + } + isEmpty = pathToID.isEmpty(); } - if (pathToID.isEmpty()) { + if (isEmpty) { stop(); - locker.unlock(); wait(); - locker.relock(); } else { write(kqpipe[1], "@", 1); } -- cgit v0.12 From e0e9d4ea2cec37243d964a5309be49101d112233 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:10 +0100 Subject: QKqueueFileSystemWatcherEngine: Unlock mutex between two events. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the worker thread unlock the mutex between processing two events. Otherwise it's possible for the worker thread to block the application thread when many events occur. Also, there's no need to lock the mutex when processing a pipe event. Generally the worker thread should hamper the application thread as little as possible, so only lock the mutex where needed. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 8fba091..637a961 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -235,8 +235,6 @@ void QKqueueFileSystemWatcherEngine::stop() void QKqueueFileSystemWatcherEngine::run() { - static const struct timespec ZeroTimeout = { 0, 0 }; - forever { int r; struct kevent kev; @@ -245,10 +243,7 @@ void QKqueueFileSystemWatcherEngine::run() if (r < 0) { perror("QKqueueFileSystemWatcherEngine: error during kevent wait"); return; - } - - QMutexLocker locker(&mutex); - do { + } else { int fd = kev.ident; DEBUG() << "QKqueueFileSystemWatcherEngine: processing kevent" << kev.ident << kev.filter; @@ -280,6 +275,8 @@ void QKqueueFileSystemWatcherEngine::run() break; } } else { + QMutexLocker locker(&mutex); + int id = fd; QString path = idToPath.value(id); if (path.isEmpty()) { @@ -288,12 +285,12 @@ void QKqueueFileSystemWatcherEngine::run() path = idToPath.value(id); if (path.isEmpty()) { DEBUG() << "QKqueueFileSystemWatcherEngine: received a kevent for a file we're not watching"; - goto process_next_event; + continue; } } if (kev.filter != EVFILT_VNODE) { DEBUG() << "QKqueueFileSystemWatcherEngine: received a kevent with the wrong filter"; - goto process_next_event; + continue; } if ((kev.fflags & (NOTE_DELETE | NOTE_REVOKE | NOTE_RENAME)) != 0) { @@ -316,11 +313,7 @@ void QKqueueFileSystemWatcherEngine::run() emit fileChanged(path, false); } } - - // are there any more? -process_next_event: - r = kevent(kqfd, 0, 0, &kev, 1, &ZeroTimeout); - } while (r > 0); + } } } -- cgit v0.12 From f7feeee1733b6cb8bfcc157fff1e444068dc290c Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:11 +0100 Subject: QKqueueFileSystemWatcherEngine: Use higher file descriptors. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A file descriptor is used for every path to be monitored, but descriptors below FD_SETSIZE (typically 1024) are precious, for use with select(2). To allow the application (and other parts of Qt) to use select(2), try to duplicate the descriptor returned by open(2) above FD_SETSIZE and close(2) the original. However, only do so when the descriptor table is already fairly large (FD_SETSIZE / 2). This keeps the descriptor table small for applications that use only a few descriptors. While here, also set the close-on-exec flag on the (new) descriptor. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 637a961..0103abd 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -134,6 +134,14 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, perror("QKqueueFileSystemWatcherEngine::addPaths: open"); continue; } + if (fd >= (int)FD_SETSIZE / 2 && fd < (int)FD_SETSIZE) { + int fddup = fcntl(fd, F_DUPFD, FD_SETSIZE); + if (fddup != -1) { + ::close(fd); + fd = fddup; + } + } + fcntl(fd, F_SETFD, FD_CLOEXEC); QT_STATBUF st; if (QT_FSTAT(fd, &st) == -1) { -- cgit v0.12 From 0af0682ebbb70635f40dbed64d4cc678ade6bed2 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:12 +0100 Subject: QPollingFileSystemWatcherEngine: Fix double report of directory change. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The polling engine first retrieves a QFileInfo for a given path, then tests whether it's different from before and if so, stores the new file info and emits a signal. In case path is a directory the test also checks if the list of directory entries has changed. This creates a window between retrieving the file info and the test in which a file can be added/removed from the directory or the directory itself can be removed. In that case the test returns true, because the list of entries has changed, but outdated file info is stored which means that on the next timeout the same change will be reported a second time. Therefore, refresh the file info after the test for changes. Merge-request: 2425 Reviewed-by: João Abecasis --- src/corelib/io/qfilesystemwatcher.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 18c3c9f..1e6dcee 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -228,8 +228,14 @@ void QPollingFileSystemWatcherEngine::timeout() dit.remove(); emit directoryChanged(path, true); } else if (x.value() != fi) { - x.value() = fi; - emit directoryChanged(path, false); + fi.refresh(); + if (!fi.exists()) { + dit.remove(); + emit directoryChanged(path, true); + } else { + x.value() = fi; + emit directoryChanged(path, false); + } } } -- cgit v0.12 From b758e011a6d88448bf4c3db7f27cb4df773fd5e3 Mon Sep 17 00:00:00 2001 From: Tijl Coosemans Date: Fri, 26 Nov 2010 10:11:13 +0100 Subject: tst_QFileSystemWatcher: Don't exit the event loop on first signal. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes tests can produce more than one signal and other times more than one signal would be an error. In order to test this the event loop should run long enough and not quit on the first signal. This is especially important on multicore systems where the application and worker threads run on different CPUs. Signals emitted by the worker thread are then almost immediately processed by the application thread. Merge-request: 2425 Reviewed-by: João Abecasis --- tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index a26e34d..3ed93fa 100644 --- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -139,10 +139,6 @@ void tst_QFileSystemWatcher::basicTest() QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(const QString &))); QEventLoop eventLoop; - connect(&watcher, - SIGNAL(fileChanged(const QString &)), - &eventLoop, - SLOT(quit())); QTimer timer; connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); @@ -278,10 +274,6 @@ void tst_QFileSystemWatcher::watchDirectory() QSignalSpy changedSpy(&watcher, SIGNAL(directoryChanged(const QString &))); QEventLoop eventLoop; - connect(&watcher, - SIGNAL(directoryChanged(const QString &)), - &eventLoop, - SLOT(quit())); QTimer timer; connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); -- cgit v0.12 From 5784daa662e1ace86e6046bf369e9029d57c32d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 26 Nov 2010 10:11:14 +0100 Subject: Fix QSettings auto test to use QTRY_VERIFY ... instead of relying on qApp->processEvents. Reviewed-by: Olivier Goffart --- tests/auto/qsettings/tst_qsettings.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/auto/qsettings/tst_qsettings.cpp b/tests/auto/qsettings/tst_qsettings.cpp index 0395eff..0813e28 100644 --- a/tests/auto/qsettings/tst_qsettings.cpp +++ b/tests/auto/qsettings/tst_qsettings.cpp @@ -51,6 +51,7 @@ #include #include #include +#include "../../shared/util.h" #if !defined(Q_OS_SYMBIAN) # include @@ -1726,26 +1727,22 @@ void tst_QSettings::testUpdateRequestEvent() settings1.setValue("key1", 1); QVERIFY(QFileInfo("foo").size() == 0); - qApp->processEvents(); - QVERIFY(QFileInfo("foo").size() > 0); + QTRY_VERIFY(QFileInfo("foo").size() > 0); settings1.remove("key1"); QVERIFY(QFileInfo("foo").size() > 0); - qApp->processEvents(); - QVERIFY(QFileInfo("foo").size() == 0); + QTRY_VERIFY(QFileInfo("foo").size() == 0); settings1.setValue("key2", 2); QVERIFY(QFileInfo("foo").size() == 0); - qApp->processEvents(); - QVERIFY(QFileInfo("foo").size() > 0); + QTRY_VERIFY(QFileInfo("foo").size() > 0); settings1.clear(); QVERIFY(QFileInfo("foo").size() > 0); - qApp->processEvents(); - QVERIFY(QFileInfo("foo").size() == 0); + QTRY_VERIFY(QFileInfo("foo").size() == 0); } const int NumIterations = 5; -- cgit v0.12 From 4e6cc34b75fd42d663ced0f3da1c9a9a6950fb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 26 Nov 2010 10:11:15 +0100 Subject: QKqueueFileSystemWatcher: don't stop thread that isn't running When removing paths from the watch list, if we end up with an empty watch list, we would send a request to the processing thread to quit. In the case where the watch list was empty to begin with (the paths being removed weren't actually being watched) the request to quit would still be queued. If the processing thread wasn't running (and it shouldn't if there weren't any paths being watched) the request to quit would still be posted but not processed. The next time paths were added and the thread started, the request would be processed and the thread would quit at once. When removing paths from the list, we now check whether the watch list is empty to begin with and exit early without asking the processing thread to quit itself. Task-Number: QTBUG-14435 Reviewed-by: Bradley T. Hughes --- src/corelib/io/qfilesystemwatcher_kqueue.cpp | 2 ++ tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 0103abd..3664396 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -206,6 +206,8 @@ QStringList QKqueueFileSystemWatcherEngine::removePaths(const QStringList &paths QStringList p = paths; { QMutexLocker locker(&mutex); + if (pathToID.isEmpty()) + return p; QMutableListIterator it(p); while (it.hasNext()) { diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 3ed93fa..1feaced 100644 --- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -135,6 +135,7 @@ void tst_QFileSystemWatcher::basicTest() // create watcher, forcing it to use a specific backend QFileSystemWatcher watcher; watcher.setObjectName(QLatin1String("_qt_autotest_force_engine_") + backend); + watcher.removePath(testFile.fileName()); watcher.addPath(testFile.fileName()); QSignalSpy changedSpy(&watcher, SIGNAL(fileChanged(const QString &))); -- cgit v0.12 From 86ddcd84dc13618cf27ae899f136d8fd138e4b26 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 26 Nov 2010 18:07:56 +0100 Subject: QNetworkReply autotest: fix possible crash ... by waiting for the thread to finish. Reviewed-by: Markus Goetz --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 90416f2..9cf61f9 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -4490,6 +4490,7 @@ void tst_QNetworkReply::httpProxyCommandsSynchronous() QVERIFY(reply->isFinished()); // synchronous manager.setProxy(QNetworkProxy()); serverThread.quit(); + serverThread.wait(3000); //qDebug() << reply->error() << reply->errorString(); -- cgit v0.12 From 5e257bd44fa4a76f4c2c573a6c5623802022ff18 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Nov 2010 18:38:55 +0100 Subject: Fix a race condition related to service acquisition. The explanation is in the testcase and in the task. The reentrancy caused some deadlocks, that's why handleMessage() stops processing if the refcount has dropped down to zero. Should also save some CPU cycles at the application shutdown time. Task-number: QTBUG-15651 Reviewed-by: Trust Me --- src/dbus/qdbusconnection_p.h | 13 +++- src/dbus/qdbusintegrator.cpp | 35 +++++++++-- tests/auto/qdbusconnection/tst_qdbusconnection.cpp | 69 ++++++++++++++++++++++ 3 files changed, 108 insertions(+), 9 deletions(-) diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 1bd00da..67145b8 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -203,6 +203,8 @@ public: void disconnectRelay(const QString &service, const QString &path, const QString &interface, QDBusAbstractInterface *receiver, const char *signal); + void registerService(const QString &serviceName); + void unregisterService(const QString &serviceName); bool handleMessage(const QDBusMessage &msg); void waitForFinished(QDBusPendingCallPrivate *pcall); @@ -247,9 +249,11 @@ public slots: void socketWrite(int); void objectDestroyed(QObject *o); void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args); - void _q_serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); - void registerService(const QString &serviceName); - void unregisterService(const QString &serviceName); + +private slots: + void serviceOwnerChangedNoLock(const QString &name, const QString &oldOwner, const QString &newOwner); + void registerServiceNoLock(const QString &serviceName); + void unregisterServiceNoLock(const QString &serviceName); signals: void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); @@ -303,6 +307,9 @@ public: QObject *receiver, const char *signal, int minMIdx, bool buildSignature); static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *); + static bool checkReplyForDelivery(QDBusConnectionPrivate *target, QObject *object, + int idx, const QList &metaTypes, + const QDBusMessage &msg); static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object, int idx, const QList &metaTypes, const QDBusMessage &msg); diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index a5d8ada..1842e5a 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -552,6 +552,9 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) (*(*list)[i])(amsg); } + if (!ref) + return false; + switch (amsg.type()) { case QDBusMessage::SignalMessage: handleSignal(amsg); @@ -713,6 +716,8 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, return -1; } +static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1; + QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target, QObject *object, int idx, const QList &metaTypes, @@ -736,6 +741,8 @@ QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPriv // we can deliver // prepare for the call + if (target == object) + return DIRECT_DELIVERY; return new QDBusCallDeliveryEvent(QDBusConnection(target), idx, target, msg, metaTypes); } @@ -750,6 +757,12 @@ void QDBusConnectionPrivate::activateSignal(const QDBusConnectionPrivate::Signal // Slots can optionally have one final parameter that is a QDBusMessage // Slots receive read-only copies of the message (i.e., pass by value or by const-ref) QDBusCallDeliveryEvent *call = prepareReply(this, hook.obj, hook.midx, hook.params, msg); + if (call == DIRECT_DELIVERY) { + // short-circuit delivery + Q_ASSERT(this == hook.obj); + deliverCall(this, 0, msg, hook.params, hook.midx); + return; + } if (call) postEventToThread(ActivateSignalAction, hook.obj, call); } @@ -1207,11 +1220,11 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in q_dbus_message_unref(msg); } -void QDBusConnectionPrivate::_q_serviceOwnerChanged(const QString &name, - const QString &oldOwner, const QString &newOwner) +void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name, + const QString &oldOwner, const QString &newOwner) { Q_UNUSED(oldOwner); - QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this); +// QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this); WatchedServicesHash::Iterator it = watchedServices.find(name); if (it == watchedServices.end()) return; @@ -1686,11 +1699,11 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError hook.obj = this; hook.params << QMetaType::Void << QVariant::String; // both functions take a QString as parameter and return void - hook.midx = staticMetaObject.indexOfSlot("registerService(QString)"); + hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)"); Q_ASSERT(hook.midx != -1); signalHooks.insert(QLatin1String("NameAcquired:" DBUS_INTERFACE_DBUS), hook); - hook.midx = staticMetaObject.indexOfSlot("unregisterService(QString)"); + hook.midx = staticMetaObject.indexOfSlot("unregisterServiceNoLock(QString)"); Q_ASSERT(hook.midx != -1); signalHooks.insert(QLatin1String("NameLost:" DBUS_INTERFACE_DBUS), hook); @@ -2081,7 +2094,7 @@ void QDBusConnectionPrivate::connectSignal(const QString &key, const SignalHook // we need to watch for this service changing connectSignal(dbusServiceString(), QString(), dbusInterfaceString(), QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(), - this, SLOT(_q_serviceOwnerChanged(QString,QString,QString))); + this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString))); data.owner = getNameOwnerNoCache(hook.service); qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:" << data.owner << ")"; @@ -2342,12 +2355,22 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa void QDBusConnectionPrivate::registerService(const QString &serviceName) { QDBusWriteLocker locker(RegisterServiceAction, this); + registerServiceNoLock(serviceName); +} + +void QDBusConnectionPrivate::registerServiceNoLock(const QString &serviceName) +{ serviceNames.append(serviceName); } void QDBusConnectionPrivate::unregisterService(const QString &serviceName) { QDBusWriteLocker locker(UnregisterServiceAction, this); + unregisterServiceNoLock(serviceName); +} + +void QDBusConnectionPrivate::unregisterServiceNoLock(const QString &serviceName) +{ serviceNames.removeAll(serviceName); } diff --git a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp index 599abbd..4494d6f 100644 --- a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp @@ -106,6 +106,8 @@ private slots: void slotsWithLessParameters(); void nestedCallWithCallback(); + void serviceRegistrationRaceCondition(); + public: QString serviceName() const { return "com.trolltech.Qt.Autotests.QDBusConnection"; } bool callMethod(const QDBusConnection &conn, const QString &path); @@ -647,6 +649,73 @@ void tst_QDBusConnection::nestedCallWithCallback() QCOMPARE(signalsReceived, 1); } +class RaceConditionSignalWaiter : public QObject +{ + Q_OBJECT +public: + int count; + RaceConditionSignalWaiter() : count (0) {} + virtual ~RaceConditionSignalWaiter() {} + +public slots: + void countUp() { ++count; emit done(); } +signals: + void done(); +}; + +void tst_QDBusConnection::serviceRegistrationRaceCondition() +{ + // There was a race condition in the updating of list of name owners in + // QtDBus. When the user connects to a signal coming from a given + // service, we must listen for NameOwnerChanged signals relevant to that + // name and update when the owner changes. However, it's possible that we + // receive in one chunk from the server both the NameOwnerChanged signal + // about the service and the signal we're interested in. Since QtDBus + // posts events in order to handle the incoming signals, the update + // happens too late. + + const QString connectionName = "testConnectionName"; + const QString serviceName = "org.example.SecondaryName"; + + QDBusConnection session = QDBusConnection::sessionBus(); + QVERIFY(!session.interface()->isServiceRegistered(serviceName)); + + // connect to the signal: + RaceConditionSignalWaiter recv; + session.connect(serviceName, "/", "com.trolltech.TestCase", "oneSignal", &recv, SLOT(countUp())); + + // create a secondary connection and register a name + QDBusConnection connection = QDBusConnection::connectToBus(QDBusConnection::SessionBus, connectionName); + QDBusConnection::disconnectFromBus(connectionName); // disconnection happens when "connection" goes out of scope + QVERIFY(connection.isConnected()); + QVERIFY(connection.registerService(serviceName)); + + // send a signal + QDBusMessage msg = QDBusMessage::createSignal("/", "com.trolltech.TestCase", "oneSignal"); + connection.send(msg); + + // make a blocking call just to be sure that the buffer was flushed + msg = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", + "NameHasOwner"); + msg << connectionName; + connection.call(msg); // ignore result + + // Now here's the race condition (more info on task QTBUG-15651): + // the bus has most likely queued three signals for us to work on: + // 1) NameOwnerChanged for the connection we created above + // 2) NameOwnerChanged for the service we registered above + // 3) The "oneSignal" signal we sent + // + // We'll most likely receive all three in one go from the server. We must + // update the owner of serviceName before we start processing the + // "oneSignal" signal. + + QTestEventLoop::instance().connect(&recv, SIGNAL(done()), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(recv.count, 1); +} + QString MyObject::path; QTEST_MAIN(tst_QDBusConnection) -- cgit v0.12 From 86ed592bba2a7ef23f5065397144c3915bdbdbd5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 19:20:25 +0100 Subject: Fix warnings with GCC 4.5: some cases are not part of the enum --- src/gui/painting/qpdf.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index ba5d164..bd68d2a 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1390,7 +1390,7 @@ int QPdfBaseEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const void QPdfBaseEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(QPdfBaseEngine); - switch (key) { + switch (int(key)) { case PPK_CollateCopies: d->collate = value.toBool(); break; @@ -1480,7 +1480,7 @@ QVariant QPdfBaseEngine::property(PrintEnginePropertyKey key) const Q_D(const QPdfBaseEngine); QVariant ret; - switch (key) { + switch (int(key)) { case PPK_CollateCopies: ret = d->collate; break; -- cgit v0.12 From c89ca078ba39780ebe556aff8fff6b92118a0a1d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 20:52:45 +0100 Subject: Fix "value not in enum" warning with GCC 4.5. QMetaType::Float is not a member of QVariant::Type. --- src/xmlpatterns/data/qatomicvalue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmlpatterns/data/qatomicvalue.cpp b/src/xmlpatterns/data/qatomicvalue.cpp index ecc78bf..fc4cf2e 100644 --- a/src/xmlpatterns/data/qatomicvalue.cpp +++ b/src/xmlpatterns/data/qatomicvalue.cpp @@ -202,7 +202,7 @@ ItemType::Ptr AtomicValue::qtToXDMType(const QXmlItem &item) Q_ASSERT(item.isAtomicValue()); const QVariant v(item.toAtomicValue()); - switch(v.type()) + switch(int(v.type())) { case QVariant::Char: /* Fallthrough. */ -- cgit v0.12 From 2534805c3fa3dafe4fad7c35687b105c6b01fd97 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Nov 2010 21:17:02 +0100 Subject: Fix warning about use of uninitialised variable --- src/network/ssl/qsslcertificate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index a3ea555..275c7be 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -716,7 +716,7 @@ QSslCertificate QSslCertificatePrivate::QSslCertificate_from_X509(X509 *x509) static bool matchLineFeed(const QByteArray &pem, int *offset) { - char ch; + char ch = 0; // ignore extra whitespace at the end of the line while (*offset < pem.size() && (ch = pem.at(*offset)) == ' ') -- cgit v0.12 From d54fe278bcbba0018bbed9a09abc35b628b0024b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 21:20:31 +0100 Subject: Fix warning about mixing integral with non-integral type in ?: --- src/gui/dialogs/qdialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qdialog.cpp b/src/gui/dialogs/qdialog.cpp index b7a0026..fbdc522 100644 --- a/src/gui/dialogs/qdialog.cpp +++ b/src/gui/dialogs/qdialog.cpp @@ -282,8 +282,8 @@ QDialog::QDialog(QWidget *parent, Qt::WindowFlags f) QDialog::QDialog(QWidget *parent, const char *name, bool modal, Qt::WindowFlags f) : QWidget(*new QDialogPrivate, parent, f - | QFlag(modal ? Qt::WShowModal : 0) - | QFlag((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : 0) + | QFlag(modal ? Qt::WShowModal : Qt::WindowType(0)) + | QFlag((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)) ) { setObjectName(QString::fromAscii(name)); -- cgit v0.12 From b284975435f80eba7bf6d1edd21987dcee134e86 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 21:23:33 +0100 Subject: Fix silly "will be initialised after" warning. --- src/declarative/util/qdeclarativepixmapcache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index a07b1bb..380d9bc 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -684,7 +684,7 @@ void QDeclarativePixmapStore::timerEvent(QTimerEvent *) } QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativePixmapData *d) -: data(d), reader(0), loading(false), redirectCount(0), requestSize(d->requestSize) +: data(d), reader(0), requestSize(d->requestSize), loading(false), redirectCount(0) { if (finishedIndex == -1) { finishedIndex = QDeclarativePixmapReply::staticMetaObject.indexOfSignal("finished()"); -- cgit v0.12 From dc23fd546163edb7ff4395f44217b5cb2600004a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Nov 2010 18:41:07 +0100 Subject: Fix warnings related to unused variables. Just add some Q_UNUSED for parameters or remove the variable we don't need for the others. Reviewed-by: Trust Me --- src/declarative/qml/qdeclarativeengine.cpp | 2 ++ src/declarative/qml/qdeclarativepropertycache.cpp | 1 - src/gui/styles/qstyle.cpp | 2 ++ src/gui/styles/qstyleoption.cpp | 4 ++++ src/opengl/qgl_x11egl.cpp | 1 - src/opengl/qglpixelbuffer_egl.cpp | 1 - src/plugins/bearer/connman/qconnmanservice_linux.cpp | 2 -- tools/shared/windows/registry.cpp | 3 +++ 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 1160ed8..c646302 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -2232,6 +2232,8 @@ bool QDeclarative_isFileCaseCorrect(const QString &fileName) if (a != c) return false; } +#else + Q_UNUSED(fileName); #endif return true; diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 0adcdbd..dd9a224 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -320,7 +320,6 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb { Q_ASSERT(engine); Q_ASSERT(metaObject); - QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine); clear(); diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp index 3ebfab2..be8f794 100644 --- a/src/gui/styles/qstyle.cpp +++ b/src/gui/styles/qstyle.cpp @@ -2456,6 +2456,8 @@ QDebug operator<<(QDebug debug, QStyle::State state) qSort(states); debug << states.join(QLatin1String(" | ")); debug << ')'; +#else + Q_UNUSED(state); #endif return debug; } diff --git a/src/gui/styles/qstyleoption.cpp b/src/gui/styles/qstyleoption.cpp index 4780edf..05ca793 100644 --- a/src/gui/styles/qstyleoption.cpp +++ b/src/gui/styles/qstyleoption.cpp @@ -5483,6 +5483,8 @@ QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) case QStyleOption::SO_GraphicsItem: debug << "SO_GraphicsItem"; break; } +#else + Q_UNUSED(optionType); #endif return debug; } @@ -5496,6 +5498,8 @@ QDebug operator<<(QDebug debug, const QStyleOption &option) debug << ',' << option.state; debug << ',' << option.rect; debug << ')'; +#else + Q_UNUSED(option); #endif return debug; } diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index d33ea56..144d140 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -97,7 +97,6 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) XVisualInfo visualInfo; XVisualInfo *vi; int numVisuals; - EGLint id = 0; visualInfo.visualid = QEgl::getCompatibleVisualId(config); vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); diff --git a/src/opengl/qglpixelbuffer_egl.cpp b/src/opengl/qglpixelbuffer_egl.cpp index 0b94f5a..2d9f6f1 100644 --- a/src/opengl/qglpixelbuffer_egl.cpp +++ b/src/opengl/qglpixelbuffer_egl.cpp @@ -74,7 +74,6 @@ bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidge // Use the same configuration as the widget we are sharing with. ctx->setConfig(shareContext->config()); #if QGL_RENDER_TEXTURE - EGLint value = EGL_FALSE; if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGBA) == EGL_TRUE) textureFormat = EGL_TEXTURE_RGBA; else if (ctx->configAttrib(EGL_BIND_TO_TEXTURE_RGB) == EGL_TRUE) diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp index 952a444..0545422 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp +++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp @@ -216,7 +216,6 @@ void QConnmanManagerInterface::registerCounter(const QString &path, quint32 inte { QDBusReply > reply = this->call(QLatin1String("RegisterCounter"), QVariant::fromValue(path), QVariant::fromValue(interval)); - bool ok = true; if(reply.error().type() == QDBusError::InvalidArgs) { qWarning() << reply.error().message(); } @@ -225,7 +224,6 @@ void QConnmanManagerInterface::registerCounter(const QString &path, quint32 inte void QConnmanManagerInterface::unregisterCounter(const QString &path) { QDBusReply > reply = this->call(QLatin1String("UnregisterCounter"), QVariant::fromValue(path)); - bool ok = true; if(reply.error().type() == QDBusError::InvalidArgs) { qWarning() << reply.error().message(); } diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp index 48e9ae6..f520910 100644 --- a/tools/shared/windows/registry.cpp +++ b/tools/shared/windows/registry.cpp @@ -157,6 +157,9 @@ QString qt_readRegistryKey(HKEY parentHandle, const QString &rSubkey) } RegCloseKey(handle); +#else + Q_UNUSED(parentHandle); + Q_UNUSED(rSubkey) #endif return result; -- cgit v0.12 From 20da7afb4c575001b7373554ebf7e7fb434a2942 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Nov 2010 20:26:58 +0100 Subject: Fix warning about address of a function being constant. In OpenGL ES 2, these functions are always expected to be present, so the address can never be zero. So only test for the function being found if we tried to find it dynamicaly. --- src/opengl/qgl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index ed9753e..18f1203 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2095,7 +2095,9 @@ void QGLContextPrivate::cleanup() void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) { Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT); +#ifdef glEnableVertexAttribArray Q_ASSERT(glEnableVertexAttribArray); +#endif if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled) glDisableVertexAttribArray(arrayIndex); @@ -2108,7 +2110,9 @@ void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled void QGLContextPrivate::syncGlState() { +#ifdef glEnableVertexAttribArray Q_ASSERT(glEnableVertexAttribArray); +#endif for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) { if (vertexAttributeArraysEnabledState[i]) glEnableVertexAttribArray(i); -- cgit v0.12 From 3251c5023c184466e8199c8999aa6e332eb98534 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Nov 2010 20:28:23 +0100 Subject: Fix warning about %x parameter type mismatch in EGL --- src/opengl/qgl_x11egl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 144d140..75dd1b6 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -345,7 +345,7 @@ void QGLWidgetPrivate::recreateEglSurface() // old surface before re-creating a new one. Note: This should not be the case as the // surface should be deleted before the old window id. if (glcx->d_func()->eglSurface != EGL_NO_SURFACE && (currentId != eglSurfaceWindowId)) { - qWarning("EGL surface for deleted window %x was not destroyed", eglSurfaceWindowId); + qWarning("EGL surface for deleted window %x was not destroyed", uint(eglSurfaceWindowId)); glcx->d_func()->destroyEglSurfaceForDevice(); } -- cgit v0.12 From d89985ce546f63f4e563ccc54951957d2f33c5ec Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Nov 2010 19:21:17 +0100 Subject: Fix strict-aliasing violation warning. Strict aliasing is violated here, so just silence the compiler (GCC) by using an extension. --- src/gui/text/qtextformat.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 46db253..fdbb680 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -265,10 +265,18 @@ private: friend QDataStream &operator>>(QDataStream &, QTextFormat &); }; -// this is only safe if sizeof(int) == sizeof(float) +// this is only safe because sizeof(int) == sizeof(float) static inline uint hash(float d) { +#ifdef Q_CC_GNU + // this is a GCC extension and isn't guaranteed to work in other compilers + // the reinterpret_cast below generates a strict-aliasing warning with GCC + union { float f; uint u; } cvt; + cvt.f = d; + return cvt.u; +#else return reinterpret_cast(d); +#endif } static inline uint hash(const QColor &color) -- cgit v0.12