QLibrary: stop setting errorString after resolve()

resolve() is technically thread-safe if the library has been loadaed. We
don't promise that, but it's there. More importantly, because
QLibraryPrivate is shared among QPluginLoader and QLibrary that point to
the same file, we can't thread-safely set the error string.

[ChangeLog][Important Behavior Changes] QLibrary::resolve() will no
longer set or clear the error string based on the success of finding the
symbol. The error string will reflect the result of loading the library.

Change-Id: I46bf1f65e8db46afbde5fffd15e1a4f4c2713c17
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Thiago Macieira 2019-12-18 18:31:55 -08:00
parent f6c1cebe42
commit ef92ac5636
3 changed files with 1 additions and 13 deletions

View File

@ -317,12 +317,6 @@ Q_CORE_EXPORT QFunctionPointer qt_mac_resolve_sys(void *handle, const char *symb
QFunctionPointer QLibraryPrivate::resolve_sys(const char* symbol)
{
QFunctionPointer address = QFunctionPointer(dlsym(pHnd, symbol));
if (!address) {
errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
QString::fromLatin1(symbol), fileName, qdlerror());
} else {
errorString.clear();
}
return address;
}

View File

@ -162,12 +162,6 @@ bool QLibraryPrivate::unload_sys()
QFunctionPointer QLibraryPrivate::resolve_sys(const char* symbol)
{
FARPROC address = GetProcAddress(pHnd, symbol);
if (!address) {
errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
QString::fromLatin1(symbol), QDir::toNativeSeparators(fileName), qt_error_string());
} else {
errorString.clear();
}
return QFunctionPointer(address);
}
QT_END_NAMESPACE

View File

@ -368,7 +368,7 @@ void tst_QLibrary::errorString_data()
QTest::newRow("bad load()") << (int)Load << QString("nosuchlib") << false << QString("Cannot load library nosuchlib: .*");
QTest::newRow("call errorString() on QLibrary with no d-pointer (crashtest)") << (int)(Load | DontSetFileName) << QString() << false << QString("Unknown error");
QTest::newRow("bad resolve") << (int)Resolve << appDir + "/mylib" << false << QString("Cannot resolve symbol \"nosuchsymbol\" in \\S+: .*");
QTest::newRow("bad resolve") << (int)Resolve << appDir + "/mylib" << false << QString("Unknown error");
QTest::newRow("good resolve") << (int)Resolve << appDir + "/mylib" << true << QString("Unknown error");
#ifdef Q_OS_WIN