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 /libshiboken/bindingmanager.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 'libshiboken/bindingmanager.cpp')
-rw-r--r-- | libshiboken/bindingmanager.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index 3610e2907..8c8be3e46 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -153,5 +153,16 @@ void BindingManager::invalidateWrapper(const void* cptr) invalidateWrapper(iter->second); } +void BindingManager::transferOwnershipToCpp(PyBaseWrapper* wrapper) +{ + if (wrapper->parentInfo) + Shiboken::removeParent(wrapper); + + if (PyBaseWrapper_containsCppWrapper(wrapper)) + PyBaseWrapper_setOwnership(wrapper, false); + else + invalidateWrapper(wrapper); +} + } // namespace Shiboken |