summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-05-13 11:07:39 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-05-17 10:34:31 +0000
commitae1c2375f596258c878933adc46a19a541a43a6c (patch)
treee5559a91634354657c270fed2ae59ca92f1552cc /tools
parentf228af06c2c712302ee1dcdaf761cd24504b473e (diff)
Add abstraction for temporarily setting StaticData when saving
The StaticData flag needs to be saved to disk, but removed again afterwards so that we can free() the malloc'd data. This also allows us to avoid copying all the data into a byte array before saving. Change-Id: I96513f8d98acf0ea0b4514d96376b487e8444917 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp36
1 files changed, 14 insertions, 22 deletions
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index 63be5c5ec4..7b4135e1f8 100644
--- a/tools/qmlcachegen/qmlcachegen.cpp
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -169,7 +169,7 @@ static bool checkArgumentsObjectUseInSignalHandlers(const QmlIR::Document &doc,
return true;
}
-using SaveFunction = std::function<bool (const QV4::CompiledData::CompilationUnit &, QString *)>;
+using SaveFunction = std::function<bool(const QV4::CompiledData::SaveableUnitPointer &, QString *)>;
static bool compileQmlFile(const QString &inputFileName, SaveFunction saveFunction, Error *error)
{
@@ -229,11 +229,13 @@ static bool compileQmlFile(const QString &inputFileName, SaveFunction saveFuncti
QmlIR::QmlUnitGenerator generator;
irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit(/*generate unit*/false);
generator.generate(irDocument);
- QV4::CompiledData::Unit *unit = const_cast<QV4::CompiledData::Unit*>(irDocument.javaScriptCompilationUnit.data);
- unit->flags |= QV4::CompiledData::Unit::StaticData;
- unit->flags |= QV4::CompiledData::Unit::PendingTypeCompilation;
- if (!saveFunction(irDocument.javaScriptCompilationUnit, &error->message))
+ const quint32 saveFlags
+ = QV4::CompiledData::Unit::StaticData
+ | QV4::CompiledData::Unit::PendingTypeCompilation;
+ QV4::CompiledData::SaveableUnitPointer saveable(&irDocument.javaScriptCompilationUnit,
+ saveFlags);
+ if (!saveFunction(saveable, &error->message))
return false;
}
return true;
@@ -321,17 +323,15 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile
irDocument.javaScriptCompilationUnit = v4CodeGen.generateCompilationUnit(/*generate unit*/false);
QmlIR::QmlUnitGenerator generator;
generator.generate(irDocument);
- QV4::CompiledData::Unit *unitData = const_cast<QV4::CompiledData::Unit*>(irDocument.javaScriptCompilationUnit.data);
- unitData->flags |= QV4::CompiledData::Unit::StaticData;
unit = std::move(irDocument.javaScriptCompilationUnit);
}
}
- return saveFunction(unit, &error->message);
+ return saveFunction(QV4::CompiledData::SaveableUnitPointer(&unit), &error->message);
}
static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFileName,
- const QV4::CompiledData::CompilationUnit &unit,
+ const QV4::CompiledData::SaveableUnitPointer &unit,
QString *errorString)
{
QSaveFile f(outputFileName);
@@ -368,17 +368,9 @@ static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFil
QByteArray hexifiedData;
{
- QByteArray modifiedUnit;
- modifiedUnit.resize(unit.data->unitSize);
- memcpy(modifiedUnit.data(), unit.data, unit.data->unitSize);
- const char *dataPtr = modifiedUnit.data();
- QV4::CompiledData::Unit *unitPtr;
- memcpy(&unitPtr, &dataPtr, sizeof(unitPtr));
- unitPtr->flags |= QV4::CompiledData::Unit::StaticData;
-
QTextStream stream(&hexifiedData);
- const uchar *begin = reinterpret_cast<const uchar *>(modifiedUnit.constData());
- const uchar *end = begin + unit.data->unitSize;
+ const uchar *begin = unit.data<uchar>();
+ const uchar *end = begin + unit.size();
stream << hex;
int col = 0;
for (const uchar *data = begin; data < end; ++data, ++col) {
@@ -527,15 +519,15 @@ int main(int argc, char **argv)
inputFileUrl = QStringLiteral("qrc://") + inputResourcePath;
saveFunction = [inputResourcePath, outputFileName](
- const QV4::CompiledData::CompilationUnit &unit,
+ const QV4::CompiledData::SaveableUnitPointer &unit,
QString *errorString) {
return saveUnitAsCpp(inputResourcePath, outputFileName, unit, errorString);
};
} else {
- saveFunction = [outputFileName](const QV4::CompiledData::CompilationUnit &unit,
+ saveFunction = [outputFileName](const QV4::CompiledData::SaveableUnitPointer &unit,
QString *errorString) {
- return unit.saveToDisk(outputFileName, errorString);
+ return unit->saveToDisk(outputFileName, errorString);
};
}