QLibrary: fix load() after a failed load()

Regression introduced by commit 8d4eb292b2
in 6.0, when QTaggedPointer was introduced. We set the tag even when the
loading failed and failed to reset it because d = {} retains the tag.

Pick-to: 6.2 6.4
Fixes: QTBUG-103387
Change-Id: Ie4bb662dcb274440ab8bfffd170a07aa9c9ecfca
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2022-08-10 09:10:41 -07:00
parent 636dbe6045
commit 823b7c7bce
2 changed files with 78 additions and 2 deletions

View File

@ -776,9 +776,11 @@ bool QLibrary::load()
return false;
if (d.tag() == Loaded)
return d->pHnd.loadRelaxed();
else
if (d->load()) {
d.setTag(Loaded);
return d->load();
return true;
}
return false;
}
/*!

View File

@ -90,10 +90,14 @@ private slots:
void unload_data();
void unload();
void unload_after_implicit_load();
void setFilenameAfterFailedLoad();
void loadAfterFailedLoad();
void isLibrary_data();
void isLibrary();
void version_data();
void version();
void setFileNameAndVersionAfterFailedLoad_data() { version_data(); }
void setFileNameAndVersionAfterFailedLoad();
void errorString_data();
void errorString();
void loadHints();
@ -272,6 +276,76 @@ void tst_QLibrary::unload_after_implicit_load()
QCOMPARE(library.isLoaded(), false);
}
void tst_QLibrary::setFilenameAfterFailedLoad()
{
#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt");
#endif
QLibrary library(directory + "/nolib");
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
library.setFileName(directory + "/mylib");
QVERIFY(library.load());
QVERIFY(library.isLoaded());
auto p = (VersionFunction)library.resolve("mylibversion");
QVERIFY(p);
QCOMPARE(p(), 2);
library.unload();
}
void tst_QLibrary::setFileNameAndVersionAfterFailedLoad()
{
QLibrary library(directory + "/nolib");
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
#if !defined(Q_OS_AIX) && !defined(Q_OS_WIN)
QFETCH(QString, lib);
QFETCH(int, loadversion);
QFETCH(int, resultversion);
library.setFileNameAndVersion(directory + '/' + lib, loadversion);
QVERIFY(library.load());
QVERIFY(library.isLoaded());
auto p = (VersionFunction)library.resolve("mylibversion");
QVERIFY(p);
QCOMPARE(p(), resultversion);
library.unload();
#endif
}
void tst_QLibrary::loadAfterFailedLoad()
{
#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID)
QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt");
#endif
QTemporaryDir dir;
QLibrary library(dir.path() + "/mylib");
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
QVERIFY(!library.load());
QVERIFY(!library.isLoaded());
// now copy the actual lib file into our dir
QString actualLib = PREFIX "mylib" SUFFIX;
QVERIFY(QFile::copy(directory + '/' + actualLib, dir.filePath(actualLib)));
// try again, must succeed now
QVERIFY(library.load());
QVERIFY(library.isLoaded());
auto p = (VersionFunction)library.resolve("mylibversion");
QVERIFY(p);
QCOMPARE(p(), 2);
library.unload();
}
void tst_QLibrary::resolve_data()
{
QTest::addColumn<QString>("lib");