diff options
author | Renato Araujo Oliveira Filho <renato.filho@openbossa.org> | 2010-12-14 15:19:37 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:12:49 -0300 |
commit | cf6c0ca50f29c6e606b7c27fbceb8d1d6faf3f14 (patch) | |
tree | 44b60c3183824f448cc22110b7aafff52818339f /libshiboken | |
parent | a0fa4f1d94f86362e8adef0171c9f4dc966fa402 (diff) |
Fix object destruction process to avoid pass a invalid object during the
__del__ function.
Fix bug #505
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r-- | libshiboken/basewrapper.cpp | 27 | ||||
-rw-r--r-- | libshiboken/basewrapper.h | 1 | ||||
-rw-r--r-- | libshiboken/bindingmanager.cpp | 3 |
3 files changed, 19 insertions, 12 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index d9f5d3c07..cb87e56d5 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -814,6 +814,11 @@ PyObject* newObject(SbkObjectType* instanceType, void destroy(SbkObject* self) { + destroy(self, 0); +} + +void destroy(SbkObject* self, void* cppData) +{ // Skip if this is called with NULL pointer this can happen in derived classes if (!self) return; @@ -821,16 +826,9 @@ void destroy(SbkObject* self) // This can be called in c++ side Shiboken::GilState gil; - // We will marks this object as invalid because this function will be called from wrapper destructor - // If The object has ownership and this was destroyed then is necessary invalidate to avoid future used by Python - self->d->validCppObject = false; - // Remove all references attached to this object clearReferences(self); - // Remove from BindinManager - Shiboken::BindingManager::instance().releaseWrapper(self); - // Remove the object from parent control // Verify if this object has parent @@ -848,6 +846,13 @@ void destroy(SbkObject* self) // This can cause the object death Py_DECREF((PyObject*)self); } + + //Python Object is not destroyed yet + if (cppData && Shiboken::BindingManager::instance().hasWrapper(cppData)) { + // Remove from BindinManager + Shiboken::BindingManager::instance().releaseWrapper(self); + } + // After this point the object can be death do not use the self pointer bellow } @@ -876,7 +881,7 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) child->d->hasOwnership = giveOwnershipBack; // Remove parent ref - Py_DECREF(child); + Py_CLEAR(child); } void setParent(PyObject* parent, PyObject* child) @@ -952,11 +957,11 @@ void deallocData(SbkObject* self, bool cleanup) _destroyParentInfo(self, true); clearReferences(self); - - // Remove from BindinManager - Shiboken::BindingManager::instance().releaseWrapper(self); } + // Remove from BindinManager + Shiboken::BindingManager::instance().releaseWrapper(self); + Py_XDECREF(self->ob_dict); delete[] self->d->cptr; self->d->cptr = 0; diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index 46bc641d9..99e354745 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -294,6 +294,7 @@ LIBSHIBOKEN_API void makeValid(SbkObject* self); * Destroy any data in Shiboken structure and c++ pointer if the pyboject has the ownership **/ LIBSHIBOKEN_API void destroy(SbkObject* self); +LIBSHIBOKEN_API void destroy(SbkObject* self, void* cppData); /** * Set user data on type of \p wrapper. diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index 2bcf2debe..68bfe4856 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -148,7 +148,7 @@ BindingManager::~BindingManager() * the BindingManager is being destroyed the interpreter is alredy * shutting down. */ while (!m_d->wrapperMapper.empty()) { - Object::destroy(m_d->wrapperMapper.begin()->second); + Object::destroy(m_d->wrapperMapper.begin()->second, const_cast<void*>(m_d->wrapperMapper.begin()->first)); } assert(m_d->wrapperMapper.size() == 0); delete m_d; @@ -204,6 +204,7 @@ void BindingManager::releaseWrapper(SbkObject* sbkObj) } } } + sbkObj->d->validCppObject = false; } SbkObject* BindingManager::retrieveWrapper(const void* cptr) |