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
39cb34c8
Commit
39cb34c8
authored
Jan 07, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid collisions with user types in CAF_ADD_ATOM
parent
6b2cbd4f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
24 deletions
+74
-24
CHANGELOG.md
CHANGELOG.md
+2
-0
libcaf_core/caf/type_id.hpp
libcaf_core/caf/type_id.hpp
+34
-24
libcaf_core/test/type_id_list.cpp
libcaf_core/test/type_id_list.cpp
+38
-0
No files found.
CHANGELOG.md
View file @
39cb34c8
...
@@ -84,6 +84,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
...
@@ -84,6 +84,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
-
Skipping high-priority messages resulted in CAF lowering the priority to
-
Skipping high-priority messages resulted in CAF lowering the priority to
normal. This unintentional demotion has been fixed (#1171).
normal. This unintentional demotion has been fixed (#1171).
-
Fix undefined behavior in the experimental datagram brokers (#1174).
-
Fix undefined behavior in the experimental datagram brokers (#1174).
-
`CAF_ADD_TYPE_ID`
now works with types that live in namespaces that also exist
as nested namespace in CAF such as
`detail`
or
`io`
(#1195).
## [0.18.0-rc.1] - 2020-09-09
## [0.18.0-rc.1] - 2020-09-09
...
...
libcaf_core/caf/type_id.hpp
View file @
39cb34c8
...
@@ -131,7 +131,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -131,7 +131,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
#ifdef CAF_MSVC
#ifdef CAF_MSVC
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
template <> \
struct type_id<
CAF_PP_EXPAND fully_qualified_name> {
\
struct type_id<
::CAF_PP_EXPAND fully_qualified_name> {
\
static constexpr type_id_t value \
static constexpr type_id_t value \
= id_block::project_name##_first_type_id \
= id_block::project_name##_first_type_id \
+ (CAF_PP_CAT(CAF_PP_COUNTER, ()) \
+ (CAF_PP_CAT(CAF_PP_COUNTER, ()) \
...
@@ -140,7 +140,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -140,7 +140,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
#else
#else
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
# define CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
template <> \
struct type_id<
CAF_PP_EXPAND fully_qualified_name> {
\
struct type_id<
::CAF_PP_EXPAND fully_qualified_name> {
\
static constexpr type_id_t value \
static constexpr type_id_t value \
= id_block::project_name##_first_type_id \
= id_block::project_name##_first_type_id \
+ (__COUNTER__ - id_block::project_name##_type_id_counter_init - 1); \
+ (__COUNTER__ - id_block::project_name##_type_id_counter_init - 1); \
...
@@ -151,33 +151,33 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -151,33 +151,33 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
namespace caf { \
namespace caf { \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
template <> \
struct type_by_id<type_id<
CAF_PP_EXPAND fully_qualified_name>::value> {
\
struct type_by_id<type_id<
::CAF_PP_EXPAND fully_qualified_name>::value> {
\
using type =
CAF_PP_EXPAND fully_qualified_name;
\
using type =
::CAF_PP_EXPAND fully_qualified_name;
\
}; \
}; \
template <> \
template <> \
struct type_name<
CAF_PP_EXPAND fully_qualified_name> {
\
struct type_name<
::CAF_PP_EXPAND fully_qualified_name> {
\
static constexpr string_view value \
static constexpr string_view value \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
}; \
template <> \
template <> \
struct type_name_by_id<type_id<
CAF_PP_EXPAND fully_qualified_name>::value>
\
struct type_name_by_id<type_id<
::CAF_PP_EXPAND fully_qualified_name>::value>
\
: type_name<
CAF_PP_EXPAND fully_qualified_name> {};
\
: type_name<
::CAF_PP_EXPAND fully_qualified_name> {};
\
}
}
#define CAF_ADD_TYPE_ID_3(project_name, fully_qualified_name, user_type_name) \
#define CAF_ADD_TYPE_ID_3(project_name, fully_qualified_name, user_type_name) \
namespace caf { \
namespace caf { \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
CAF_DETAIL_NEXT_TYPE_ID(project_name, fully_qualified_name) \
template <> \
template <> \
struct type_by_id<type_id<
CAF_PP_EXPAND fully_qualified_name>::value> {
\
struct type_by_id<type_id<
::CAF_PP_EXPAND fully_qualified_name>::value> {
\
using type =
CAF_PP_EXPAND fully_qualified_name;
\
using type =
::CAF_PP_EXPAND fully_qualified_name;
\
}; \
}; \
template <> \
template <> \
struct type_name<
CAF_PP_EXPAND fully_qualified_name> {
\
struct type_name<
::CAF_PP_EXPAND fully_qualified_name> {
\
static constexpr string_view value = user_type_name; \
static constexpr string_view value = user_type_name; \
}; \
}; \
template <> \
template <> \
struct type_name_by_id<type_id<
CAF_PP_EXPAND fully_qualified_name>::value>
\
struct type_name_by_id<type_id<
::CAF_PP_EXPAND fully_qualified_name>::value>
\
: type_name<
CAF_PP_EXPAND fully_qualified_name> {};
\
: type_name<
::CAF_PP_EXPAND fully_qualified_name> {};
\
}
}
/// @def CAF_ADD_TYPE_ID(project_name, fully_qualified_name, user_type_name)
/// @def CAF_ADD_TYPE_ID(project_name, fully_qualified_name, user_type_name)
...
@@ -276,22 +276,32 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
...
@@ -276,22 +276,32 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}; \
}; \
}
}
namespace
caf
::
detail
{
// We can't pass a builtin type such as `bool` to CAF_ADD_TYPE_ID because it
// expands to `::bool`, which for some reason is invalid in C++. This alias only
// exists to work around this limitation.
template
<
class
T
>
using
id_t
=
T
;
}
// namespace caf::detail
CAF_BEGIN_TYPE_ID_BLOCK
(
core_module
,
0
)
CAF_BEGIN_TYPE_ID_BLOCK
(
core_module
,
0
)
// -- C types
// -- C types
CAF_ADD_TYPE_ID
(
core_module
,
(
bool
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
bool
>
),
"bool"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
double
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
double
>
),
"double"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
float
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
float
>
),
"float"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
int16_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
int16_t
>
),
"int16_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
int32_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
int32_t
>
),
"int32_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
int64_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
int64_t
>
),
"int64_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
int8_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
int8_t
>
),
"int8_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
long
double
),
"ldouble"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
long
double
>
),
"ldouble"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
uint16_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
uint16_t
>
),
"uint16_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
uint32_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
uint32_t
>
),
"uint32_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
uint64_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
uint64_t
>
),
"uint64_t"
)
CAF_ADD_TYPE_ID
(
core_module
,
(
uint8_t
)
)
CAF_ADD_TYPE_ID
(
core_module
,
(
caf
::
detail
::
id_t
<
uint8_t
>
),
"uint8_t"
)
// -- STL types
// -- STL types
...
...
libcaf_core/test/type_id_list.cpp
View file @
39cb34c8
...
@@ -8,6 +8,44 @@
...
@@ -8,6 +8,44 @@
#include "core-test.hpp"
#include "core-test.hpp"
namespace
detail
{
struct
my_secret
{
int
value
;
};
template
<
class
Inspector
>
bool
inspect
(
Inspector
&
f
,
my_secret
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"value"
,
x
.
value
));
}
}
// namespace detail
namespace
io
{
struct
protocol
{
std
::
string
name
;
};
template
<
class
Inspector
>
bool
inspect
(
Inspector
&
f
,
protocol
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"name"
,
x
.
name
));
}
}
// namespace io
// A type ID block with types that live in namespaces that also exist as nested
// CAF namespaces. This is a regression test for
// https://github.com/actor-framework/actor-framework/issues/1195. We don't need
// to actually use these types, only check whether the code compiles.
CAF_BEGIN_TYPE_ID_BLOCK
(
type_id_test
,
caf
::
id_block
::
core_test
::
end
)
CAF_ADD_TYPE_ID
(
type_id_test
,
(
detail
::
my_secret
))
CAF_ADD_TYPE_ID
(
type_id_test
,
(
io
::
protocol
))
CAF_END_TYPE_ID_BLOCK
(
type_id_test
)
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
lists
store
the
size
at
index
0
)
{
CAF_TEST
(
lists
store
the
size
at
index
0
)
{
...
...
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