56 # include <private/qcore_mac_p.h>
58 #include <private/qcoreapplication_p.h>
59 #include <private/qloggingregistry_p.h>
60 #include <private/qsystemerror_p.h>
67 #include <qtcore_tracepoints_p.h>
74 static constexpr
bool PluginMustMatchQtDebug =
76 #if defined(Q_CC_MINGW)
82 static constexpr
bool QtBuildIsDebug =
false;
84 static constexpr
bool QtBuildIsDebug =
true;
206 #if defined(Q_OF_ELF)
208 #elif defined(Q_OF_MACH_O)
210 #elif defined(Q_OS_WIN)
213 static constexpr
auto matcher = [] {
217 constexpr
auto &
pattern =
"QTMETADATA !";
220 static_assert(
pattern == magic);
248 qCWarning(qt_lcDebugPlugins,
"%ls: cannot open: %ls", qUtf16Printable(
library),
255 constexpr
qint64 MaxMemoryMapSize =
259 const char *filedata =
reinterpret_cast<char *
>(
file.
map(0, fdlen));
262 if (filedata ==
nullptr) {
265 qCWarning(qt_lcDebugPlugins,
"%ls: failed to map to memory: %ls",
271 if (filedata ==
nullptr) {
276 filedata =
data.constData();
286 qCWarning(qt_lcDebugPlugins,
"Found invalid metadata in lib %ls: %ls",
289 qCDebug(qt_lcDebugPlugins,
"Found metadata in lib %ls, metadata=\n%s\n",
295 qCDebug(qt_lcDebugPlugins,
"Failed to find metadata in lib %ls: %ls",
306 #ifdef __COVERAGESCANNER__
323 qDebug(
"coverage data for %ls registered",
324 qUtf16Printable(libPrivate->
fileName));
326 qWarning(
"could not register %ls: error %d; coverage data may be incomplete",
327 qUtf16Printable(libPrivate->
fileName),
355 static bool qt_library_data_once;
359 qt_library_data =
nullptr;
370 for (;
it !=
data->libraryMap.end(); ++
it) {
381 #elif defined(Q_OS_DARWIN)
391 it.value() =
nullptr;
396 if (lcDebugLibrary().isDebugEnabled()) {
400 <<
"On QtCore unload," << lib->
fileName <<
"was leaked, with"
408 static void qlibraryCleanup()
412 Q_DESTRUCTOR_FUNCTION(qlibraryCleanup)
417 if (
Q_UNLIKELY(!qt_library_data_once && !qt_library_data)) {
420 qt_library_data_once =
true;
422 return qt_library_data;
426 QLibrary::LoadHints loadHints)
436 lib->mergeLoadHints(loadHints);
445 lib->libraryRefCount.
ref();
454 if (lib->libraryRefCount.
deref()) {
470 QLibraryPrivate::QLibraryPrivate(
const QString &canonicalFileName,
const QString &
version, QLibrary::LoadHints loadHints)
471 :
fileName(canonicalFileName), fullVersion(
version), pluginState(MightBeAPlugin)
473 loadHintsInt.storeRelaxed(loadHints.toInt());
474 if (canonicalFileName.
isEmpty())
475 errorString =
QLibrary::tr(
"The shared library was not found.");
479 QLibrary::LoadHints loadHints)
484 QLibraryPrivate::~QLibraryPrivate()
488 void QLibraryPrivate::mergeLoadHints(QLibrary::LoadHints lh)
501 return resolve_sys(symbol);
541 libraryUnloadCount.
ref();
549 bool ret = load_sys();
552 << (
ret ?
"loaded library" : qUtf8Printable(
u"cannot load: " +
errorString));
556 libraryUnloadCount.
ref();
557 libraryRefCount.
ref();
558 installCoverageTool(
this);
578 libraryRefCount.
deref();
596 libraryUnloadCount.
ref();
599 if (pluginState == IsNotAPlugin)
607 pluginState = IsNotAPlugin;
628 #if defined(Q_OS_WIN)
631 # if defined(Q_OS_DARWIN)
642 # if defined(Q_OS_HPUX)
652 # elif defined(Q_OS_AIX)
655 # elif defined(Q_OS_DARWIN)
658 # elif defined(Q_OS_UNIX)
674 auto suffixes =
qTokenize(completeSuffix,
u'.');
675 auto it = suffixes.begin();
676 const auto end = suffixes.end();
681 if (isValidSuffix(*
it++))
696 QFunctionPointer pfn = priv->
resolve(
"qt_plugin_query_metadata_v2");
699 #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
700 }
else if ((pfn = priv->
resolve(
"qt_plugin_query_metadata"))) {
706 auto data =
reinterpret_cast<const char *
>(metaData.
data);
712 return error(
QLibrary::tr(
"entrypoint to query the plugin meta data not found"));
726 if (pluginState == MightBeAPlugin)
729 return pluginState == IsAPlugin;
736 if (pluginState != MightBeAPlugin)
739 bool success =
false;
741 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
750 pluginState = IsNotAPlugin;
757 success = findPatternUnloaded(
fileName,
this);
771 pluginState = IsNotAPlugin;
775 pluginState = IsNotAPlugin;
779 if ((qt_version & 0x00ff00) > (
QT_VERSION & 0x00ff00) || (qt_version & 0xff0000) != (
QT_VERSION & 0xff0000)) {
781 " Plugin uses incompatible Qt library (%d.%d.%d) [%s]",
783 (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff,
784 debug ?
"debug" :
"release");
791 }
else if (PluginMustMatchQtDebug &&
debug != QtBuildIsDebug) {
794 " (Cannot mix debug and release libraries.)").arg(
fileName);
796 pluginState = IsAPlugin;
814 if (d.
tag() == Loaded)
838 if (d.
tag() == Loaded) {
946 QLibrary::LoadHints lh;
975 QLibrary::LoadHints lh;
995 QLibrary::LoadHints lh;
1047 return library.resolve(symbol);
1067 return library.resolve(symbol);
1088 return library.resolve(symbol);
1153 return d ? d->
loadHints() : QLibrary::LoadHints();
1160 return debug_env != 0;
1165 #include "moc_qlibrary.cpp"
small capitals from c petite p scientific f u
void storeRelaxed(T newValue) noexcept
T loadRelaxed() const noexcept
Type loadAcquire() const noexcept
Type loadRelaxed() const noexcept
void storeRelaxed(Type newValue) noexcept
void storeRelease(Type newValue) noexcept
The QByteArray class provides an array of bytes.
const char * constData() const noexcept
qint64 toInteger(qint64 defaultValue=0) const
bool toBool(bool defaultValue=false) const
uchar * map(qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
The QFile class provides an interface for reading from and writing to files.
bool open(OpenMode flags) override
static QByteArray encodeName(const QString &fileName)
qint64 size() const override
The QFileInfo class provides system-independent file information.
QString completeSuffix() const
QString errorString() const
qint64 read(char *data, qint64 maxlen)
The QJsonDocument class provides a way to read and write JSON documents.
QByteArray toJson(JsonFormat format=Indented) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QLibrary class loads shared libraries at runtime.
LoadHints loadHints
Give the load() function some hints on how it should behave.
QString fileName
the file name of the library
static bool isLibrary(const QString &fileName)
void setFileNameAndVersion(const QString &fileName, int verNum)
void setFileName(const QString &fileName)
void setLoadHints(LoadHints hints)
QLibrary(QObject *parent=nullptr)
QFunctionPointer resolve(const char *symbol)
QString errorString() const
bool unload(UnloadFlag flag=UnloadSys)
QString qualifiedFileName
QtPluginInstanceFunction loadPlugin()
QAtomicPointer< std::remove_pointer< Handle >::type > pHnd
void setLoadHints(QLibrary::LoadHints lh)
QAtomicPointer< std::remove_pointer< QtPluginInstanceFunction >::type > instanceFactory
QPluginParsedMetaData metaData
QFunctionPointer resolve(const char *)
QObject * pluginInstance()
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString(), QLibrary::LoadHints loadHints={ })
QLibrary::LoadHints loadHints() const
static void releaseLibrary(QLibraryPrivate *lib)
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version, QLibrary::LoadHints loadHints)
The QMutex class provides access serialization between threads.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
The QObject class is the base class of all Qt objects.
static constexpr OSType currentType()
template< size_t N > QStaticByteArrayMatcher qMakeStaticByteArrayMatcher(const char(&pattern)[N])
The QString class provides a Unicode character string.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QByteArray toLocal8Bit() const &
static QString number(int, int base=10)
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
auto it unsigned count const
constexpr struct q20::ranges::@310 all_of
#define QT_CONFIG(feature)
bool qt_debug_component()
qsizetype QString * errMsg
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QObject *(* QtPluginInstanceFunction)()
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
int QT_PREPEND_NAMESPACE(QSharedMemoryPrivate)
constexpr auto qTokenize(Haystack &&h, Needle &&n, Flags...flags) noexcept(QtPrivate::Tok::is_nothrow_constructible_from< Haystack, Needle >::value) -> decltype(QtPrivate::Tok::TokenizerResult< Haystack, Needle >{std::forward< Haystack >(h), std::forward< Needle >(n), flags...})
QItemEditorFactory * factory
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
QDomElement find(const QString &tagName, const QDomElement &e)