20# include <private/qcore_mac_p.h>
22#include <private/qcoreapplication_p.h>
23#include <private/qloggingregistry_p.h>
24#include <private/qsystemerror_p.h>
31#include <qtcore_tracepoints_p.h>
45#if defined(Q_CC_MINGW)
177#elif defined(Q_OF_MACH_O)
179#elif defined(Q_OS_WIN)
182# warning "Qt does not know how to efficiently parse your platform's binary format; using slow fall-back."
184 static constexpr auto matcher = [] {
188 constexpr auto &
pattern =
"QTMETADATA !";
226 constexpr qint64 MaxMemoryMapSize =
230 const char *filedata =
reinterpret_cast<char *
>(
file.
map(0, fdlen));
233 if (filedata ==
nullptr) {
236 qCWarning(qt_lcDebugPlugins,
"%ls: failed to map to memory: %ls",
242 if (filedata ==
nullptr) {
247 filedata =
data.constData();
255#if defined(Q_OF_MACH_O)
261 qCDebug(qt_lcDebugPlugins,
"Found invalid metadata in lib %ls: %ls",
264 qCDebug(qt_lcDebugPlugins,
"Found metadata in lib %ls, metadata=\n%s\n",
270 qCDebug(qt_lcDebugPlugins,
"Failed to find metadata in lib %ls: %ls",
274 lib->
errorString = QLibrary::tr(
"Failed to extract plugin meta data from '%1': %2")
281#ifdef __COVERAGESCANNER__
298 qDebug(
"coverage data for %ls registered",
301 qWarning(
"could not register %ls: error %d; coverage data may be incomplete",
351#if defined(Q_OS_DARWIN)
361 it.value() =
nullptr;
366 if (lcDebugLibrary().isDebugEnabled()) {
370 <<
"On QtCore unload," << lib->fileName <<
"was leaked, with"
371 << lib->libraryRefCount.loadRelaxed() <<
"users";
396 QLibrary::LoadHints loadHints)
406 lib =
data->libraryMap.value(mapName);
408 lib->mergeLoadHints(loadHints);
415 data->libraryMap.insert(mapName, lib);
417 lib->libraryRefCount.
ref();
426 if (lib->libraryRefCount.
deref()) {
436 return it.value() == lib;
438 Q_ASSERT_X(
n,
"~QLibrary",
"Did not find this library in the library map");
444QLibraryPrivate::QLibraryPrivate(
const QString &canonicalFileName,
const QString &version, QLibrary::LoadHints loadHints)
445 :
fileName(canonicalFileName), fullVersion(version), pluginState(MightBeAPlugin)
447 loadHintsInt.storeRelaxed(loadHints.toInt());
448 if (canonicalFileName.
isEmpty())
449 errorString = QLibrary::tr(
"The shared library was not found.");
453 QLibrary::LoadHints loadHints)
458QLibraryPrivate::~QLibraryPrivate()
462void QLibraryPrivate::mergeLoadHints(QLibrary::LoadHints lh)
475 return resolve_sys(symbol);
522 libraryUnloadCount.
ref();
530 bool ret = load_sys();
537 libraryUnloadCount.
ref();
538 libraryRefCount.
ref();
559 libraryRefCount.
deref();
577 libraryUnloadCount.
ref();
580 if (pluginState == IsNotAPlugin)
588 pluginState = IsNotAPlugin;
612# if defined(Q_OS_DARWIN)
623# if defined(Q_OS_HPUX)
633# elif defined(Q_OS_AIX)
636# elif defined(Q_OS_DARWIN)
639# elif defined(Q_OS_UNIX)
645 return std::find(std::begin(candidates), std::end(candidates),
s) != std::end(candidates);
655 auto suffixes =
qTokenize(completeSuffix, u
'.');
657 const auto end = suffixes.end();
662 if (isValidSuffix(*
it++))
672 *
errMsg = QLibrary::tr(
"'%1' is not a Qt plugin (%2)").
arg(
priv->fileName, std::move(explanation));
677 QFunctionPointer pfn =
priv->resolve(
"qt_plugin_query_metadata_v2");
680#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
681 }
else if ((pfn =
priv->resolve(
"qt_plugin_query_metadata"))) {
684 return error(QLibrary::tr(
"metadata too small"));
687 auto data =
reinterpret_cast<const char *
>(metaData.
data);
693 return error(QLibrary::tr(
"entrypoint to query the plugin meta data not found"));
697 return error(QLibrary::tr(
"metadata too small"));
699 if (
priv->metaData.parse(metaData))
707 if (pluginState == MightBeAPlugin)
710 return pluginState == IsAPlugin;
717 if (pluginState != MightBeAPlugin)
720 bool success =
false;
722#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
730 errorString = QLibrary::tr(
"The shared library was not found.");
731 pluginState = IsNotAPlugin;
739#if defined(Q_OF_MACH_O)
744 qCDebug(qt_lcDebugPlugins,
"Library is encrypted. Doing prospective load before parsing metadata");
752 success =
result.length != 0;
763 errorString = QLibrary::tr(
"The shared library was not found.");
767 pluginState = IsNotAPlugin;
771 pluginState = IsNotAPlugin;
775 if ((qt_version & 0x00ff00) > (
QT_VERSION & 0x00ff00) || (qt_version & 0xff0000) != (
QT_VERSION & 0xff0000)) {
776 qCDebug(qt_lcDebugPlugins,
"In %s:\n"
777 " Plugin uses incompatible Qt library (%d.%d.%d) [%s]",
779 (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff,
780 debug ?
"debug" :
"release");
781 errorString = QLibrary::tr(
"The plugin '%1' uses incompatible Qt library. (%2.%3.%4) [%5]")
786 debug ?
"debug"_L1 :
"release"_L1);
789 errorString = QLibrary::tr(
"The plugin '%1' uses incompatible Qt library."
790 " (Cannot mix debug and release libraries.)").
arg(
fileName);
792 pluginState = IsAPlugin;
810 if (d.
tag() == Loaded)
836 if (d.
tag() == Loaded) {
854 return d.
tag() == Loaded;
985 QLibrary::LoadHints lh;
1037 return library.
resolve(symbol);
1057 return library.
resolve(symbol);
1078 return library.
resolve(symbol);
1147 return d ? d->
loadHints() : QLibrary::LoadHints();
1154 return debug_env != 0;
1159#include "moc_qlibrary.cpp"
T fetchAndOrRelaxed(T valueToAdd) noexcept
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
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
qint64 toInteger(qint64 defaultValue=0) const
Returns the integer value stored in this QCborValue, if it is of the integer type.
bool toBool(bool defaultValue=false) const
Returns the boolean value stored in this QCborValue, if it is of a boolean type.
uchar * map(qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
Maps size bytes of the file into memory starting at offset.
\inmodule QtCore \reentrant
QString completeSuffix() const
Returns the complete suffix (extension) of the file.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
qint64 size() const override
\reimp
QString errorString() const
Returns a human-readable description of the last device error that occurred.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
\inmodule QtCore\reentrant
QByteArray toJson(JsonFormat format=Indented) 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)
\inmodule QtCore \reentrant
bool load()
Loads the library and returns true if the library was loaded successfully; otherwise returns false.
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)
Returns true if fileName has a valid suffix for a loadable library; otherwise returns false.
void setFileNameAndVersion(const QString &fileName, int verNum)
Sets the fileName property and major version number to fileName and versionNumber respectively.
void setFileName(const QString &fileName)
bool isLoaded() const
Returns true if load() succeeded; otherwise returns false.
bool unload()
Unloads the library and returns true if the library could be unloaded; otherwise returns false.
void setLoadHints(LoadHints hints)
QLibrary(QObject *parent=nullptr)
Constructs a library with the given parent.
QFunctionPointer resolve(const char *symbol)
Returns the address of the exported symbol symbol.
~QLibrary()
Destroys the QLibrary object.
QString errorString() const
void unlock() noexcept
Unlocks this mutex locker.
void relock() noexcept
Relocks an unlocked mutex locker.
static constexpr OSType currentType()
Returns the current OS type without constructing a QOperatingSystemVersion instance.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QByteArray toLocal8Bit() const &
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr struct q20::ranges::@5 all_of
qsizetype erase_if(QByteArray &ba, Predicate pred)
constexpr QStaticByteArrayMatcher< N > qMakeStaticByteArrayMatcher(const char(&pattern)[N]) noexcept
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
static void installCoverageTool(QLibraryPrivate *libPrivate)
static Q_CONSTINIT bool qt_library_data_once
bool qt_debug_component()
qsizetype QString * errMsg
static constexpr bool QtBuildIsDebug
static bool qt_get_metadata(QLibraryPrivate *priv, QString *errMsg)
static Q_CONSTINIT QLibraryStore * qt_library_data
static QLibraryScanResult findPatternUnloaded(const QString &library, QLibraryPrivate *lib)
static Q_CONSTINIT QBasicMutex qt_library_mutex
static constexpr bool PluginMustMatchQtDebug
static void qlibraryCleanup()
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName)
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMin(const T &a, const T &b)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QObject *(* QtPluginInstanceFunction)()
#define Q_ASSERT_X(cond, x, msg)
#define qUtf8Printable(string)
#define qUtf16Printable(string)
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...})
#define QT_CONFIG(feature)
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
#define Q_TRACE_POINT(provider, tracepoint,...)
static const uchar magic[MagicLength]
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId
static const auto matcher
[0]
QItemEditorFactory * factory
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent