path: root/libshiboken/bindingmanager.h
diff options
authorMarcelo Lira <>2009-11-29 01:26:56 -0300
committerMarcelo Lira <>2009-11-30 13:50:08 -0300
commit78bf7bca1fe92052ae7b64827ae81bbe25bd8c3d (patch)
tree19bd083348c0ad3aaa9c479a2fcb239004be26b0 /libshiboken/bindingmanager.h
parent697f24dfa96b15a46e9e5afa79e102e9a5100d73 (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 <>
Diffstat (limited to 'libshiboken/bindingmanager.h')
1 files changed, 8 insertions, 0 deletions
diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h
index fe5767d3..602066f9 100644
--- a/libshiboken/bindingmanager.h
+++ b/libshiboken/bindingmanager.h
@@ -64,6 +64,14 @@ public:
/// Convenience method to invalidate the Python wrapper for a C++ wrapped object. Do nothing if C++ pointer has no Python wrapper.
void invalidateWrapper(const void* cptr);
+ /// Transfers the ownership of a Python wrapper to C++.
+ void transferOwnershipToCpp(PyBaseWrapper* wrapper);
+ /// Convenience method to call transferOwnershipToCpp with a properly cast PyBaseWrapper.
+ inline void transferOwnershipToCpp(PyObject* wrapper)
+ {
+ transferOwnershipToCpp(reinterpret_cast<PyBaseWrapper*>(wrapper));
+ }
// disable copy