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
483fcc4c
Commit
483fcc4c
authored
Apr 14, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch to new CAF_ENABLE_EXCEPTIONS flag
parent
244475ea
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
50 deletions
+42
-50
cmake/build_config.hpp.in
cmake/build_config.hpp.in
+1
-3
libcaf_core/caf/raise_error.hpp
libcaf_core/caf/raise_error.hpp
+13
-13
libcaf_core/caf/scheduled_actor.hpp
libcaf_core/caf/scheduled_actor.hpp
+10
-10
libcaf_core/caf/typed_actor_view.hpp
libcaf_core/caf/typed_actor_view.hpp
+2
-2
libcaf_core/src/blocking_actor.cpp
libcaf_core/src/blocking_actor.cpp
+1
-1
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+12
-12
libcaf_core/test/custom_exception_handler.cpp
libcaf_core/test/custom_exception_handler.cpp
+3
-9
No files found.
cmake/build_config.hpp.in
View file @
483fcc4c
...
@@ -25,10 +25,8 @@
...
@@ -25,10 +25,8 @@
#define CAF_LOG_LEVEL CAF_LOG_LEVEL_@CAF_LOG_LEVEL@
#define CAF_LOG_LEVEL CAF_LOG_LEVEL_@CAF_LOG_LEVEL@
#cmakedefine CAF_NO_MEM_MANAGEMENT
#cmakedefine CAF_ENABLE_RUNTIME_CHECKS
#cmakedefine CAF_ENABLE_RUNTIME_CHECKS
#cmakedefine CAF_
NO
_EXCEPTIONS
#cmakedefine CAF_
ENABLE
_EXCEPTIONS
#cmakedefine CAF_ENABLE_ACTOR_PROFILER
#cmakedefine CAF_ENABLE_ACTOR_PROFILER
libcaf_core/caf/raise_error.hpp
View file @
483fcc4c
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
# include <stdexcept>
# include <stdexcept>
#endif
#endif
...
@@ -33,32 +33,32 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
...
@@ -33,32 +33,32 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
}
// namespace caf::detail
}
// namespace caf::detail
#ifdef CAF_
NO
_EXCEPTIONS
#ifdef CAF_
ENABLE
_EXCEPTIONS
# define CAF_RAISE_ERROR_IMPL_
1(msg)
\
# define CAF_RAISE_ERROR_IMPL_
2(exception_type, msg)
\
do { \
do { \
::caf::detail::log_cstring_error(msg); \
::caf::detail::log_cstring_error(msg); \
CAF_CRITICAL(msg);
\
throw exception_type(msg);
\
} while (false)
} while (false)
# define CAF_RAISE_ERROR_IMPL_2(unused, msg) CAF_RAISE_ERROR_IMPL_1(msg)
# define CAF_RAISE_ERROR_IMPL_1(msg) \
CAF_RAISE_ERROR_IMPL_2(std::runtime_error, msg)
#else // CAF_
NO
_EXCEPTIONS
#else // CAF_
ENABLE
_EXCEPTIONS
# define CAF_RAISE_ERROR_IMPL_
2(exception_type, msg)
\
# define CAF_RAISE_ERROR_IMPL_
1(msg)
\
do { \
do { \
::caf::detail::log_cstring_error(msg); \
::caf::detail::log_cstring_error(msg); \
throw exception_type(msg);
\
CAF_CRITICAL(msg);
\
} while (false)
} while (false)
# define CAF_RAISE_ERROR_IMPL_1(msg) \
# define CAF_RAISE_ERROR_IMPL_2(unused, msg) CAF_RAISE_ERROR_IMPL_1(msg)
CAF_RAISE_ERROR_IMPL_2(std::runtime_error, msg)
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
#ifdef CAF_MSVC
#ifdef CAF_MSVC
/// Throws an exception if `CAF_
NO_EXCEPTIONS` is un
defined, otherwise calls
/// Throws an exception if `CAF_
ENABLE_EXCEPTIONS` is
defined, otherwise calls
/// abort() after printing a given message.
/// abort() after printing a given message.
# define CAF_RAISE_ERROR(...) \
# define CAF_RAISE_ERROR(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, \
...
@@ -67,7 +67,7 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
...
@@ -67,7 +67,7 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
#else // CAF_MSVC
#else // CAF_MSVC
/// Throws an exception if `CAF_
NO_EXCEPTIONS` is un
defined, otherwise calls
/// Throws an exception if `CAF_
ENABLE_EXCEPTIONS` is
defined, otherwise calls
/// abort() after printing a given message.
/// abort() after printing a given message.
# define CAF_RAISE_ERROR(...) \
# define CAF_RAISE_ERROR(...) \
CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, __VA_ARGS__)(__VA_ARGS__)
CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, __VA_ARGS__)(__VA_ARGS__)
...
...
libcaf_core/caf/scheduled_actor.hpp
View file @
483fcc4c
...
@@ -20,9 +20,9 @@
...
@@ -20,9 +20,9 @@
#include "caf/config.hpp"
#include "caf/config.hpp"
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
# include <exception>
# include <exception>
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
#include <forward_list>
#include <forward_list>
#include <map>
#include <map>
...
@@ -190,10 +190,10 @@ public:
...
@@ -190,10 +190,10 @@ public:
/// Function object for handling exit messages.
/// Function object for handling exit messages.
using
exit_handler
=
std
::
function
<
void
(
pointer
,
exit_msg
&
)
>
;
using
exit_handler
=
std
::
function
<
void
(
pointer
,
exit_msg
&
)
>
;
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
/// Function object for handling exit messages.
/// Function object for handling exit messages.
using
exception_handler
=
std
::
function
<
error
(
pointer
,
std
::
exception_ptr
&
)
>
;
using
exception_handler
=
std
::
function
<
error
(
pointer
,
std
::
exception_ptr
&
)
>
;
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
/// Consumes messages from the mailbox.
/// Consumes messages from the mailbox.
struct
mailbox_visitor
{
struct
mailbox_visitor
{
...
@@ -232,9 +232,9 @@ public:
...
@@ -232,9 +232,9 @@ public:
static
void
default_exit_handler
(
pointer
ptr
,
exit_msg
&
x
);
static
void
default_exit_handler
(
pointer
ptr
,
exit_msg
&
x
);
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
static
error
default_exception_handler
(
pointer
ptr
,
std
::
exception_ptr
&
x
);
static
error
default_exception_handler
(
pointer
ptr
,
std
::
exception_ptr
&
x
);
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
// -- constructors and destructors -------------------------------------------
// -- constructors and destructors -------------------------------------------
...
@@ -389,7 +389,7 @@ public:
...
@@ -389,7 +389,7 @@ public:
set_exit_handler
([
fun
](
scheduled_actor
*
,
exit_msg
&
x
)
{
fun
(
x
);
});
set_exit_handler
([
fun
](
scheduled_actor
*
,
exit_msg
&
x
)
{
fun
(
x
);
});
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
/// Sets a custom exception handler for this actor. If multiple handlers are
/// Sets a custom exception handler for this actor. If multiple handlers are
/// defined, only the functor that was added *last* is being executed.
/// defined, only the functor that was added *last* is being executed.
inline
void
set_exception_handler
(
exception_handler
fun
)
{
inline
void
set_exception_handler
(
exception_handler
fun
)
{
...
@@ -408,7 +408,7 @@ public:
...
@@ -408,7 +408,7 @@ public:
set_exception_handler
(
set_exception_handler
(
[
f
](
scheduled_actor
*
,
std
::
exception_ptr
&
x
)
{
return
f
(
x
);
});
[
f
](
scheduled_actor
*
,
std
::
exception_ptr
&
x
)
{
return
f
(
x
);
});
}
}
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
/// @cond PRIVATE
/// @cond PRIVATE
...
@@ -703,10 +703,10 @@ protected:
...
@@ -703,10 +703,10 @@ protected:
/// Pointer to a private thread object associated with a detached actor.
/// Pointer to a private thread object associated with a detached actor.
detail
::
private_thread
*
private_thread_
;
detail
::
private_thread
*
private_thread_
;
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
/// Customization point for setting a default exception callback.
/// Customization point for setting a default exception callback.
exception_handler
exception_handler_
;
exception_handler
exception_handler_
;
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
/// @endcond
/// @endcond
};
};
...
...
libcaf_core/caf/typed_actor_view.hpp
View file @
483fcc4c
...
@@ -104,7 +104,7 @@ public:
...
@@ -104,7 +104,7 @@ public:
self_
->
set_exit_handler
(
std
::
forward
<
Fun
>
(
fun
));
self_
->
set_exit_handler
(
std
::
forward
<
Fun
>
(
fun
));
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
/// @copydoc scheduled_actor::set_exception_handler
/// @copydoc scheduled_actor::set_exception_handler
template
<
class
Fun
>
template
<
class
Fun
>
...
@@ -112,7 +112,7 @@ public:
...
@@ -112,7 +112,7 @@ public:
self_
->
set_exception_handler
(
std
::
forward
<
Fun
>
(
fun
));
self_
->
set_exception_handler
(
std
::
forward
<
Fun
>
(
fun
));
}
}
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
// -- linking and monitoring -------------------------------------------------
// -- linking and monitoring -------------------------------------------------
...
...
libcaf_core/src/blocking_actor.cpp
View file @
483fcc4c
...
@@ -107,7 +107,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
...
@@ -107,7 +107,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
CAF_PUSH_AID_FROM_PTR
(
self
);
CAF_PUSH_AID_FROM_PTR
(
self
);
self
->
initialize
();
self
->
initialize
();
error
rsn
;
error
rsn
;
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
try
{
try
{
self
->
act
();
self
->
act
();
rsn
=
self
->
fail_state_
;
rsn
=
self
->
fail_state_
;
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
483fcc4c
...
@@ -97,7 +97,7 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) {
...
@@ -97,7 +97,7 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) {
default_error_handler
(
ptr
,
x
.
reason
);
default_error_handler
(
ptr
,
x
.
reason
);
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
error
scheduled_actor
::
default_exception_handler
(
pointer
ptr
,
error
scheduled_actor
::
default_exception_handler
(
pointer
ptr
,
std
::
exception_ptr
&
x
)
{
std
::
exception_ptr
&
x
)
{
CAF_ASSERT
(
x
!=
nullptr
);
CAF_ASSERT
(
x
!=
nullptr
);
...
@@ -115,7 +115,7 @@ error scheduled_actor::default_exception_handler(pointer ptr,
...
@@ -115,7 +115,7 @@ error scheduled_actor::default_exception_handler(pointer ptr,
}
}
return
sec
::
runtime_error
;
return
sec
::
runtime_error
;
}
}
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
// -- constructors and destructors ---------------------------------------------
// -- constructors and destructors ---------------------------------------------
...
@@ -129,10 +129,10 @@ scheduled_actor::scheduled_actor(actor_config& cfg)
...
@@ -129,10 +129,10 @@ scheduled_actor::scheduled_actor(actor_config& cfg)
node_down_handler_
(
default_node_down_handler
),
node_down_handler_
(
default_node_down_handler
),
exit_handler_
(
default_exit_handler
),
exit_handler_
(
default_exit_handler
),
private_thread_
(
nullptr
)
private_thread_
(
nullptr
)
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
,
,
exception_handler_
(
default_exception_handler
)
exception_handler_
(
default_exception_handler
)
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
{
{
auto
&
sys_cfg
=
home_system
().
config
();
auto
&
sys_cfg
=
home_system
().
config
();
auto
interval
=
sys_cfg
.
stream_tick_duration
();
auto
interval
=
sys_cfg
.
stream_tick_duration
();
...
@@ -743,9 +743,9 @@ bool scheduled_actor::activate(execution_unit* ctx) {
...
@@ -743,9 +743,9 @@ bool scheduled_actor::activate(execution_unit* ctx) {
CAF_LOG_ERROR
(
"activate called on a terminated actor"
);
CAF_LOG_ERROR
(
"activate called on a terminated actor"
);
return
false
;
return
false
;
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
try
{
try
{
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
if
(
!
getf
(
is_initialized_flag
))
{
if
(
!
getf
(
is_initialized_flag
))
{
initialize
();
initialize
();
if
(
finalize
())
{
if
(
finalize
())
{
...
@@ -754,7 +754,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
...
@@ -754,7 +754,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
}
}
CAF_LOG_DEBUG
(
"initialized actor:"
<<
CAF_ARG
(
name
()));
CAF_LOG_DEBUG
(
"initialized actor:"
<<
CAF_ARG
(
name
()));
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
}
catch
(...)
{
}
catch
(...)
{
CAF_LOG_ERROR
(
"actor died during initialization"
);
CAF_LOG_ERROR
(
"actor died during initialization"
);
auto
eptr
=
std
::
current_exception
();
auto
eptr
=
std
::
current_exception
();
...
@@ -762,7 +762,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
...
@@ -762,7 +762,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
finalize
();
finalize
();
return
false
;
return
false
;
}
}
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
return
true
;
return
true
;
}
}
...
@@ -779,7 +779,7 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x)
...
@@ -779,7 +779,7 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x)
auto
scheduled_actor
::
reactivate
(
mailbox_element
&
x
)
->
activation_result
{
auto
scheduled_actor
::
reactivate
(
mailbox_element
&
x
)
->
activation_result
{
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
auto
handle_exception
=
[
&
](
std
::
exception_ptr
eptr
)
{
auto
handle_exception
=
[
&
](
std
::
exception_ptr
eptr
)
{
auto
err
=
call_handler
(
exception_handler_
,
this
,
eptr
);
auto
err
=
call_handler
(
exception_handler_
,
this
,
eptr
);
if
(
x
.
mid
.
is_request
())
{
if
(
x
.
mid
.
is_request
())
{
...
@@ -789,7 +789,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
...
@@ -789,7 +789,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
quit
(
std
::
move
(
err
));
quit
(
std
::
move
(
err
));
};
};
try
{
try
{
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
switch
(
consume
(
x
))
{
switch
(
consume
(
x
))
{
case
invoke_message_result
:
:
dropped
:
case
invoke_message_result
:
:
dropped
:
return
activation_result
::
dropped
;
return
activation_result
::
dropped
;
...
@@ -803,7 +803,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
...
@@ -803,7 +803,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
case
invoke_message_result
:
:
skipped
:
case
invoke_message_result
:
:
skipped
:
return
activation_result
::
skipped
;
return
activation_result
::
skipped
;
}
}
#if
ndef CAF_NO
_EXCEPTIONS
#if
def CAF_ENABLE
_EXCEPTIONS
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
CAF_LOG_INFO
(
"actor died because of an exception, what: "
<<
e
.
what
());
CAF_LOG_INFO
(
"actor died because of an exception, what: "
<<
e
.
what
());
static_cast
<
void
>
(
e
);
// keep compiler happy when not logging
static_cast
<
void
>
(
e
);
// keep compiler happy when not logging
...
@@ -814,7 +814,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
...
@@ -814,7 +814,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
}
}
finalize
();
finalize
();
return
activation_result
::
terminated
;
return
activation_result
::
terminated
;
#endif // CAF_
NO
_EXCEPTIONS
#endif // CAF_
ENABLE
_EXCEPTIONS
}
}
// -- behavior management ----------------------------------------------------
// -- behavior management ----------------------------------------------------
...
...
libcaf_core/test/custom_exception_handler.cpp
View file @
483fcc4c
...
@@ -24,7 +24,9 @@
...
@@ -24,7 +24,9 @@
using
namespace
caf
;
using
namespace
caf
;
#ifndef CAF_NO_EXCEPTIONS
#ifndef CAF_ENABLE_EXCEPTIONS
# error "building unit test for exception handlers in no-exceptions build"
#endif
class
exception_testee
:
public
event_based_actor
{
class
exception_testee
:
public
event_based_actor
{
public:
public:
...
@@ -77,11 +79,3 @@ CAF_TEST(test_custom_exception_handler) {
...
@@ -77,11 +79,3 @@ CAF_TEST(test_custom_exception_handler) {
// receive all down messages
// receive all down messages
self
->
wait_for
(
testee1
,
testee2
,
testee3
);
self
->
wait_for
(
testee1
,
testee2
,
testee3
);
}
}
#else // CAF_NO_EXCEPTIONS
CAF_TEST
(
no_exceptions_dummy
)
{
CAF_CHECK_EQUAL
(
true
,
true
);
}
#endif // CAF_NO_EXCEPTIONS
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