From 771487a89a6bfc1b32964c9f518bd75dee20b76b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 24 May 2018 17:23:03 +0200 Subject: [PATCH] fix(c-wrapper): add a way to clone custom properties of c objects --- src/c-wrapper/api/c-content.cpp | 8 ++++++++ src/c-wrapper/internal/c-tools.h | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index 29ccb9c16..6dbbd81ec 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -32,10 +32,12 @@ using namespace std; static void _linphone_content_constructor (LinphoneContent *content); static void _linphone_content_destructor (LinphoneContent *content); +static void _linphone_content_c_clone (LinphoneContent *dest, const LinphoneContent *src); L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content, _linphone_content_constructor, _linphone_content_destructor, + _linphone_content_c_clone, void *cryptoContext; // Used to encrypt file for RCS file transfer. @@ -57,6 +59,12 @@ static void _linphone_content_destructor (LinphoneContent *content) { content->cache.~Cache(); } +static void _linphone_content_c_clone (LinphoneContent *dest, const LinphoneContent *src) { + new(&dest->cache) LinphoneContent::Cache(); + dest->size = src->size; + dest->cache = src->cache; +} + // ============================================================================= // Reference and user data handling functions. // ============================================================================= diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 492cbaccf..e2520dcc3 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -612,6 +612,7 @@ LINPHONE_END_NAMESPACE #undef L_INTERNAL_WRAPPER_CONSTEXPR #define L_INTERNAL_C_NO_XTOR(C_OBJECT) +#define L_INTERNAL_C_NO_CLONE_C(C_DEST_OBJECT, C_SRC_OBJECT) #define L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, ...) \ static_assert(LinphonePrivate::CTypeMetaInfo::defined, "Type is not defined."); \ @@ -669,7 +670,7 @@ LINPHONE_END_NAMESPACE __VA_ARGS__ \ }; \ -#define L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR) \ +#define L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C) \ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_TYPE); \ Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init () { \ Linphone ## C_TYPE *object = belle_sip_object_new(Linphone ## C_TYPE); \ @@ -683,6 +684,7 @@ LINPHONE_END_NAMESPACE static void _linphone_ ## C_TYPE ## _clone (Linphone ## C_TYPE *dest, const Linphone ## C_TYPE *src) { \ L_ASSERT(src->cppPtr); \ dest->cppPtr = new L_CPP_TYPE_OF_C_TYPE(C_TYPE)(*src->cppPtr); \ + CLONE_C(dest, src); \ } \ BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_TYPE); \ BELLE_SIP_INSTANCIATE_VPTR( \ @@ -760,15 +762,15 @@ LINPHONE_END_NAMESPACE L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, __VA_ARGS__) \ L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR) -// Declare clonable wrapped C object with constructor/destructor. -#define L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, ...) \ +// Declare clonable wrapped C object with constructor/destructor and clone_c. +#define L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C, ...) \ L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \ - L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR) + L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C) // Declare clonable wrapped C object. #define L_DECLARE_C_CLONABLE_OBJECT_IMPL(C_TYPE, ...) \ L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \ - L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR) + L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_CLONE_C) // ----------------------------------------------------------------------------- // Helpers.