Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
8167360f
Commit
8167360f
authored
Sep 22, 2017
by
Ronan
Browse files
feat(c-wrapper): setCppPtrFromC is now more secure
parent
dbb214f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/c-wrapper/internal/c-tools.h
View file @
8167360f
...
...
@@ -123,21 +123,27 @@ public:
return
reinterpret_cast
<
const
WrappedClonableObject
<
CppType
>
*>
(
cObject
)
->
cppPtr
;
}
template
<
typename
T
>
static
inline
void
setCppPtrFromC
(
void
*
cObject
,
const
std
::
shared_ptr
<
T
>
&
cppObject
)
{
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
std
::
is_base_of
<
Object
,
CppType
>
::
value
,
CppType
>::
type
>
static
inline
void
setCppPtrFromC
(
void
*
cObject
,
const
std
::
shared_ptr
<
CppType
>
&
cppObject
)
{
L_ASSERT
(
cObject
);
static_cast
<
WrappedObject
<
T
>
*>
(
cObject
)
->
cppPtr
=
cppObject
;
static_cast
<
WrappedObject
<
CppType
>
*>
(
cObject
)
->
cppPtr
=
cppObject
;
cppObject
->
setProperty
(
"LinphonePrivate::Wrapper::cBackPtr"
,
cObject
);
}
template
<
typename
T
>
static
inline
void
setCppPtrFromC
(
void
*
cObject
,
const
T
*
cppObject
)
{
template
<
typename
CppType
,
typename
=
typename
std
::
enable_if
<
std
::
is_base_of
<
ClonableObject
,
CppType
>
::
value
,
CppType
>::
type
>
static
inline
void
setCppPtrFromC
(
void
*
cObject
,
const
CppType
*
cppObject
)
{
L_ASSERT
(
cObject
);
T
*
oldPtr
=
reinterpret_cast
<
T
*>
(
static_cast
<
WrappedClonableObject
<
T
>
*>
(
cObject
)
->
cppPtr
);
CppType
*
oldPtr
=
reinterpret_cast
<
CppType
*>
(
static_cast
<
WrappedClonableObject
<
CppType
>
*>
(
cObject
)
->
cppPtr
);
if
(
oldPtr
!=
cppObject
)
{
delete
oldPtr
;
T
**
cppPtr
=
&
static_cast
<
WrappedClonableObject
<
T
>
*>
(
cObject
)
->
cppPtr
;
*
cppPtr
=
new
T
(
*
cppObject
);
CppType
**
cppPtr
=
&
static_cast
<
WrappedClonableObject
<
CppType
>
*>
(
cObject
)
->
cppPtr
;
*
cppPtr
=
new
CppType
(
*
cppObject
);
(
*
cppPtr
)
->
setProperty
(
"LinphonePrivate::Wrapper::cBackPtr"
,
cObject
);
}
}
...
...
@@ -429,8 +435,8 @@ LINPHONE_END_NAMESPACE
>(C_OBJECT)
// Set the cpp-ptr of a wrapped C object.
#define L_SET_CPP_PTR_FROM_C_OBJECT(C_OBJECT, CPP_
PTR
) \
LINPHONE_NAMESPACE::Wrapper::setCppPtrFromC(C_OBJECT, CPP_
PTR
)
#define L_SET_CPP_PTR_FROM_C_OBJECT(C_OBJECT, CPP_
OBJECT
) \
LINPHONE_NAMESPACE::Wrapper::setCppPtrFromC(C_OBJECT, CPP_
OBJECT
)
// Get the private data of a shared or simple cpp-ptr.
#define L_GET_PRIVATE(CPP_OBJECT) \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment