diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-07-01 10:20:21 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-09-01 15:19:46 +0000 |
commit | 7bd79b3cffbbbece23867c5e111a3dd2ebcad016 (patch) | |
tree | 9563078fb7aeae16b1f4321bfcbc18c969f9f6ed /src/corelib | |
parent | d9766ddc3d525cf08acec4c3483e61d86c9899a8 (diff) |
Plugins: Save some architectural requirement flags
...not just the debug flag. The information is saved outside of the CBOR
map for two reasons:
1) removing the hack that depended on how QCborStreamWriter and
TinyCBOR internally work, allowing for the extra parameter to be
written directly. We wouldn't be able to use that hack anyway and would
have needed a further, uglier hack to encode a byte whose value we
don't know.
2) outside the map, this information can be parsed more quickly and
then we can discard any plugins we shouldn't actually load.
Since we're doing this for a flag, I decided to move the Qt version
there too for reason #2.
Change-Id: I61ecce6b1324410bbab4fffd153d4e5fc696d19e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 22 | ||||
-rw-r--r-- | src/corelib/plugin/qplugin.h | 15 | ||||
-rw-r--r-- | src/corelib/plugin/qplugin_p.h | 4 |
3 files changed, 35 insertions, 6 deletions
diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index 9f877ccda8..35c64180d4 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -69,11 +69,17 @@ static inline int metaDataSignatureLength() static QJsonDocument jsonFromCborMetaData(const char *raw, qsizetype size, QString *errMsg) { - if (Q_UNLIKELY(raw[-1] != '!')) { - *errMsg = QStringLiteral("Invalid metadata signature"); + // extract the keys not stored in CBOR + int qt_metadataVersion = quint8(raw[0]); + int qt_version = qFromBigEndian<quint16>(raw + 1); + int qt_archRequirements = quint8(raw[3]); + if (Q_UNLIKELY(raw[-1] != '!' || qt_metadataVersion != 0)) { + *errMsg = QStringLiteral("Invalid metadata version"); return QJsonDocument(); } + raw += 4; + size -= 4; QByteArray ba = QByteArray::fromRawData(raw, int(size)); QCborParserError err; QCborValue metadata = QCborValue::fromCbor(ba, &err); @@ -88,8 +94,12 @@ static QJsonDocument jsonFromCborMetaData(const char *raw, qsizetype size, QStri return QJsonDocument(); } - // convert the top-level map integer keys QJsonObject o; + o.insert(QLatin1String("version"), qt_version << 8); + o.insert(QLatin1String("debug"), bool(qt_archRequirements & 1)); + o.insert(QLatin1String("archreq"), qt_archRequirements); + + // convert the top-level map integer keys for (auto it : metadata.toMap()) { QString key; if (it.first.isInteger()) { @@ -98,6 +108,12 @@ static QJsonDocument jsonFromCborMetaData(const char *raw, qsizetype size, QStri case int(IntKey): key = QStringLiteral(StringKey); break; QT_PLUGIN_FOREACH_METADATA(CONVERT_TO_STRING) #undef CONVERT_TO_STRING + + case int(QtPluginMetaDataKeys::Requirements): + // special case: recreate the debug key + o.insert(QLatin1String("debug"), bool(it.second.toInteger() & 1)); + key = QStringLiteral("archreq"); + break; } } else { key = it.first.toString(); diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h index 9922026f97..5aca22497a 100644 --- a/src/corelib/plugin/qplugin.h +++ b/src/corelib/plugin/qplugin.h @@ -55,6 +55,21 @@ QT_BEGIN_NAMESPACE # endif #endif +inline constexpr unsigned char qPluginArchRequirements() +{ + return 0 +#ifndef QT_NO_DEBUG + | 1 +#endif +#ifdef __AVX2__ + | 2 +# ifdef __AVX512F__ + | 4 +# endif +#endif + ; +} + typedef QObject *(*QtPluginInstanceFunction)(); typedef const char *(*QtPluginMetaDataFunction)(); diff --git a/src/corelib/plugin/qplugin_p.h b/src/corelib/plugin/qplugin_p.h index 99ee16a3e8..717129268b 100644 --- a/src/corelib/plugin/qplugin_p.h +++ b/src/corelib/plugin/qplugin_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE enum class QtPluginMetaDataKeys { QtVersion, - Debug, + Requirements, IID, ClassName, MetaData @@ -66,8 +66,6 @@ enum class QtPluginMetaDataKeys { // F(IntKey, StringKey, Description) // Keep this list sorted in the order moc should output. #define QT_PLUGIN_FOREACH_METADATA(F) \ - F(QtPluginMetaDataKeys::QtVersion, "version", "Qt version built against") \ - F(QtPluginMetaDataKeys::Debug, "debug", "Whether it is a debug build") \ F(QtPluginMetaDataKeys::IID, "IID", "Plugin's Interface ID") \ F(QtPluginMetaDataKeys::ClassName, "className", "Plugin class name") \ F(QtPluginMetaDataKeys::MetaData, "MetaData", "Other meta data") |