diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-10-17 17:15:37 -0200 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:18:23 -0300 |
commit | faacc898e03e239d6f76ab18ae4cdb4805525b28 (patch) | |
tree | cb0a54fc0be6df7b4ca920c45e6d25af2d20a621 | |
parent | ba1e6dfea28a472e4137984581ac96c7486c89b7 (diff) |
Don't delete parentInfo when it seens to be useless to avoid crash on garbage collector.
-rw-r--r-- | libshiboken/basewrapper.cpp | 18 | ||||
-rw-r--r-- | libshiboken/basewrapper_p.h | 8 |
2 files changed, 13 insertions, 13 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 97154ee7d..d0d66436c 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -367,7 +367,7 @@ void _destroyParentInfo(SbkObject* obj, bool keepReference) // Mark child as invalid Shiboken::Object::invalidate(first); Shiboken::Object::removeParent(first, false, keepReference); - } + } Shiboken::Object::removeParent(obj, false); } } @@ -1085,11 +1085,10 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) if (!pInfo || !pInfo->parent) { if (pInfo && pInfo->hasWrapperRef) { pInfo->hasWrapperRef = false; - delete pInfo; - child->d->parentInfo = 0; } return; } + ChildrenList& oldBrothers = pInfo->parent->d->parentInfo->children; // Verify if this child is part of parent list ChildrenList::iterator iChild = std::find(oldBrothers.begin(), oldBrothers.end(), child); @@ -1105,7 +1104,7 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) child->d->containsCppWrapper) { //If have already a extra ref remove this one if (pInfo->hasWrapperRef) - Py_CLEAR(child); + Py_DECREF(child); else pInfo->hasWrapperRef = true; return; @@ -1114,14 +1113,8 @@ void removeParent(SbkObject* child, bool giveOwnershipBack, bool keepReference) // Transfer ownership back to Python child->d->hasOwnership = giveOwnershipBack; - if (pInfo->children.empty()) { - // Erase parentInfo data - delete pInfo; - child->d->parentInfo = 0; - } - // Remove parent ref - Py_CLEAR(child); + Py_DECREF(child); } void setParent(PyObject* parent, PyObject* child) @@ -1287,8 +1280,7 @@ void clearReferences(SbkObject* self) RefCountMap::iterator iter; for (iter = refCountMap.begin(); iter != refCountMap.end(); ++iter) decRefPyObjectList(iter->second); - delete self->d->referredObjects; - self->d->referredObjects = 0; + self->d->referredObjects->clear(); } } // namespace Object diff --git a/libshiboken/basewrapper_p.h b/libshiboken/basewrapper_p.h index e553d8e68..f34e710f9 100644 --- a/libshiboken/basewrapper_p.h +++ b/libshiboken/basewrapper_p.h @@ -80,6 +80,14 @@ struct SbkObjectPrivate Shiboken::ParentInfo* parentInfo; /// Manage reference counting of objects that are referred but not owned. Shiboken::RefCountMap* referredObjects; + + ~SbkObjectPrivate() + { + delete parentInfo; + parentInfo = 0; + delete referredObjects; + referredObjects = 0; + } }; /// The type behaviour was not defined yet |