forked from qt-creator/qt-creator
Fix some deprecation warnings from QCryptographicHash
QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead") void addData(const char *data, qsizetype length); Change-Id: I144765e6993a9942b372943ccbf5c783fcf9da3d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
#include <QString>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace LanguageUtils {
|
||||
|
||||
// QTC_TEMP
|
||||
@@ -42,8 +40,8 @@ QString ComponentVersion::toString() const
|
||||
|
||||
void ComponentVersion::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
hash.addData(reinterpret_cast<const char *>(&_major), sizeof(_major));
|
||||
hash.addData(reinterpret_cast<const char *>(&_minor), sizeof(_minor));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(&_major), sizeof(_major)));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(&_minor), sizeof(_minor)));
|
||||
}
|
||||
|
||||
} // namespace LanguageUtils
|
||||
|
@@ -6,6 +6,21 @@
|
||||
|
||||
using namespace LanguageUtils;
|
||||
|
||||
static QByteArrayView asData(const void *mem, size_t len)
|
||||
{
|
||||
return QByteArrayView(reinterpret_cast<const char *>(mem), len);
|
||||
}
|
||||
|
||||
static void addData(QCryptographicHash &hash, int x)
|
||||
{
|
||||
hash.addData(asData(&x, sizeof(int)));
|
||||
}
|
||||
|
||||
static void addData(QCryptographicHash &hash, const QString &x)
|
||||
{
|
||||
hash.addData(asData(x.constData(), x.size() * sizeof(QChar)));
|
||||
}
|
||||
|
||||
FakeMetaEnum::FakeMetaEnum()
|
||||
{}
|
||||
|
||||
@@ -39,15 +54,12 @@ bool FakeMetaEnum::hasKey(const QString &key) const
|
||||
|
||||
void FakeMetaEnum::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
int len = m_name.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar));
|
||||
len = m_keys.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, m_name.size());
|
||||
addData(hash, m_name);
|
||||
addData(hash, m_keys.size());
|
||||
for (const QString &key : std::as_const(m_keys)) {
|
||||
len = key.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
|
||||
addData(hash, key.size());
|
||||
addData(hash, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,29 +133,23 @@ void FakeMetaMethod::setRevision(int r)
|
||||
|
||||
void FakeMetaMethod::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
int len = m_name.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_name.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(&m_methodAccess), sizeof(m_methodAccess));
|
||||
hash.addData(reinterpret_cast<const char *>(&m_methodTy), sizeof(m_methodTy));
|
||||
hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision));
|
||||
len = m_paramNames.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, m_name.size());
|
||||
addData(hash, m_name);
|
||||
addData(hash, m_methodAccess);
|
||||
addData(hash, m_methodTy);
|
||||
addData(hash, m_revision);
|
||||
addData(hash, m_paramNames.size());
|
||||
for (const QString &pName : std::as_const(m_paramNames)) {
|
||||
len = pName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(pName.constData()), len * sizeof(QChar));
|
||||
addData(hash, pName.size());
|
||||
addData(hash, pName);
|
||||
}
|
||||
len = m_paramTypes.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, m_paramTypes.size());
|
||||
for (const QString &pType : std::as_const(m_paramTypes)) {
|
||||
len = pType.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(pType.constData()), len * sizeof(QChar));
|
||||
addData(hash, pType.size());
|
||||
addData(hash, pType);
|
||||
}
|
||||
len = m_returnType.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_returnType.constData()), len * sizeof(QChar));
|
||||
addData(hash, m_returnType.size());
|
||||
addData(hash, m_returnType);
|
||||
}
|
||||
|
||||
QString FakeMetaMethod::describe(int baseIndent) const
|
||||
@@ -213,17 +219,15 @@ int FakeMetaProperty::revision() const
|
||||
|
||||
void FakeMetaProperty::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
int len = m_propertyName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_propertyName.constData()), len * sizeof(QChar));
|
||||
hash.addData(reinterpret_cast<const char *>(&m_revision), sizeof(m_revision));
|
||||
addData(hash, m_propertyName.size());
|
||||
addData(hash, m_propertyName);
|
||||
addData(hash, m_revision);
|
||||
int flags = (m_isList ? (1 << 0) : 0)
|
||||
+ (m_isPointer ? (1 << 1) : 0)
|
||||
+ (m_isWritable ? (1 << 2) : 0);
|
||||
hash.addData(reinterpret_cast<const char *>(&flags), sizeof(flags));
|
||||
len = m_type.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_type.constData()), len * sizeof(QChar));
|
||||
addData(hash, flags);
|
||||
addData(hash, m_type.size());
|
||||
addData(hash, m_type);
|
||||
}
|
||||
|
||||
QString FakeMetaProperty::describe(int baseIndent) const
|
||||
@@ -361,34 +365,34 @@ QByteArray FakeMetaObject::calculateFingerprint() const
|
||||
{
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
int len = m_className.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_className.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, m_className);
|
||||
len = m_attachedTypeName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_attachedTypeName.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, m_attachedTypeName);
|
||||
len = m_defaultPropertyName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_defaultPropertyName.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, m_defaultPropertyName);
|
||||
len = m_enumNameToIndex.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, len);
|
||||
{
|
||||
QStringList keys(m_enumNameToIndex.keys());
|
||||
keys.sort();
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
len = key.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, key);
|
||||
int value = m_enumNameToIndex.value(key);
|
||||
hash.addData(reinterpret_cast<const char *>(&value), sizeof(value)); // avoid? this adds order dependency to fingerprint...
|
||||
addData(hash, value);
|
||||
m_enums.at(value).addToHash(hash);
|
||||
}
|
||||
}
|
||||
len = m_exports.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, len);
|
||||
for (const Export &e : std::as_const(m_exports))
|
||||
e.addToHash(hash); // normalize order?
|
||||
len = m_exports.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
addData(hash, len);
|
||||
for (const FakeMetaMethod &m : std::as_const(m_methods))
|
||||
m.addToHash(hash); // normalize order?
|
||||
{
|
||||
@@ -396,16 +400,16 @@ QByteArray FakeMetaObject::calculateFingerprint() const
|
||||
keys.sort();
|
||||
for (const QString &key : std::as_const(keys)) {
|
||||
len = key.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(key.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, key);
|
||||
int value = m_propNameToIdx.value(key);
|
||||
hash.addData(reinterpret_cast<const char *>(&value), sizeof(value)); // avoid? this adds order dependency to fingerprint...
|
||||
addData(hash, value);
|
||||
m_props.at(value).addToHash(hash);
|
||||
}
|
||||
}
|
||||
len = m_superName.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(m_superName.constData()), len * sizeof(QChar));
|
||||
addData(hash, len);
|
||||
addData(hash, m_superName);
|
||||
|
||||
QByteArray res = hash.result();
|
||||
res.append('F');
|
||||
@@ -540,14 +544,12 @@ bool FakeMetaObject::Export::isValid() const
|
||||
|
||||
void FakeMetaObject::Export::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
int len = package.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(package.constData()), len * sizeof(QChar));
|
||||
len = type.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(type.constData()), len * sizeof(QChar));
|
||||
addData(hash, package.size());
|
||||
addData(hash, package);
|
||||
addData(hash, type.size());
|
||||
addData(hash, type);
|
||||
version.addToHash(hash);
|
||||
hash.addData(reinterpret_cast<const char *>(&metaObjectRevision), sizeof(metaObjectRevision));
|
||||
addData(hash, metaObjectRevision);
|
||||
}
|
||||
|
||||
QString FakeMetaObject::Export::describe(int baseIndent) const
|
||||
|
@@ -185,14 +185,14 @@ ImportKey::ImportKey(ImportType::Enum type, const QString &path, int majorVersio
|
||||
|
||||
void ImportKey::addToHash(QCryptographicHash &hash) const
|
||||
{
|
||||
hash.addData(reinterpret_cast<const char *>(&type), sizeof(type));
|
||||
hash.addData(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion));
|
||||
hash.addData(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(&type), sizeof(type)));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion)));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion)));
|
||||
for (const QString &s : splitPath) {
|
||||
hash.addData("/", 1);
|
||||
hash.addData(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size());
|
||||
hash.addData("/");
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size()));
|
||||
}
|
||||
hash.addData("/", 1);
|
||||
hash.addData("/");
|
||||
}
|
||||
|
||||
ImportKey ImportKey::flatKey() const {
|
||||
@@ -547,11 +547,11 @@ QByteArray DependencyInfo::calculateFingerprint(const ImportDependencies &deps)
|
||||
QStringList coreImports = Utils::toList(allCoreImports);
|
||||
coreImports.sort();
|
||||
for (const QString &importId : std::as_const(coreImports)) {
|
||||
hash.addData(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar));
|
||||
hash.addData(QByteArrayView(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar)));
|
||||
QByteArray coreImportFingerprint = deps.coreImport(importId).fingerprint;
|
||||
hash.addData(coreImportFingerprint);
|
||||
}
|
||||
hash.addData("/", 1);
|
||||
hash.addData("/");
|
||||
QList<ImportKey> imports = Utils::toList(allImports);
|
||||
std::sort(imports.begin(), imports.end());
|
||||
for (const ImportKey &k : std::as_const(imports))
|
||||
|
Reference in New Issue
Block a user