Преглед изворни кода

CommandLineModules: Fix Qt5 build error related to ResultStore

This commit accounts for changes introduced in qt/qtbase@6797570 (Fix UB
in QFutureInterface: invalid casts from ResultStoreBase to ResultStore<>)
Jean-Christophe Fillion-Robin пре 7 година
родитељ
комит
2b9a3d3276

+ 8 - 1
Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.cpp

@@ -112,9 +112,12 @@ QFutureInterface<ctkCmdLineModuleResult>::~QFutureInterface()
 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
   if (referenceCountIsOne())
     resultStore().clear();
-#else
+#elif QT_VERSION < QT_VERSION_CHECK(5,9,0)
   if (!derefT())
     resultStore().clear();
+#else
+  if (!derefT())
+    resultStore().clear<ctkCmdLineModuleResult>();
 #endif
 
   if (!d->RefCount.deref())
@@ -139,7 +142,11 @@ QFutureInterface<ctkCmdLineModuleResult>::operator=(const QFutureInterface& othe
   other.refT();
   if (!derefT())
 #endif
+#if QT_VERSION < QT_VERSION_CHECK(5,9,0)
     resultStore().clear();
+#else
+    resultStore().clear<ctkCmdLineModuleResult>();
+#endif
 
   QFutureInterfaceBase::operator=(other);
 

+ 32 - 9
Libs/CommandLineModules/Core/ctkCmdLineModuleFutureInterface.h

@@ -27,7 +27,7 @@
 #include "ctkCmdLineModuleResult.h"
 
 #include <QFutureInterface>
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 #include <QtCore>
 #else
 #include <QtConcurrent>
@@ -88,16 +88,21 @@ private:
 
   friend struct ctkCmdLineModuleFutureWatcherPrivate;
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
   QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore()
   { return static_cast<QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
   const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &resultStore() const
   { return static_cast<const QtConcurrent::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
   QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore()
   { return static_cast<QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
   const QtPrivate::ResultStore<ctkCmdLineModuleResult> &resultStore() const
   { return static_cast<const QtPrivate::ResultStore<ctkCmdLineModuleResult> &>(resultStoreBase()); }
+#else
+  QtPrivate::ResultStoreBase &resultStore()
+  { return static_cast<QtPrivate::ResultStoreBase &>(resultStoreBase()); }
+  const QtPrivate::ResultStoreBase &resultStore() const
+  { return static_cast<const QtPrivate::ResultStoreBase &>(resultStoreBase()); }
 #endif
 
   ctkCmdLineModuleFutureInterfacePrivate* d;
@@ -110,10 +115,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResult(const ctkCmdL
         return;
     }
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
+#else
+    QtPrivate::ResultStoreBase &store = resultStore();
 #endif
 
     if (store.filterMode()) {
@@ -138,10 +145,12 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportResults(const QVecto
         return;
     }
 
-#if (QT_VERSION < 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultStore<ctkCmdLineModuleResult> &store = resultStore();
+#else
+    QtPrivate::ResultStoreBase &store = resultStore();
 #endif
 
     if (store.filterMode()) {
@@ -164,13 +173,21 @@ inline void QFutureInterface<ctkCmdLineModuleResult>::reportFinished(const ctkCm
 inline const ctkCmdLineModuleResult &QFutureInterface<ctkCmdLineModuleResult>::resultReference(int index) const
 {
     QMutexLocker lock(mutex());
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     return resultStore().resultAt(index).value();
+#else
+    return resultStore().resultAt(index).value<ctkCmdLineModuleResult>();
+#endif
 }
 
 inline const ctkCmdLineModuleResult *QFutureInterface<ctkCmdLineModuleResult>::resultPointer(int index) const
 {
     QMutexLocker lock(mutex());
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     return resultStore().resultAt(index).pointer();
+#else
+    return resultStore().resultAt(index).pointer<ctkCmdLineModuleResult>();
+#endif
 }
 
 inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::results()
@@ -184,13 +201,19 @@ inline QList<ctkCmdLineModuleResult> QFutureInterface<ctkCmdLineModuleResult>::r
     QList<ctkCmdLineModuleResult> res;
     QMutexLocker lock(mutex());
 
-#if (QT_VERSION <= 0x50000)
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QtConcurrent::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
-#else
+#elif (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
     QtPrivate::ResultIterator<ctkCmdLineModuleResult> it = resultStore().begin();
+#else
+    QtPrivate::ResultIteratorBase it = resultStore().begin();
 #endif
     while (it != resultStore().end()) {
+#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0))
         res.append(it.value());
+#else
+        res.append(it.value<ctkCmdLineModuleResult>());
+#endif
         ++it;
     }