Commit aab81fe7 authored by Ronan's avatar Ronan

fix(c-wrapper): deal with internal cpp ptr destructions (on clonable)

parent 39e7f6ed
......@@ -293,12 +293,22 @@ public:
typename CppType,
typename = typename std::enable_if<std::is_base_of<BaseObject, CppType>::value, CppType>::type
>
static void signalCppPtrDestruction (CppType *cppObject) {
static void handleObjectDestruction (CppType *cppObject) {
void *value = cppObject->getCBackPtr();
if (value && static_cast<WrappedBaseObject<CppType> *>(value)->owner == WrappedObjectOwner::Internal)
belle_sip_object_unref(value);
}
template<
typename CppType,
typename = typename std::enable_if<std::is_base_of<ClonableObject, CppType>::value, CppType>::type
>
static void handleClonableObjectDestruction (CppType *cppObject) {
void *value = cppObject->getCBackPtr();
if (value && static_cast<WrappedClonableObject<CppType> *>(value)->owner == WrappedObjectOwner::Internal)
belle_sip_object_unref(value);
}
// ---------------------------------------------------------------------------
// Get c/cpp ptr helpers.
// ---------------------------------------------------------------------------
......@@ -771,10 +781,6 @@ LINPHONE_END_NAMESPACE
// Call the init function of wrapped C object.
#define L_INIT(C_TYPE) _linphone_ ## C_TYPE ## _init()
// Signal to wrapper the destruction of cpp base object.
#define L_SIGNAL_CPP_PTR_DESTRUCTION(CPP_OBJECT) \
LinphonePrivate::Wrapper::signalCppPtrDestruction(CPP_OBJECT);
// Get/set the cpp-ptr of a wrapped C object.
#define L_GET_CPP_PTR_FROM_C_OBJECT_1_ARGS(C_OBJECT) \
LinphonePrivate::Wrapper::getCppPtrFromC(C_OBJECT)
......
......@@ -19,8 +19,6 @@
#include "base-object-p.h"
#include "base-object.h"
// Necessary for: L_SIGNAL_CPP_PTR_DESTRUCTION.
#include "c-wrapper/internal/c-tools.h"
// =============================================================================
......@@ -34,7 +32,7 @@ BaseObject::BaseObject (BaseObjectPrivate &p) : mPrivate(&p) {
}
BaseObject::~BaseObject () {
L_SIGNAL_CPP_PTR_DESTRUCTION(this);
Wrapper::handleObjectDestruction(this);
delete mPrivate;
}
......
......@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "c-wrapper/internal/c-tools.h"
#include "clonable-object-p.h"
#include "clonable-object.h"
......@@ -43,6 +44,7 @@ ClonableObject::ClonableObject (ClonableObjectPrivate &p) {
} while (false);
ClonableObject::~ClonableObject () {
Wrapper::handleClonableObjectDestruction(this);
UNREF();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment