diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-29 01:26:56 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-30 13:50:08 -0300 |
commit | 78bf7bca1fe92052ae7b64827ae81bbe25bd8c3d (patch) | |
tree | 19bd083348c0ad3aaa9c479a2fcb239004be26b0 /cppgenerator.cpp | |
parent | 697f24dfa96b15a46e9e5afa79e102e9a5100d73 (diff) |
Added method to take care of the details of ownership transfer to C++.
Simple ownership transference, i.e. without parenting, is now performed
by the new BindingManager::transferOwnershipToCpp method. It remove the
parent of the transfered object and proceeds transfer or invalidation
if needed. The generated code for simple ownership transfer from Python
to C++ now reflects this change.
Fixed the method BlackBox::keepObjectType that steals an ObjectType
ownership to C++ to remove it from its parent also. The BlackBox
class does not take care of the stolen object as a proper parent
would, but its destructor deletes the object, so the "unparenting"
is needed to avoid freeing the same memory twice.
Created an unit test that adds children to a parent ObjectType and then
steal the children to C++ with BlackBox.keepObjectType.
Reviewed by Hugo Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'cppgenerator.cpp')
-rw-r--r-- | cppgenerator.cpp | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index 625d48b78..5847b5567 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1183,22 +1183,13 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } s << INDENT; - if (arg_mod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::TargetLangOwnership) { - s << "PyBaseWrapper_setOwnership(" << pyArgName << ", true);" << endl; - } else if (wrappedClass->hasVirtualDestructor()) { - s << "if (PyBaseWrapper_containsCppWrapper(" << pyArgName << "))" << endl; - { - Indentation indent(INDENT); - s << INDENT << "PyBaseWrapper_setOwnership(" << pyArgName << ", false);" << endl; - } - s << INDENT << "else" << endl; - { - Indentation indent(INDENT); - s << INDENT << "BindingManager::instance().invalidateWrapper(" << pyArgName << ");" << endl; - } - } else { - s << "BindingManager::instance().invalidateWrapper(" << pyArgName << ");" << endl; - } + if (arg_mod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::TargetLangOwnership) + s << "PyBaseWrapper_setOwnership(" << pyArgName << ", true"; + else if (wrappedClass->hasVirtualDestructor()) + s << "BindingManager::instance().transferOwnershipToCpp(" << pyArgName; + else + s << "BindingManager::instance().invalidateWrapper(" << pyArgName; + s << ");" << endl; } } } |