Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
60c07ea1
Commit
60c07ea1
authored
Jan 05, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Force all types to be serializable or whiteslisted
Relates #388
parent
d17d2b03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
5 deletions
+59
-5
libcaf_core/caf/allowed_unsafe_message_type.hpp
libcaf_core/caf/allowed_unsafe_message_type.hpp
+39
-0
libcaf_core/caf/message.hpp
libcaf_core/caf/message.hpp
+20
-5
No files found.
libcaf_core/caf/allowed_unsafe_message_type.hpp
0 → 100644
View file @
60c07ea1
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_ALLOWED_UNSAFE_MESSAGE_TYPE_HPP
#define CAF_ALLOWED_UNSAFE_MESSAGE_TYPE_HPP
#include <type_traits>
namespace
caf
{
///
template
<
class
T
>
struct
allowed_unsafe_message_type
:
std
::
false_type
{};
}
// namespace caf
#define CAF_ALLOW_UNSAFE_MESSAGE_TYPE(type_name) \
namespace caf { \
template <> \
struct allowed_unsafe_message_type<type_name> : std::true_type {}; \
}
#endif // CAF_ALLOWED_UNSAFE_MESSAGE_TYPE_HPP
libcaf_core/caf/message.hpp
View file @
60c07ea1
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include "caf/make_counted.hpp"
#include "caf/make_counted.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip_message.hpp"
#include "caf/index_mapping.hpp"
#include "caf/index_mapping.hpp"
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/apply_args.hpp"
#include "caf/detail/apply_args.hpp"
...
@@ -383,27 +384,41 @@ struct unbox_message_element<atom_constant<V>, 0> {
...
@@ -383,27 +384,41 @@ struct unbox_message_element<atom_constant<V>, 0> {
using
type
=
atom_value
;
using
type
=
atom_value
;
};
};
///
template
<
class
T
>
struct
is_serializable_or_whitelisted
{
static
constexpr
bool
value
=
detail
::
is_serializable
<
T
>::
value
||
allowed_unsafe_message_type
<
T
>::
value
;
};
/// Returns a new `message` containing the values `(x, xs...)`.
/// Returns a new `message` containing the values `(x, xs...)`.
/// @relates message
/// @relates message
template
<
class
V
,
class
...
Ts
>
template
<
class
T
,
class
...
Ts
>
typename
std
::
enable_if
<
typename
std
::
enable_if
<
!
std
::
is_same
<
message
,
typename
std
::
decay
<
V
>::
type
>::
value
!
std
::
is_same
<
message
,
typename
std
::
decay
<
T
>::
type
>::
value
||
(
sizeof
...(
Ts
)
>
0
),
||
(
sizeof
...(
Ts
)
>
0
),
message
message
>::
type
>::
type
make_message
(
V
&&
x
,
Ts
&&
...
xs
)
{
make_message
(
T
&&
x
,
Ts
&&
...
xs
)
{
using
namespace
caf
::
detail
;
using
namespace
caf
::
detail
;
using
stored_types
=
using
stored_types
=
type_list
<
type_list
<
typename
unbox_message_element
<
typename
unbox_message_element
<
typename
strip_and_convert
<
V
>::
type
typename
strip_and_convert
<
T
>::
type
>::
type
,
>::
type
,
typename
unbox_message_element
<
typename
unbox_message_element
<
typename
strip_and_convert
<
Ts
>::
type
typename
strip_and_convert
<
Ts
>::
type
>::
type
...
>::
type
...
>
;
>
;
static_assert
(
tl_forall
<
stored_types
,
is_serializable_or_whitelisted
>::
value
,
"at least one type is not serializable via free "
"'serialize(InOrOut&, T&, const unsigned int)' or "
"`T::serialize(InOrOut&, const unsigned int)` "
"member function; you can whitelist individual types by "
"specializing `caf::allowed_unsafe_message_type<T>` "
"or using the macro CAF_ALLOW_UNSAFE_MESSAGE_TYPE"
);
using
storage
=
typename
tl_apply
<
stored_types
,
tuple_vals
>::
type
;
using
storage
=
typename
tl_apply
<
stored_types
,
tuple_vals
>::
type
;
auto
ptr
=
make_counted
<
storage
>
(
std
::
forward
<
V
>
(
x
),
std
::
forward
<
Ts
>
(
xs
)...);
auto
ptr
=
make_counted
<
storage
>
(
std
::
forward
<
T
>
(
x
),
std
::
forward
<
Ts
>
(
xs
)...);
return
message
{
detail
::
message_data
::
cow_ptr
{
std
::
move
(
ptr
)}};
return
message
{
detail
::
message_data
::
cow_ptr
{
std
::
move
(
ptr
)}};
}
}
...
...
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