aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-10-15 16:04:49 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:07:21 -0300
commitdc18b27491b45577fe2868382f0f645a4127387b (patch)
tree82db615b6078ecec7cfcc9ebb5df9769dff40681 /libshiboken
parentb4d648d09c293816a6f15ffdc2bdc7b0ec0792fb (diff)
Fix bug#272 - "__del__ never called by python"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Lauro Moura <lauro.neto@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp41
1 files changed, 8 insertions, 33 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 189e211c0..7f7b8da8b 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -246,7 +246,7 @@ static void _destroyParentInfo(SbkBaseWrapper* obj, bool removeFromParent)
for (; it != pInfo->children.end(); ++it) {
SbkBaseWrapper*& child = *it;
- // keep this, the wrapper still alive
+ // keep this, the wrapper still alive
if (!SbkBaseWrapper_containsCppWrapper(obj) &&
SbkBaseWrapper_containsCppWrapper(child) &&
child->parentInfo) {
@@ -316,8 +316,7 @@ void walkThroughClassHierarchy(PyTypeObject* currentType, HierarchyVisitor* visi
PyObject* SbkBaseWrapper_TpNew(PyTypeObject* subtype, PyObject*, PyObject*)
{
- Shiboken::AutoDecRef emptyTuple(PyTuple_New(0));
- SbkBaseWrapper* self = reinterpret_cast<SbkBaseWrapper*>(PyBaseObject_Type.tp_new(subtype, emptyTuple, 0));
+ SbkBaseWrapper* self = reinterpret_cast<SbkBaseWrapper*>(subtype->tp_alloc(subtype, 0));
SbkBaseWrapperType* sbkType = reinterpret_cast<SbkBaseWrapperType*>(subtype);
int numBases = sbkType->is_multicpp ? getNumberOfCppBaseClasses(subtype) : 1;
@@ -465,34 +464,8 @@ private:
SbkBaseWrapper* m_pyObj;
};
-static void deallocPythonTypes(PyObject* pyObj)
-{
- SbkBaseWrapper* sbkObj = reinterpret_cast<SbkBaseWrapper*>(pyObj);
- if (sbkObj->weakreflist)
- PyObject_ClearWeakRefs(pyObj);
-
- BindingManager::instance().releaseWrapper(pyObj);
- if (SbkBaseWrapper_hasOwnership(sbkObj)) {
- DtorCallerVisitor visitor(sbkObj);
- walkThroughClassHierarchy(pyObj->ob_type, &visitor);
- }
-
- if (SbkBaseWrapper_hasParentInfo(sbkObj))
- destroyParentInfo(sbkObj);
- clearReferences(sbkObj);
-
- delete[] sbkObj->cptr;
- sbkObj->cptr = 0;
-
- Py_TYPE(pyObj)->tp_free(pyObj);
-
-}
-
void deallocWrapper(PyObject* pyObj)
{
- if (Py_TYPE(pyObj)->tp_del)
- Py_TYPE(pyObj)->tp_del(pyObj);
-
SbkBaseWrapper* sbkObj = reinterpret_cast<SbkBaseWrapper*>(pyObj);
if (sbkObj->weakreflist)
PyObject_ClearWeakRefs(pyObj);
@@ -500,8 +473,12 @@ void deallocWrapper(PyObject* pyObj)
BindingManager::instance().releaseWrapper(pyObj);
if (SbkBaseWrapper_hasOwnership(pyObj)) {
SbkBaseWrapperType* sbkType = reinterpret_cast<SbkBaseWrapperType*>(pyObj->ob_type);
- assert(!sbkType->is_multicpp);
- sbkType->cpp_dtor(sbkObj->cptr[0]);
+ if (sbkType->is_multicpp) {
+ DtorCallerVisitor visitor(sbkObj);
+ walkThroughClassHierarchy(pyObj->ob_type, &visitor);
+ } else {
+ sbkType->cpp_dtor(sbkObj->cptr[0]);
+ }
}
if (SbkBaseWrapper_hasParentInfo(pyObj))
@@ -537,7 +514,6 @@ PyObject* SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObj
std::list<SbkBaseWrapperType*> bases = getCppBaseClasses(reinterpret_cast<PyTypeObject*>(newType));
if (bases.size() == 1) {
SbkBaseWrapperType* parentType = bases.front();
- newType->super.ht_type.tp_dealloc = parentType->super.ht_type.tp_dealloc;
newType->mi_offsets = parentType->mi_offsets;
newType->mi_init = parentType->mi_init;
newType->mi_specialcast = parentType->mi_specialcast;
@@ -548,7 +524,6 @@ PyObject* SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObj
newType->cpp_dtor = parentType->cpp_dtor;
newType->is_multicpp = 0;
} else {
- newType->super.ht_type.tp_dealloc = &deallocPythonTypes;
newType->mi_offsets = 0;
newType->mi_init = 0;
newType->mi_specialcast = 0;