From 8bc2c5c6c9a67dfbbd856be34c69c6fe6fd35494 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 24 May 2022 08:10:48 +0200 Subject: shiboken6: Indicate ownership transferences by constructor heuristics Make them easier to spot in case they cause issues. Amend b0f4b96c4b3172578f9ea52fbf1556c553f7b8ce to indicate the kind of heuristics. Task-number: PYSIDE-1939 Change-Id: I01909885ecf2367791de3ec71d471b3dec4d6bef Reviewed-by: Christian Tismer Reviewed-by: Shyamnath Premnadh (cherry picked from commit b40aa266275898d983592d89158e77f9d38dd40b) Reviewed-by: Qt Cherry-pick Bot --- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 26a5340b5..a998aa7a0 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -6782,6 +6782,7 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF { const int numArgs = func->arguments().size(); bool ctorHeuristicEnabled = func->isConstructor() && useCtorHeuristic() && useHeuristicPolicy; + bool heuristicTriggered = false; ArgumentOwner argOwner = getArgumentOwner(func, argIndex); ArgumentOwner::Action action = argOwner.action; @@ -6793,6 +6794,7 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF action = ArgumentOwner::Add; parentIndex = argIndex; childIndex = -1; + heuristicTriggered = true; } } @@ -6825,7 +6827,11 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF ? pythonArgsAt(childIndex - 1) : PYTHON_ARG; } - s << "Shiboken::Object::setParent(" << parentVariable << ", " << childVariable << ");\n"; + s << "// Ownership transferences"; + if (heuristicTriggered) + s << " (constructor heuristics)"; + s << ".\nShiboken::Object::setParent(" << parentVariable << ", " + << childVariable << ");\n"; return true; } @@ -6863,7 +6869,7 @@ void CppGenerator::writeReturnValueHeuristics(TextStream &s, const AbstractMetaF ArgumentOwner argOwner = getArgumentOwner(func, ArgumentOwner::ReturnIndex); if (argOwner.action == ArgumentOwner::Invalid || argOwner.index != ArgumentOwner::ThisIndex) { if (type.isPointerToWrapperType()) { - s << "// Ownership transferences (heuristics).\n" + s << "// Ownership transferences (return value heuristics).\n" << "Shiboken::Object::setParent(self, " << PYTHON_RETURN_VAR << ");\n"; } } -- cgit v1.2.3