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

This commit is contained in:
Ronan Abhamon 2018-04-24 17:04:59 +02:00
parent 39e7f6eddc
commit aab81fe7ed
3 changed files with 14 additions and 8 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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();
}