diff options
Diffstat (limited to 'src/corelib/plugin/qlibrary_unix.cpp')
-rw-r--r-- | src/corelib/plugin/qlibrary_unix.cpp | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 898d5a2f6c..6d764f1ba1 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -12,7 +12,7 @@ #include <dlfcn.h> -#ifdef Q_OS_MAC +#ifdef Q_OS_DARWIN # include <private/qcore_mac_p.h> #endif @@ -25,12 +25,6 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; -static QString qdlerror() -{ - const char *err = dlerror(); - return err ? u'(' + QString::fromLocal8Bit(err) + u')' : QString(); -} - QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) { QStringList suffixes; @@ -72,7 +66,7 @@ QStringList QLibraryPrivate::suffixes_sys(const QString &fullVersion) # endif } #endif -# ifdef Q_OS_MAC +# ifdef Q_OS_DARWIN if (!fullVersion.isEmpty()) { suffixes << ".%1.bundle"_L1.arg(fullVersion); suffixes << ".%1.dylib"_L1.arg(fullVersion); @@ -90,6 +84,11 @@ QStringList QLibraryPrivate::prefixes_sys() bool QLibraryPrivate::load_sys() { +#if defined(Q_OS_WASM) && defined(QT_STATIC) + // emscripten does not support dlopen when using static linking + return false; +#endif + QMutexLocker locker(&mutex); QString attempt; QFileSystemEntry fsEntry(fileName); @@ -186,15 +185,13 @@ bool QLibraryPrivate::load_sys() Handle hnd = nullptr; for (int prefix = 0; retry && !hnd && prefix < prefixes.size(); prefix++) { for (int suffix = 0; retry && !hnd && suffix < suffixes.size(); suffix++) { - if (!prefixes.at(prefix).isEmpty() && name.startsWith(prefixes.at(prefix))) - continue; if (path.isEmpty() && prefixes.at(prefix).contains(u'/')) continue; if (!suffixes.at(suffix).isEmpty() && name.endsWith(suffixes.at(suffix))) continue; if (loadHints & QLibrary::LoadArchiveMemberHint) { attempt = name; - int lparen = attempt.indexOf(u'('); + qsizetype lparen = attempt.indexOf(u'('); if (lparen == -1) lparen = attempt.size(); attempt = path + prefixes.at(prefix) + attempt.insert(lparen, suffixes.at(suffix)); @@ -208,14 +205,6 @@ bool QLibraryPrivate::load_sys() auto attemptFromBundle = attempt; hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(u'/', u'_')), dlFlags); } - if (hnd) { - using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved); - JniOnLoadPtr jniOnLoad = reinterpret_cast<JniOnLoadPtr>(dlsym(hnd, "JNI_OnLoad")); - if (jniOnLoad && jniOnLoad(QJniEnvironment::javaVM(), nullptr) == JNI_ERR) { - dlclose(hnd); - hnd = nullptr; - } - } #endif if (!hnd && fileName.startsWith(u'/') && QFile::exists(attempt)) { @@ -228,7 +217,7 @@ bool QLibraryPrivate::load_sys() } } -#ifdef Q_OS_MAC +#ifdef Q_OS_DARWIN if (!hnd) { QByteArray utf8Bundle = fileName.toUtf8(); QCFType<CFURLRef> bundleUrl = CFURLCreateFromFileSystemRepresentation(NULL, reinterpret_cast<const UInt8*>(utf8Bundle.data()), utf8Bundle.length(), true); @@ -245,7 +234,8 @@ bool QLibraryPrivate::load_sys() locker.relock(); if (!hnd) { - errorString = QLibrary::tr("Cannot load library %1: %2").arg(fileName, qdlerror()); + errorString = QLibrary::tr("Cannot load library %1: %2") + .arg(fileName, QString::fromLocal8Bit(dlerror())); } if (hnd) { qualifiedFileName = attempt; @@ -257,36 +247,27 @@ bool QLibraryPrivate::load_sys() bool QLibraryPrivate::unload_sys() { - if (dlclose(pHnd.loadAcquire())) { -#if defined (Q_OS_QNX) // Workaround until fixed in QNX; fixes crash in - char *error = dlerror(); // QtDeclarative auto test "qqmlenginecleanup" for instance + bool doTryUnload = true; +#ifndef RTLD_NODELETE + if (loadHints() & QLibrary::PreventUnloadHint) + doTryUnload = false; +#endif + if (doTryUnload && dlclose(pHnd.loadAcquire())) { + const char *error = dlerror(); +#if defined (Q_OS_QNX) + // Workaround until fixed in QNX; fixes crash in + // QtDeclarative auto test "qqmlenginecleanup" for instance if (!qstrcmp(error, "Shared objects still referenced")) // On QNX that's only "informative" return true; - errorString = QLibrary::tr("Cannot unload library %1: %2").arg(fileName, - QLatin1StringView(error)); -#else - errorString = QLibrary::tr("Cannot unload library %1: %2").arg(fileName, qdlerror()); #endif + errorString = QLibrary::tr("Cannot unload library %1: %2") + .arg(fileName, QString::fromLocal8Bit(error)); return false; } errorString.clear(); return true; } -#if defined(Q_OS_LINUX) -Q_CORE_EXPORT QFunctionPointer qt_linux_find_symbol_sys(const char *symbol) -{ - return QFunctionPointer(dlsym(RTLD_DEFAULT, symbol)); -} -#endif - -#ifdef Q_OS_MAC -Q_CORE_EXPORT QFunctionPointer qt_mac_resolve_sys(void *handle, const char *symbol) -{ - return QFunctionPointer(dlsym(handle, symbol)); -} -#endif - QFunctionPointer QLibraryPrivate::resolve_sys(const char *symbol) { QFunctionPointer address = QFunctionPointer(dlsym(pHnd.loadAcquire(), symbol)); |