Advertisement
Guest User

bhughes

a guest
Aug 31st, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 18.49 KB | None | 0 0
  1. From beae7886f42cba5268ed89c311120bbde3963b45 Mon Sep 17 00:00:00 2001
  2. From: Bradley T. Hughes <bradley.hughes@nokia.com>
  3. Date: Wed, 31 Aug 2011 15:17:30 +0200
  4. Subject: [PATCH] Don't use QSettings to "cache" plugin information
  5.  
  6. The main rationale of the cache was to examine the plugin's build-key
  7. before loading it. Now that the build-key has been removed, the cache
  8. has lost its usefulness.
  9.  
  10. This is part of a larger push to not use QSettings for Qt specific
  11. settings or caches.
  12.  
  13. See also:
  14. http://lists.qt.nokia.com/pipermail/qt5-feedback/2011-August/000892.html
  15. http://lists.qt.nokia.com/pipermail/qt5-feedback/2011-August/000960.html
  16. http://lists.qt.nokia.com/pipermail/qt5-feedback/2011-August/000907.html
  17. http://lists.qt.nokia.com/pipermail/qt5-feedback/2011-August/000904.html
  18.  
  19. Change-Id: I96e84aa25983c8e06e027ff70cef109444c362a2
  20.  
  21. diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
  22. index 2458f96..6d8bf20 100644
  23. --- a/src/corelib/kernel/qcoreapplication.cpp
  24. +++ b/src/corelib/kernel/qcoreapplication.cpp
  25. @@ -266,18 +266,6 @@ bool QCoreApplicationPrivate::is_app_closing = false;
  26.  // initialized in qcoreapplication and in qtextstream autotest when setlocale is called.
  27.  Q_CORE_EXPORT bool qt_locale_initialized = false;
  28.  
  29. -
  30. -/*
  31. -  Create an instance of Trolltech.conf. This ensures that the settings will not
  32. -  be thrown out of QSetting's cache for unused settings.
  33. -  */
  34. -Q_GLOBAL_STATIC_WITH_ARGS(QSettings, staticTrolltechConf, (QSettings::UserScope, QLatin1String("Trolltech")))
  35. -
  36. -QSettings *QCoreApplicationPrivate::trolltechConf()
  37. -{
  38. -    return staticTrolltechConf();
  39. -}
  40. -
  41.  Q_CORE_EXPORT uint qGlobalPostedEventsCount()
  42.  {
  43.      QThreadData *currentThreadData = QThreadData::current();
  44. diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h
  45. index 553e15f..8dff4ed 100644
  46. --- a/src/corelib/kernel/qcoreapplication_p.h
  47. +++ b/src/corelib/kernel/qcoreapplication_p.h
  48. @@ -139,7 +139,6 @@ public:
  49.      static uint attribs;
  50.      static inline bool testAttribute(uint flag) { return attribs & (1 << flag); }
  51.      static int app_compile_version;
  52. -    static QSettings *trolltechConf();
  53.  };
  54.  
  55.  QT_END_NAMESPACE
  56. diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp
  57. index c8831e5..c175dcf 100644
  58. --- a/src/corelib/plugin/qfactoryloader.cpp
  59. +++ b/src/corelib/plugin/qfactoryloader.cpp
  60. @@ -45,7 +45,6 @@
  61.  #include "qfactoryinterface.h"
  62.  #include "qmap.h"
  63.  #include <qdir.h>
  64. -#include <qsettings.h>
  65.  #include <qdebug.h>
  66.  #include "qmutex.h"
  67.  #include "qplugin.h"
  68. @@ -107,7 +106,6 @@ void QFactoryLoader::update()
  69.  #ifdef QT_SHARED
  70.      Q_D(QFactoryLoader);
  71.      QStringList paths = QCoreApplication::libraryPaths();
  72. -    QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
  73.      for (int i = 0; i < paths.count(); ++i) {
  74.          const QString &pluginDir = paths.at(i);
  75.          // Already loaded, skip it...
  76. @@ -127,7 +125,7 @@ void QFactoryLoader::update()
  77.                  qDebug() << "QFactoryLoader::QFactoryLoader() looking at" << fileName;
  78.              }
  79.              library = QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath());
  80. -            if (!library->isPlugin(&settings)) {
  81. +            if (!library->isPlugin()) {
  82.                  if (qt_debug_component()) {
  83.                      qDebug() << library->errorString;
  84.                      qDebug() << "         not a plugin";
  85. @@ -135,45 +133,26 @@ void QFactoryLoader::update()
  86.                  library->release();
  87.                  continue;
  88.              }
  89. -            QString regkey = QString::fromLatin1("Qt Factory Cache %1.%2/%3:/%4")
  90. -                             .arg((QT_VERSION & 0xff0000) >> 16)
  91. -                             .arg((QT_VERSION & 0xff00) >> 8)
  92. -                             .arg(QLatin1String(d->iid))
  93. -                             .arg(fileName);
  94. -            QStringList reg, keys;
  95. -            reg = settings.value(regkey).toStringList();
  96. -            if (reg.count() && library->lastModified == reg[0]) {
  97. -                keys = reg;
  98. -                keys.removeFirst();
  99. -            } else {
  100. -                if (!library->loadPlugin()) {
  101. -                    if (qt_debug_component()) {
  102. -                        qDebug() << library->errorString;
  103. -                        qDebug() << "           could not load";
  104. -                    }
  105. -                    library->release();
  106. -                    continue;
  107. -                }
  108. -                QObject *instance = library->instance();
  109. -                if (!instance) {
  110. -                    library->release();
  111. -                    // ignore plugins that have a valid signature but cannot be loaded.
  112. -                    continue;
  113. +            QStringList keys;
  114. +            if (!library->loadPlugin()) {
  115. +                if (qt_debug_component()) {
  116. +                    qDebug() << library->errorString;
  117. +                    qDebug() << "           could not load";
  118.                  }
  119. -                QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instance);
  120. -                if (instance && factory && instance->qt_metacast(d->iid))
  121. -                    keys = factory->keys();
  122. -                if (keys.isEmpty())
  123. -                    library->unload();
  124. -                reg.clear();
  125. -                reg << library->lastModified;
  126. -                reg += keys;
  127. -                settings.setValue(regkey, reg);
  128. +                library->release();
  129. +                continue;
  130.              }
  131. -            if (qt_debug_component()) {
  132. -                qDebug() << "keys" << keys;
  133. +            QObject *instance = library->instance();
  134. +            if (!instance) {
  135. +                library->release();
  136. +                // ignore plugins that have a valid signature but cannot be loaded.
  137. +                continue;
  138.              }
  139. -
  140. +            QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instance);
  141. +            if (instance && factory && instance->qt_metacast(d->iid))
  142. +                keys = factory->keys();
  143. +            if (keys.isEmpty())
  144. +                library->unload();
  145.              if (keys.isEmpty()) {
  146.                  library->release();
  147.                  continue;
  148. diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
  149. index 25f44d0..b971b76 100644
  150. --- a/src/corelib/plugin/qlibrary.cpp
  151. +++ b/src/corelib/plugin/qlibrary.cpp
  152. @@ -50,8 +50,6 @@
  153.  #include <qfileinfo.h>
  154.  #include <qmutex.h>
  155.  #include <qmap.h>
  156. -#include <qsettings.h>
  157. -#include <qdatetime.h>
  158.  #include <private/qcoreapplication_p.h>
  159.  #ifdef Q_OS_MAC
  160.  #  include <private/qcore_mac_p.h>
  161. @@ -648,7 +646,7 @@ bool qt_get_verificationdata(QtPluginQueryVerificationDataFunction pfn, uint *qt
  162.      return qt_parse_pattern(szData, qt_version, debug);
  163.  }
  164.  
  165. -bool QLibraryPrivate::isPlugin(QSettings *settings)
  166. +bool QLibraryPrivate::isPlugin()
  167.  {
  168.      errorString.clear();
  169.      if (pluginState != MightBeAPlugin)
  170. @@ -672,135 +670,88 @@ bool QLibraryPrivate::isPlugin(QSettings *settings)
  171.      }
  172.  #endif
  173.  
  174. -    QFileInfo fileinfo(fileName);
  175. -
  176. -#ifndef QT_NO_DATESTRING
  177. -    lastModified  = fileinfo.lastModified().toString(Qt::ISODate);
  178. -#endif
  179. -    QString regkey = QString::fromLatin1("Qt Plugin Cache %1.%2.%3/%4")
  180. -                     .arg((QT_VERSION & 0xff0000) >> 16)
  181. -                     .arg((QT_VERSION & 0xff00) >> 8)
  182. -                     .arg(QLIBRARY_AS_DEBUG ? QLatin1String("debug") : QLatin1String("false"))
  183. -                     .arg(fileName);
  184. -#ifdef Q_WS_MAC
  185. -    // On Mac, add the application arch to the reg key in order to
  186. -    // cache plugin information separately for each arch. This prevents
  187. -    // Qt from wrongly caching plugin load failures when the archs
  188. -    // don't match.
  189. -#if defined(__x86_64__)
  190. -    regkey += QLatin1String("-x86_64");
  191. -#elif defined(__i386__)
  192. -    regkey += QLatin1String("-i386");
  193. -#elif defined(__ppc64__)
  194. -    regkey += QLatin1String("-ppc64");
  195. -#elif defined(__ppc__)
  196. -    regkey += QLatin1String("-ppc");
  197. -#endif
  198. -#endif // Q_WS_MAC
  199. -
  200. -    QStringList reg;
  201. -#ifndef QT_NO_SETTINGS
  202. -    if (!settings) {
  203. -        settings = QCoreApplicationPrivate::trolltechConf();
  204. -    }
  205. -    reg = settings->value(regkey).toStringList();
  206. -#endif
  207. -    if (reg.count() == 3 && lastModified == reg.at(2)) {
  208. -        qt_version = reg.at(0).toUInt(0, 16);
  209. -        debug = bool(reg.at(1).toInt());
  210. -        success = qt_version != 0;
  211. -    } else {
  212.  #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)
  213. -        if (!pHnd) {
  214. -            // use unix shortcut to avoid loading the library
  215. -            success = qt_unix_query(fileName, &qt_version, &debug, &key, this);
  216. -        } else
  217. +    if (!pHnd) {
  218. +        // use unix shortcut to avoid loading the library
  219. +        success = qt_unix_query(fileName, &qt_version, &debug, &key, this);
  220. +    } else
  221.  #endif
  222. -        {
  223. -            bool retryLoadLibrary = false;    // Only used on Windows with MS compiler.(false in other cases)
  224. -            do {
  225. -                bool temporary_load = false;
  226. +    {
  227. +        bool retryLoadLibrary = false;    // Only used on Windows with MS compiler.(false in other cases)
  228. +        do {
  229. +            bool temporary_load = false;
  230.  #ifdef Q_OS_WIN
  231. -                HMODULE hTempModule = 0;
  232. +            HMODULE hTempModule = 0;
  233.  #endif
  234. -                if (!pHnd) {
  235. +            if (!pHnd) {
  236.  #ifdef Q_OS_WIN
  237. -                    DWORD dwFlags = (retryLoadLibrary) ? 0: DONT_RESOLVE_DLL_REFERENCES;
  238. -                    //avoid 'Bad Image' message box
  239. -                    UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
  240. -                    hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, dwFlags);
  241. -                    SetErrorMode(oldmode);
  242. +                DWORD dwFlags = (retryLoadLibrary) ? 0: DONT_RESOLVE_DLL_REFERENCES;
  243. +                //avoid 'Bad Image' message box
  244. +                UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
  245. +                hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, dwFlags);
  246. +                SetErrorMode(oldmode);
  247.  #else
  248.  #  if defined(Q_OS_SYMBIAN)
  249. -                    //Guard against accidentally trying to load non-plugin libraries by making sure the stub exists
  250. -                    if (fileinfo.exists())
  251. +                //Guard against accidentally trying to load non-plugin libraries by making sure the stub exists
  252. +                if (fileinfo.exists())
  253.  #  endif
  254. -                        temporary_load =  load_sys();
  255. +                    temporary_load =  load_sys();
  256.  #endif
  257. -                }
  258. +            }
  259.  #ifdef Q_OS_WIN
  260. -                QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = hTempModule ? (QtPluginQueryVerificationDataFunction)
  261. +            QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = hTempModule ? (QtPluginQueryVerificationDataFunction)
  262.  #ifdef Q_OS_WINCE
  263. -                        ::GetProcAddress(hTempModule, L"qt_plugin_query_verification_data")
  264. +                    ::GetProcAddress(hTempModule, L"qt_plugin_query_verification_data")
  265.  #else
  266. -                        ::GetProcAddress(hTempModule, "qt_plugin_query_verification_data")
  267. +                    ::GetProcAddress(hTempModule, "qt_plugin_query_verification_data")
  268.  #endif
  269. -                : (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
  270. +                    : (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
  271.  #else
  272. -                QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = NULL;
  273. +            QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = NULL;
  274.  #  if defined(Q_OS_SYMBIAN)
  275. -                if (temporary_load) {
  276. -                    qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
  277. -                    // If resolving with function name failed (i.e. not STDDLL), try resolving using known ordinal
  278. -                    if (!qtPluginQueryVerificationDataFunction)
  279. -                        qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("1");
  280. -                }
  281. -#  else
  282. +            if (temporary_load) {
  283.                  qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
  284. +                // If resolving with function name failed (i.e. not STDDLL), try resolving using known ordinal
  285. +                if (!qtPluginQueryVerificationDataFunction)
  286. +                    qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("1");
  287. +            }
  288. +#  else
  289. +            qtPluginQueryVerificationDataFunction = (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");
  290.  #  endif
  291.  #endif
  292. -                bool exceptionThrown = false;
  293. -                bool ret = qt_get_verificationdata(qtPluginQueryVerificationDataFunction,
  294. -                                                   &qt_version, &debug, &exceptionThrown);
  295. -                if (!exceptionThrown) {
  296. -                    if (!ret) {
  297. -                        qt_version = 0;
  298. -                        if (temporary_load)
  299. -                            unload_sys();
  300. -                    } else {
  301. -                        success = true;
  302. -                    }
  303. -                    retryLoadLibrary = false;
  304. +            bool exceptionThrown = false;
  305. +            bool ret = qt_get_verificationdata(qtPluginQueryVerificationDataFunction,
  306. +                                               &qt_version, &debug, &exceptionThrown);
  307. +            if (!exceptionThrown) {
  308. +                if (!ret) {
  309. +                    qt_version = 0;
  310. +                    if (temporary_load)
  311. +                        unload_sys();
  312. +                } else {
  313. +                    success = true;
  314.                  }
  315. +                retryLoadLibrary = false;
  316. +            }
  317.  #ifdef QT_USE_MS_STD_EXCEPTION
  318. -                else {
  319. -                    // An exception was thrown when calling qt_plugin_query_verification_data().
  320. -                    // This usually happens when plugin is compiled with the /clr compiler flag,
  321. -                    // & will only work if the dependencies are loaded & DLLMain() is called.
  322. -                    // LoadLibrary() will do this, try once with this & if it fails dont load.
  323. -                    retryLoadLibrary = !retryLoadLibrary;
  324. -                }
  325. +            else {
  326. +                // An exception was thrown when calling qt_plugin_query_verification_data().
  327. +                // This usually happens when plugin is compiled with the /clr compiler flag,
  328. +                // & will only work if the dependencies are loaded & DLLMain() is called.
  329. +                // LoadLibrary() will do this, try once with this & if it fails dont load.
  330. +                retryLoadLibrary = !retryLoadLibrary;
  331. +            }
  332.  #endif
  333.  #ifdef Q_OS_WIN
  334. -                if (hTempModule) {
  335. -                    BOOL ok = ::FreeLibrary(hTempModule);
  336. -                    if (ok) {
  337. -                        hTempModule = 0;
  338. -                    }
  339. -
  340. +            if (hTempModule) {
  341. +                BOOL ok = ::FreeLibrary(hTempModule);
  342. +                if (ok) {
  343. +                    hTempModule = 0;
  344.                  }
  345. -#endif
  346. -            } while(retryLoadLibrary);  // Will be 'false' in all cases other than when an
  347. -                                        // exception is thrown(will happen only when using a MS compiler)
  348. -        }
  349.  
  350. -#ifndef QT_NO_SETTINGS
  351. -        QStringList queried;
  352. -        queried << QString::number(qt_version,16)
  353. -                << QString::number((int)debug)
  354. -                << lastModified;
  355. -        settings->setValue(regkey, queried);
  356. +            }
  357.  #endif
  358. +        } while(retryLoadLibrary);  // Will be 'false' in all cases other than when an
  359. +        // exception is thrown(will happen only when using a MS compiler)
  360.      }
  361.  
  362.      if (!success) {
  363. @@ -818,22 +769,22 @@ bool QLibraryPrivate::isPlugin(QSettings *settings)
  364.      if ((qt_version & 0x00ff00) > (QT_VERSION & 0x00ff00) || (qt_version & 0xff0000) != (QT_VERSION & 0xff0000)) {
  365.          if (qt_debug_component()) {
  366.              qWarning("In %s:\n"
  367. -                 "  Plugin uses incompatible Qt library (%d.%d.%d) [%s]",
  368. -                 (const char*) QFile::encodeName(fileName),
  369. -                 (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff,
  370. -                 debug ? "debug" : "release");
  371. +                     "  Plugin uses incompatible Qt library (%d.%d.%d) [%s]",
  372. +                     (const char*) QFile::encodeName(fileName),
  373. +                     (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff,
  374. +                     debug ? "debug" : "release");
  375.          }
  376.          errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library. (%2.%3.%4) [%5]")
  377. -            .arg(fileName)
  378. -            .arg((qt_version&0xff0000) >> 16)
  379. -            .arg((qt_version&0xff00) >> 8)
  380. -            .arg(qt_version&0xff)
  381. -            .arg(debug ? QLatin1String("debug") : QLatin1String("release"));
  382. +                .arg(fileName)
  383. +                .arg((qt_version&0xff0000) >> 16)
  384. +                .arg((qt_version&0xff00) >> 8)
  385. +                .arg(qt_version&0xff)
  386. +                .arg(debug ? QLatin1String("debug") : QLatin1String("release"));
  387.  #ifndef QT_NO_DEBUG_PLUGIN_CHECK
  388.      } else if(debug != QLIBRARY_AS_DEBUG) {
  389.          //don't issue a qWarning since we will hopefully find a non-debug? --Sam
  390.          errorString = QLibrary::tr("The plugin '%1' uses incompatible Qt library."
  391. -                 " (Cannot mix debug and release libraries.)").arg(fileName);
  392. +                                   " (Cannot mix debug and release libraries.)").arg(fileName);
  393.  #endif
  394.      } else {
  395.          pluginState = IsAPlugin;
  396. diff --git a/src/corelib/plugin/qlibrary_p.h b/src/corelib/plugin/qlibrary_p.h
  397. index 12d6250..5559489 100644
  398. --- a/src/corelib/plugin/qlibrary_p.h
  399. +++ b/src/corelib/plugin/qlibrary_p.h
  400. @@ -68,7 +68,6 @@ QT_BEGIN_NAMESPACE
  401.  
  402.  bool qt_debug_component();
  403.  
  404. -class QSettings;
  405.  class QLibraryPrivate
  406.  {
  407.  public:
  408. @@ -99,7 +98,7 @@ public:
  409.      QString errorString;
  410.      QLibrary::LoadHints loadHints;
  411.  
  412. -    bool isPlugin(QSettings *settings = 0);
  413. +    bool isPlugin();
  414.  
  415.  
  416.  private:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement