diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-23 13:28:58 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-26 09:56:39 +0000 |
commit | 1a3447a0405831fa5502247f9eaff48afdfe0dea (patch) | |
tree | f40e71aadfda2ddc251ebab18a983a80b5d9b33f /src/qml/compiler/qqmltypecompiler.cpp | |
parent | 78be6b2aa4da54cb41ed60a31abfb7312fb44c9a (diff) |
Clean up manual reference of QQmlTypeData and QQmlPropertyCache
We have a few places in the type loader where we do adventurous manual
reference counting, where getType() returns a raw pointer that has been
addref()'ed and then sometimes somehow we call release() later. Commit
0b394e30bba4f6bb7e6f7dbe5585a2e15aa0f21d is an example of where this can
easily go wrong. As a consequence and also in preparation for future
work on the type loader, this patch starts replacing the manual
reference counting there.
Changing the return type from QQmlTypeData *getType() to a
QQmlRefPointer<> itself is not sufficient though, as the implicit
operator T*() will still allow the caller to store the result as a raw
pointer. Therefore this patch removes the "unsafe" implicit extraction
operator.
As a result of that change, other types that are sometimes stored in
QQmlRefPointer are also affected and their usage needs to be adapted
to QQmlRefPointer usage or manual raw pointer extraction with .data().
Change-Id: I18fd40634047f13196a237f4e6766cbef3bfbea2
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmltypecompiler.cpp')
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 34c2c3ffc9..d1e4041b7e 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -67,7 +67,7 @@ QQmlTypeCompiler::QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *type { } -QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile() +QQmlRefPointer<QV4::CompiledData::CompilationUnit> QQmlTypeCompiler::compile() { // Build property caches and VME meta object data @@ -147,7 +147,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile() document->jsModule.fileName = typeData->urlString(); document->jsModule.finalUrl = typeData->finalUrlString(); QmlIR::JSCodeGen v4CodeGenerator(document->code, &document->jsGenerator, &document->jsModule, &document->jsParserEngine, - document->program, typeNameCache, &document->jsGenerator.stringTable, engine->v8engine()->illegalNames()); + document->program, typeNameCache.data(), &document->jsGenerator.stringTable, engine->v8engine()->illegalNames()); v4CodeGenerator.setUseFastLookups(false); QQmlJSCodeGenerator jsCodeGen(this, &v4CodeGenerator); if (!jsCodeGen.generateCodeForComponents()) @@ -165,7 +165,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile() // The js unit owns the data and will free the qml unit. document->javaScriptCompilationUnit->data = qmlUnit; - QV4::CompiledData::CompilationUnit *compilationUnit = document->javaScriptCompilationUnit; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit = document->javaScriptCompilationUnit; compilationUnit = document->javaScriptCompilationUnit; compilationUnit->typeNameCache = typeNameCache; compilationUnit->resolvedTypes = resolvedTypes; @@ -339,14 +339,12 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio if (!type.isValid()) { if (imports->resolveType(propertyName, &type, nullptr, nullptr, nullptr)) { if (type.isComposite()) { - QQmlTypeData *tdata = enginePrivate->typeLoader.getType(type.sourceUrl()); + QQmlRefPointer<QQmlTypeData> tdata = enginePrivate->typeLoader.getType(type.sourceUrl()); Q_ASSERT(tdata); Q_ASSERT(tdata->isComplete()); auto compilationUnit = tdata->compilationUnit(); type = QQmlMetaType::qmlType(compilationUnit->metaTypeId); - - tdata->release(); } } } |