aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-03-29 17:22:40 -0300
committerHugo Lima <hugo.lima@openbossa.org>2010-03-30 17:41:39 -0300
commitd3b8a53760ba7c768aaeb547ea541f0806e6e999 (patch)
tree98d486465605cc878a51248b7f69a9e1cca810f7 /libshiboken
parentb0f8a5c519297bff918c864e76a3bc66e51980c9 (diff)
Use a non-template function for Python object deallocation.
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp22
-rw-r--r--libshiboken/basewrapper.h20
2 files changed, 29 insertions, 13 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 0d55ede18..eb3f24d06 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -222,6 +222,28 @@ bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr)
// Wrapper metatype and base type ----------------------------------------------------------
+void deallocWrapper(PyObject* pyObj)
+{
+ SbkBaseWrapper* sbkObj = reinterpret_cast<SbkBaseWrapper*>(pyObj);
+ if (sbkObj->weakreflist)
+ PyObject_ClearWeakRefs(pyObj);
+
+ BindingManager::instance().releaseWrapper(pyObj);
+ if (SbkBaseWrapper_hasOwnership(pyObj)) {
+ SbkBaseWrapperType* sbkType = reinterpret_cast<SbkBaseWrapperType*>(pyObj->ob_type);
+ assert(!sbkType->is_python_type);
+ sbkType->cpp_dtor(sbkObj->cptr);
+ }
+
+ if (SbkBaseWrapper_hasParentInfo(pyObj))
+ destroyParentInfo(sbkObj);
+ SbkBaseWrapper_clearReferences(sbkObj);
+
+ delete sbkObj->cptr;
+ sbkObj->cptr = 0;
+ Py_TYPE(pyObj)->tp_free(pyObj);
+}
+
static PyObject*
SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds)
{
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index ea234b748..97ce8f10b 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -108,6 +108,8 @@ struct LIBSHIBOKEN_API SbkBaseWrapperType
ExtendedIsConvertibleFunc ext_isconvertible;
/// Extended "toCpp" function to be used when a conversion operator is defined in another module.
ExtendedToCppFunc ext_tocpp;
+ /// Pointer to a function responsible for deletetion of the C++ instance calling the proper destructor.
+ void (*cpp_dtor)(void*);
};
/// Base Python object for all the wrapped C++ classes.
@@ -267,20 +269,12 @@ LIBSHIBOKEN_API void SbkBaseWrapper_clearReferences(SbkBaseWrapper* self);
/// Returns true and sets a Python RuntimeError if the Python wrapper is not marked as valid.
LIBSHIBOKEN_API bool cppObjectIsInvalid(PyObject* wrapper);
-template <typename T>
-void SbkBaseWrapper_Dealloc(PyObject* self)
-{
- if (((SbkBaseWrapper *)self)->weakreflist)
- PyObject_ClearWeakRefs(self);
-
- BindingManager::instance().releaseWrapper(self);
- if (SbkBaseWrapper_hasOwnership(self))
- delete (reinterpret_cast<T*>(SbkBaseWrapper_cptr(self)));
- if (SbkBaseWrapper_hasParentInfo(self))
- destroyParentInfo(reinterpret_cast<SbkBaseWrapper*>(self));
- SbkBaseWrapper_clearReferences(reinterpret_cast<SbkBaseWrapper*>(self));
+LIBSHIBOKEN_API void deallocWrapper(PyObject* pyObj);
- Py_TYPE(self)->tp_free(self);
+template<typename T>
+void callCppDestructor(void* cptr)
+{
+ delete reinterpret_cast<T*>(cptr);
}
LIBSHIBOKEN_API PyAPI_FUNC(void) SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self);