diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-14 13:40:04 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-24 11:13:08 +0200 |
| commit | e9de399dda27e4f8e8a2763b574c9fafaf2a5469 (patch) | |
| tree | 79889588c2f887ef98f96df753678b04a52f8602 /src/qml/compiler/qv4compiler.cpp | |
| parent | 8f62f07bbc59ee3d97cd3d7d54b60b47c979a3cc (diff) | |
Move unit checksum generation into qv4compiler
Only the compiler ever has to do this, and we want the structure
definition for the compiled data as a common header.
Change-Id: Ie5c6d6c9dcd180dea79f54d0f7d10f3fc50fa20e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
| -rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 592f5731ca..b378c294b7 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -126,6 +126,25 @@ void QV4::Compiler::StringTableGenerator::serialize(CompiledData::Unit *unit) } } +void QV4::Compiler::JSUnitGenerator::generateUnitChecksum(QV4::CompiledData::Unit *unit) +{ +#ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 + QCryptographicHash hash(QCryptographicHash::Md5); + + const int checksummableDataOffset + = offsetof(QV4::CompiledData::Unit, md5Checksum) + sizeof(unit->md5Checksum); + + const char *dataPtr = reinterpret_cast<const char *>(unit) + checksummableDataOffset; + hash.addData(dataPtr, unit->unitSize - checksummableDataOffset); + + QByteArray checksum = hash.result(); + Q_ASSERT(checksum.size() == sizeof(unit->md5Checksum)); + memcpy(unit->md5Checksum, checksum.constData(), sizeof(unit->md5Checksum)); +#else + memset(unit->md5Checksum, 0, sizeof(unit->md5Checksum)); +#endif +} + QV4::Compiler::JSUnitGenerator::JSUnitGenerator(QV4::Compiler::Module *module) : module(module) { @@ -392,7 +411,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorO if (option == GenerateWithStringTable) stringTable.serialize(unit); - unit->generateChecksum(); + generateUnitChecksum(unit); return unit; } |
