aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-07-01 16:00:09 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:27 -0300
commit878c6c81a7469335e70856f77142473bb358051d (patch)
tree6bae247b5587c644bd58aea18b8b8209cc8034ac /libshiboken
parent88a84ee6ae8cd12b2527576505f16774c9c542c1 (diff)
Cleared cptr data during the cpp object destruction.
This avoid problems when the same addres was used late in the program. Fixes bug #904.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 9552031ff..3e9b08a3a 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -815,7 +815,9 @@ void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType)
int idx = 0;
if (reinterpret_cast<SbkObjectType*>(type)->d->is_multicpp)
idx = getTypeIndexOnHierarchy(type, desiredType);
- return pyObj->d->cptr[idx];
+ if (pyObj->d->cptr)
+ return pyObj->d->cptr[idx];
+ return 0;
}
bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr)
@@ -951,6 +953,11 @@ void destroy(SbkObject* self, void* cppData)
if (cppData && Shiboken::BindingManager::instance().hasWrapper(cppData)) {
// Remove from BindingManager
Shiboken::BindingManager::instance().releaseWrapper(self);
+ self->d->hasOwnership = false;
+
+ // the cpp object instance was deleted
+ delete[] self->d->cptr;
+ self->d->cptr = 0;
}
// After this point the object can be death do not use the self pointer bellow
@@ -1076,13 +1083,14 @@ void deallocData(SbkObject* self, bool cleanup)
clearReferences(self);
}
- // Remove from BindingManager
- Shiboken::BindingManager::instance().releaseWrapper(self);
-
+ if (self->d->cptr) {
+ // Remove from BindingManager
+ Shiboken::BindingManager::instance().releaseWrapper(self);
+ delete[] self->d->cptr;
+ self->d->cptr = 0;
+ delete self->d;
+ }
Py_XDECREF(self->ob_dict);
- delete[] self->d->cptr;
- self->d->cptr = 0;
- delete self->d;
Py_TYPE(self)->tp_free(self);
}