QFactoryLoader: use RAII for QLibraryPrivate
Good style. Change-Id: I5e52dc5b093c43a3b678fffd16b5f15fddb9d8b4 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
d5cac0b19b
commit
b7a8051269
@ -164,6 +164,11 @@ QFactoryLoaderPrivate::~QFactoryLoaderPrivate()
|
|||||||
|
|
||||||
inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
|
inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
|
||||||
{
|
{
|
||||||
|
struct LibraryReleaser {
|
||||||
|
void operator()(QLibraryPrivate *library)
|
||||||
|
{ if (library) library->release(); }
|
||||||
|
};
|
||||||
|
|
||||||
// If we've already loaded, skip it...
|
// If we've already loaded, skip it...
|
||||||
if (loadedPaths.hasSeen(path))
|
if (loadedPaths.hasSeen(path))
|
||||||
return;
|
return;
|
||||||
@ -203,11 +208,11 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
|
|||||||
|
|
||||||
Q_TRACE(QFactoryLoader_update, fileName);
|
Q_TRACE(QFactoryLoader_update, fileName);
|
||||||
|
|
||||||
QLibraryPrivate *library = QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath());
|
std::unique_ptr<QLibraryPrivate, LibraryReleaser> library;
|
||||||
|
library.reset(QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath()));
|
||||||
if (!library->isPlugin()) {
|
if (!library->isPlugin()) {
|
||||||
qCDebug(lcFactoryLoader) << library->errorString << Qt::endl
|
qCDebug(lcFactoryLoader) << library->errorString << Qt::endl
|
||||||
<< " not a plugin";
|
<< " not a plugin";
|
||||||
library->release();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,10 +230,8 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
|
|||||||
}
|
}
|
||||||
qCDebug(lcFactoryLoader) << "Got keys from plugin meta data" << keys;
|
qCDebug(lcFactoryLoader) << "Got keys from plugin meta data" << keys;
|
||||||
|
|
||||||
if (!metaDataOk) {
|
if (!metaDataOk)
|
||||||
library->release();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
int keyUsageCount = 0;
|
int keyUsageCount = 0;
|
||||||
for (int k = 0; k < keys.count(); ++k) {
|
for (int k = 0; k < keys.count(); ++k) {
|
||||||
@ -244,16 +247,14 @@ inline void QFactoryLoaderPrivate::updateSinglePath(const QString &path)
|
|||||||
prev_qt_version = int(previous->metaData.value(QtPluginMetaDataKeys::QtVersion).toInteger());
|
prev_qt_version = int(previous->metaData.value(QtPluginMetaDataKeys::QtVersion).toInteger());
|
||||||
int qt_version = int(library->metaData.value(QtPluginMetaDataKeys::QtVersion).toInteger());
|
int qt_version = int(library->metaData.value(QtPluginMetaDataKeys::QtVersion).toInteger());
|
||||||
if (!previous || (prev_qt_version > QtVersionNoPatch && qt_version <= QtVersionNoPatch)) {
|
if (!previous || (prev_qt_version > QtVersionNoPatch && qt_version <= QtVersionNoPatch)) {
|
||||||
keyMap[key] = library;
|
keyMap[key] = library.get(); // we WILL .release()
|
||||||
++keyUsageCount;
|
++keyUsageCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keyUsageCount || keys.isEmpty()) {
|
if (keyUsageCount || keys.isEmpty()) {
|
||||||
library->setLoadHints(QLibrary::PreventUnloadHint); // once loaded, don't unload
|
library->setLoadHints(QLibrary::PreventUnloadHint); // once loaded, don't unload
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
libraryList += library;
|
libraryList += library.release();
|
||||||
} else {
|
|
||||||
library->release();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user