From e78bd2efe4063d522effaaf6a6dc737fe8da8b79 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Wed, 2 Feb 2011 19:04:16 -0200 Subject: Don't write return heuristic when there's a parent tag with the returned object involved. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Renato Araújo Luciano Wolf --- generator/cppgenerator.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'generator') diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 84a61f160..3d33fae13 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -2198,6 +2198,10 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } + // If there's already a setParent(return, me), don't use the return heuristic! + if (func->argumentOwner(func->ownerClass(), -1).index == 0) + hasReturnPolicy = true; + if (!ownership_mods.isEmpty()) { s << endl << INDENT << "// Ownership transferences." << endl; foreach (ArgumentModification arg_mod, ownership_mods) { @@ -2208,7 +2212,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f break; } - if (arg_mod.index == 0) + if (arg_mod.index == 0 || arg_mod.owner.index == 0) hasReturnPolicy = true; // The default ownership does nothing. This is useful to avoid automatic heuristically @@ -3870,13 +3874,9 @@ bool CppGenerator::writeParentChildManagement(QTextStream& s, const AbstractMeta childVariable = usePyArgs ? "pyargs["+QString::number(childIndex-1)+"]" : "arg"; s << INDENT << "Shiboken::Object::setParent(" << parentVariable << ", " << childVariable << ");\n"; - return true; } - if (argIndex == 0 && useHeuristicPolicy) - writeReturnValueHeuristics(s, func); - return false; } @@ -3888,7 +3888,10 @@ void CppGenerator::writeParentChildManagement(QTextStream& s, const AbstractMeta // 0 = self // 1..n = func. args. for (int i = -1; i <= numArgs; ++i) - writeParentChildManagement(s, func, i, i == 0 ? useHeuristicForReturn : true); + writeParentChildManagement(s, func, i, useHeuristicForReturn); + + if (useHeuristicForReturn) + writeReturnValueHeuristics(s, func); } void CppGenerator::writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func, const QString& self) -- cgit v1.2.3