Unverified Commit 0f6b0596 authored by Joseph Noir's avatar Joseph Noir Committed by GitHub

Merge pull request #732

Remove CAF_EXP_THROW and simplify CAF_RAISE_ERROR
parents a2873264 7456a997
......@@ -368,10 +368,8 @@ endif()
# configure build_config.hpp header #
################################################################################
if(CAF_LOG_LEVEL)
set(CAF_LOG_LEVEL_INT ${CAF_LOG_LEVEL})
else()
set(CAF_LOG_LEVEL_INT -1)
if(NOT CAF_LOG_LEVEL)
set(CAF_LOG_LEVEL "-1")
endif()
macro(to_int_value name)
......
......@@ -21,19 +21,11 @@
// this header is auto-generated by CMake
#if @CAF_LOG_LEVEL_INT@ != -1
#define CAF_LOG_LEVEL @CAF_LOG_LEVEL@
#endif
#if @CAF_NO_MEM_MANAGEMENT_INT@ != -1
#define CAF_NO_MEM_MANAGEMENT
#endif
#cmakedefine CAF_NO_MEM_MANAGEMENT
#if @CAF_ENABLE_RUNTIME_CHECKS_INT@ != -1
#define CAF_ENABLE_RUNTIME_CHECKS
#endif
#cmakedefine CAF_ENABLE_RUNTIME_CHECKS
#if @CAF_NO_EXCEPTIONS_INT@ != -1
#define CAF_NO_EXCEPTIONS
#endif
#cmakedefine CAF_NO_EXCEPTIONS
......@@ -88,6 +88,7 @@ set(LIBCAF_CORE_SRCS
src/pretty_type_name.cpp
src/private_thread.cpp
src/proxy_registry.cpp
src/raise_error.cpp
src/raw_event_based_actor.cpp
src/ref_counted.cpp
src/replies_to.cpp
......
......@@ -55,10 +55,11 @@
#include "caf/actor_proxy.hpp"
#include "caf/exit_reason.hpp"
#include "caf/local_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/ref_counted.hpp"
#include "caf/stream_slot.hpp"
#include "caf/thread_hook.hpp"
#include "caf/typed_actor.hpp"
#include "caf/stream_slot.hpp"
#include "caf/actor_system.hpp"
#include "caf/config_value.hpp"
#include "caf/deserializer.hpp"
......
......@@ -22,6 +22,7 @@
#include "caf/buffered_downstream_manager.hpp"
#include "caf/outbound_path.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/algorithms.hpp"
#include "caf/detail/path_state.hpp"
......
......@@ -259,12 +259,3 @@
__FILE__, __LINE__, error); \
::abort(); \
} while (false)
#ifdef CAF_NO_EXCEPTIONS
# define CAF_RAISE_ERROR(msg) \
do { std::string str = msg; CAF_CRITICAL(str.c_str()); } while (true)
#else // CAF_NO_EXCEPTIONS
# define CAF_RAISE_ERROR(msg) \
throw std::runtime_error(msg)
#endif // CAF_NO_EXCEPTIONS
......@@ -30,6 +30,7 @@
#include "caf/dictionary.hpp"
#include "caf/fwd.hpp"
#include "caf/optional.hpp"
#include "caf/raise_error.hpp"
#include "caf/string_algorithms.hpp"
#include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp"
......
......@@ -23,14 +23,9 @@
#include <utility>
#include <type_traits>
#include "caf/config.hpp"
#ifndef CAF_NO_EXCEPTIONS
#include <exception>
#endif // CAF_NO_EXCEPTIONS
#include "caf/fwd.hpp"
#include "caf/data_processor.hpp"
#include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
namespace caf {
......@@ -54,8 +49,6 @@ public:
explicit deserializer(execution_unit* x = nullptr);
};
#ifndef CAF_NO_EXCEPTIONS
template <class T>
typename std::enable_if<
std::is_same<
......@@ -66,7 +59,7 @@ typename std::enable_if<
operator&(deserializer& source, T& x) {
auto e = source.apply(x);
if (e)
CAF_RAISE_ERROR(to_string(e));
CAF_RAISE_ERROR("error during serialization (using operator&)");
}
template <class T>
......@@ -82,7 +75,5 @@ operator>>(deserializer& source, T& x) {
return source;
}
#endif // CAF_NO_EXCEPTIONS
} // namespace caf
......@@ -21,11 +21,11 @@
#include <cstddef>
#include <iterator>
#include <algorithm>
#include <stdexcept>
#include <type_traits>
#include <initializer_list>
#include "caf/config.hpp"
#include "caf/raise_error.hpp"
namespace caf {
namespace detail {
......
......@@ -21,13 +21,11 @@
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <functional>
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/raise_error.hpp"
namespace caf {
namespace detail {
......@@ -231,11 +229,8 @@ public:
mapped_type& at(const K& key) {
auto i = find(key);
if (i == end())
#ifdef CAF_NO_EXCEPTIONS
CAF_CRITICAL("caf::detail::unordered_flat_map::at out of range");
#else
throw std::out_of_range{"caf::detail::unordered_flat_map::at"};
#endif
CAF_RAISE_ERROR(std::out_of_range,
"caf::detail::unordered_flat_map::at out of range");
return i->second;
}
......
......@@ -443,18 +443,6 @@ inline std::string to_string(const expected<void>& x) {
return "!" + to_string(x.error());
}
/// @cond PRIVATE
/// Assigns the value of `expr` (which must return an `expected`)
/// to a new variable named `var` or throws a `std::runtime_error` on error.
/// @relates expected
/// @experimental
#define CAF_EXP_THROW(var, expr) \
auto CAF_UNIFYN(tmp_var_) = expr; \
if (!CAF_UNIFYN(tmp_var_)) \
CAF_RAISE_ERROR(to_string(CAF_UNIFYN(tmp_var_).error())); \
auto& var = *CAF_UNIFYN(tmp_var_)
/// @endcond
} // namespace caf
namespace std {
......
......@@ -360,7 +360,7 @@ bool operator==(const logger::field& x, const logger::field& y);
#define CAF_LOG_COMPONENT "caf"
#endif // CAF_LOG_COMPONENT
#ifndef CAF_LOG_LEVEL
#if CAF_LOG_LEVEL == -1
#define CAF_LOG_IMPL(unused1, unused2, unused3)
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* 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. *
******************************************************************************/
#pragma once
#include "caf/config.hpp"
#ifndef CAF_NO_EXCEPTIONS
#include <stdexcept>
#endif
#include "caf/detail/pp.hpp"
namespace caf {
namespace detail {
void log_cstring_error(const char* cstring);
} // namespace detail
} // namespace caf
#ifdef CAF_NO_EXCEPTIONS
#define CAF_RAISE_ERROR_IMPL_1(msg) \
do { \
::caf::detail::log_cstring_error(msg); \
CAF_CRITICAL(msg); \
} while (false)
#define CAF_RAISE_ERROR_IMPL_2(unused, msg) CAF_RAISE_ERROR_IMPL_1(msg)
#else // CAF_NO_EXCEPTIONS
#define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \
do { \
::caf::detail::log_cstring_error(msg); \
throw exception_type(msg); \
} while (false)
#define CAF_RAISE_ERROR_IMPL_1(msg) \
CAF_RAISE_ERROR_IMPL_2(std::runtime_error, msg)
#endif // CAF_NO_EXCEPTIONS
#ifdef CAF_MSVC
/// Throws an exception if `CAF_NO_EXCEPTIONS` is undefined, otherwise calls
/// abort() after printing a given message.
#define CAF_RAISE_ERROR(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, __VA_ARGS__)(__VA_ARGS__), \
CAF_PP_EMPTY())
#else // CAF_MSVC
/// Throws an exception if `CAF_NO_EXCEPTIONS` is undefined, otherwise calls
/// abort() after printing a given message.
#define CAF_RAISE_ERROR(...) \
CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, __VA_ARGS__)(__VA_ARGS__)
#endif // CAF_MSVC
......@@ -18,19 +18,18 @@
#pragma once
#include "caf/config.hpp"
#include <deque>
#include <chrono>
#include <limits>
#include <cstddef>
#include <algorithm>
#include "caf/config.hpp"
#include "caf/detail/test_actor_clock.hpp"
#include "caf/raise_error.hpp"
#include "caf/scheduled_actor.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/detail/test_actor_clock.hpp"
namespace caf {
namespace scheduler {
......
......@@ -22,14 +22,9 @@
#include <cstddef> // size_t
#include <type_traits>
#include "caf/config.hpp"
#ifndef CAF_NO_EXCEPTIONS
#include <exception>
#endif // CAF_NO_EXCEPTIONS
#include "caf/fwd.hpp"
#include "caf/data_processor.hpp"
#include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
namespace caf {
......@@ -53,8 +48,6 @@ public:
~serializer() override;
};
#ifndef CAF_NO_EXCEPTIONS
template <class T>
typename std::enable_if<
std::is_same<
......@@ -66,7 +59,7 @@ operator&(serializer& sink, const T& x) {
// implementations are required to never modify `x` while saving
auto e = sink.apply(const_cast<T&>(x));
if (e)
CAF_RAISE_ERROR(to_string(e));
CAF_RAISE_ERROR("error during serialization (using operator&)");
}
template <class T>
......@@ -82,7 +75,5 @@ operator<<(serializer& sink, const T& x) {
return sink;
}
#endif // CAF_NO_EXCEPTIONS
} // namespace caf
......@@ -25,6 +25,7 @@
#include "caf/config.hpp"
#include "caf/default_sum_type_access.hpp"
#include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
#include "caf/static_visitor.hpp"
#include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp"
......
......@@ -20,11 +20,12 @@
#include <unordered_set>
#include "caf/send.hpp"
#include "caf/to_string.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/raw_event_based_actor.hpp"
#include "caf/send.hpp"
#include "caf/to_string.hpp"
#include "caf/policy/work_sharing.hpp"
#include "caf/policy/work_stealing.hpp"
......
......@@ -16,13 +16,14 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/message.hpp"
#include "caf/make_counted.hpp"
#include "caf/detail/concatenated_tuple.hpp"
#include <numeric>
#include "caf/make_counted.hpp"
#include "caf/message.hpp"
#include "caf/raise_error.hpp"
namespace caf {
namespace detail {
......@@ -115,7 +116,7 @@ std::pair<message_data*, size_t> concatenated_tuple::select(size_t pos) const {
else
return {m.get(), idx};
}
CAF_RAISE_ERROR("out of range: concatenated_tuple::select");
CAF_RAISE_ERROR(std::out_of_range, "concatenated_tuple::select out of range");
}
} // namespace detail
......
......@@ -53,10 +53,7 @@ constexpr const char* log_level_name[] = {
"TRACE"
};
#ifdef CAF_LOG_LEVEL
static_assert(CAF_LOG_LEVEL >= 0 && CAF_LOG_LEVEL <= 4,
"assertion: 0 <= CAF_LOG_LEVEL <= 4");
#if CAF_LOG_LEVEL >= 0
#if defined(CAF_NO_THREAD_LOCAL)
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* 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. *
******************************************************************************/
#include "caf/raise_error.hpp"
#include "caf/logger.hpp"
namespace caf {
namespace detail {
void log_cstring_error(const char* cstring) {
CAF_LOG_ERROR(cstring);
}
} // namespace detail
} // namespace caf
......@@ -24,6 +24,7 @@
#include <stdexcept>
#include "caf/config.hpp"
#include "caf/raise_error.hpp"
namespace {
......@@ -56,7 +57,7 @@ string_view::const_reverse_iterator string_view::crend() const noexcept {
string_view::const_reference string_view::at(size_type pos) const {
if (pos < size_)
return data_[pos];
CAF_RAISE_ERROR("string_view::at out of range");
CAF_RAISE_ERROR(std::out_of_range, "string_view::at out of range");
}
// -- modifiers ----------------------------------------------------------------
......
......@@ -20,9 +20,10 @@
#include <limits>
#include "caf/resumable.hpp"
#include "caf/monitorable_actor.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/monitorable_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/resumable.hpp"
namespace caf {
namespace scheduler {
......
......@@ -18,8 +18,9 @@
#include "caf/type_erased_tuple.hpp"
#include "caf/error.hpp"
#include "caf/config.hpp"
#include "caf/error.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/try_match.hpp"
......
......@@ -27,6 +27,7 @@
#include "caf/default_sum_type_access.hpp"
#include "caf/detail/overload.hpp"
#include "caf/raise_error.hpp"
#include "caf/static_visitor.hpp"
#include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp"
......
......@@ -22,6 +22,7 @@
#include <unordered_map>
#include "caf/logger.hpp"
#include "caf/raise_error.hpp"
#include "caf/ref_counted.hpp"
#include "caf/io/fwd.hpp"
......
......@@ -48,8 +48,8 @@
#include <utility>
#include "caf/detail/get_mac_addresses.hpp"
#include "caf/io/network/ip_endpoint.hpp"
#include "caf/raise_error.hpp"
namespace caf {
namespace io {
......
......@@ -18,11 +18,11 @@
#include "caf/io/network/test_multiplexer.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/io/scribe.hpp"
#include "caf/io/doorman.hpp"
#include "caf/io/datagram_servant.hpp"
#include "caf/io/doorman.hpp"
#include "caf/io/scribe.hpp"
#include "caf/raise_error.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
namespace caf {
namespace io {
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_dynamic_broker
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
......@@ -151,8 +151,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system system{cfg.load<io::middleman>().parse(argc, argv)};
auto p = system.spawn(ping, size_t{10});
CAF_MESSAGE("spawn_client...");
CAF_EXP_THROW(cl, system.middleman().spawn_client(peer_fun, "127.0.0.1",
port, p));
auto cl = unbox(system.middleman().spawn_client(peer_fun,
"127.0.0.1", port, p));
CAF_MESSAGE("spawn_client finished");
anon_send(p, kickoff_atom::value, cl);
CAF_MESSAGE("`kickoff_atom` has been send");
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_dynamic_remote_actor_tcp
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <vector>
#include <sstream>
......@@ -145,14 +145,14 @@ CAF_TEST_FIXTURE_SCOPE(dynamic_remote_actor_tests, fixture)
CAF_TEST(identity_semantics_tcp) {
// server side
auto server = server_side.spawn(make_pong_behavior);
CAF_EXP_THROW(port1, server_side_mm.publish(server, 0, local_host));
CAF_EXP_THROW(port2, server_side_mm.publish(server, 0, local_host));
auto port1 = unbox(server_side_mm.publish(server, 0, local_host));
auto port2 = unbox(server_side_mm.publish(server, 0, local_host));
CAF_REQUIRE_NOT_EQUAL(port1, port2);
CAF_EXP_THROW(same_server, server_side_mm.remote_actor(local_host, port2));
auto same_server = unbox(server_side_mm.remote_actor(local_host, port2));
CAF_REQUIRE_EQUAL(same_server, server);
CAF_CHECK_EQUAL(same_server->node(), server_side.node());
CAF_EXP_THROW(server1, client_side_mm.remote_actor(local_host, port1));
CAF_EXP_THROW(server2, client_side_mm.remote_actor(local_host, port2));
auto server1 = unbox(client_side_mm.remote_actor(local_host, port1));
auto server2 = unbox(client_side_mm.remote_actor(local_host, port2));
CAF_CHECK_EQUAL(server1, client_side_mm.remote_actor(local_host, port1));
CAF_CHECK_EQUAL(server2, client_side_mm.remote_actor(local_host, port2));
anon_send_exit(server, exit_reason::user_shutdown);
......@@ -160,29 +160,28 @@ CAF_TEST(identity_semantics_tcp) {
CAF_TEST(ping_pong_tcp) {
// server side
CAF_EXP_THROW(port,
server_side_mm.publish(server_side.spawn(make_pong_behavior),
0, local_host));
auto port = unbox(server_side_mm.publish(
server_side.spawn(make_pong_behavior), 0, local_host));
// client side
CAF_EXP_THROW(pong, client_side_mm.remote_actor(local_host, port));
auto pong = unbox(client_side_mm.remote_actor(local_host, port));
client_side.spawn(make_ping_behavior, pong);
}
CAF_TEST(custom_message_type_tcp) {
// server side
CAF_EXP_THROW(port, server_side_mm.publish(server_side.spawn(make_sort_behavior),
0, local_host));
auto port = unbox(server_side_mm.publish(
server_side.spawn(make_sort_behavior), 0, local_host));
// client side
CAF_EXP_THROW(sorter, client_side_mm.remote_actor(local_host, port));
auto sorter = unbox(client_side_mm.remote_actor(local_host, port));
client_side.spawn(make_sort_requester_behavior, sorter);
}
CAF_TEST(remote_link_tcp) {
// server side
CAF_EXP_THROW(port, server_side_mm.publish(server_side.spawn(fragile_mirror),
0, local_host));
auto port = unbox(
server_side_mm.publish(server_side.spawn(fragile_mirror), 0, local_host));
// client side
CAF_EXP_THROW(mirror, client_side_mm.remote_actor(local_host, port));
auto mirror = unbox(client_side_mm.remote_actor(local_host, port));
auto linker = client_side.spawn(linking_actor, mirror);
scoped_actor self{client_side};
self->wait_for(linker);
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_dynamic_remote_actor_udp
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <vector>
#include <sstream>
......@@ -146,14 +146,14 @@ CAF_TEST_FIXTURE_SCOPE(dynamic_remote_actor_tests_udp, fixture)
CAF_TEST(identity_semantics_udp) {
// server side
auto server = server_side.spawn(make_pong_behavior);
CAF_EXP_THROW(port1, server_side_mm.publish_udp(server, 0, local_host));
CAF_EXP_THROW(port2, server_side_mm.publish_udp(server, 0, local_host));
auto port1 = unbox(server_side_mm.publish_udp(server, 0, local_host));
auto port2 = unbox(server_side_mm.publish_udp(server, 0, local_host));
CAF_REQUIRE_NOT_EQUAL(port1, port2);
CAF_EXP_THROW(same_server, server_side_mm.remote_actor_udp(local_host, port2));
auto same_server = unbox(server_side_mm.remote_actor_udp(local_host, port2));
CAF_REQUIRE_EQUAL(same_server, server);
CAF_CHECK_EQUAL(same_server->node(), server_side.node());
CAF_EXP_THROW(server1, client_side_mm.remote_actor_udp(local_host, port1));
CAF_EXP_THROW(server2, client_side_mm.remote_actor_udp(local_host, port2));
auto server1 = unbox(client_side_mm.remote_actor_udp(local_host, port1));
auto server2 = unbox(client_side_mm.remote_actor_udp(local_host, port2));
CAF_CHECK_EQUAL(server1, client_side_mm.remote_actor_udp(local_host, port1));
CAF_CHECK_EQUAL(server2, client_side_mm.remote_actor_udp(local_host, port2));
anon_send_exit(server, exit_reason::user_shutdown);
......@@ -161,31 +161,28 @@ CAF_TEST(identity_semantics_udp) {
CAF_TEST(ping_pong_udp) {
// server side
CAF_EXP_THROW(port,
server_side_mm.publish_udp(server_side.spawn(make_pong_behavior),
0, local_host));
auto port = unbox(server_side_mm.publish_udp(
server_side.spawn(make_pong_behavior), 0, local_host));
// client side
CAF_EXP_THROW(pong, client_side_mm.remote_actor_udp(local_host, port));
auto pong = unbox(client_side_mm.remote_actor_udp(local_host, port));
client_side.spawn(make_ping_behavior, pong);
}
CAF_TEST(custom_message_type_udp) {
// server side
CAF_EXP_THROW(port,
server_side_mm.publish_udp(server_side.spawn(make_sort_behavior),
0, local_host));
auto port = unbox(server_side_mm.publish_udp(
server_side.spawn(make_sort_behavior), 0, local_host));
// client side
CAF_EXP_THROW(sorter, client_side_mm.remote_actor_udp(local_host, port));
auto sorter = unbox(client_side_mm.remote_actor_udp(local_host, port));
client_side.spawn(make_sort_requester_behavior, sorter);
}
CAF_TEST(remote_link_udp) {
// server side
CAF_EXP_THROW(port,
server_side_mm.publish_udp(server_side.spawn(fragile_mirror),
0, local_host));
auto port = unbox(server_side_mm.publish_udp(
server_side.spawn(fragile_mirror), 0, local_host));
// client side
CAF_EXP_THROW(mirror, client_side_mm.remote_actor_udp(local_host, port));
auto mirror = unbox(client_side_mm.remote_actor_udp(local_host, port));
auto linker = client_side.spawn(linking_actor, mirror);
scoped_actor self{client_side};
self->wait_for(linker);
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_remote_spawn
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <thread>
#include <string>
......@@ -82,7 +82,10 @@ void run_client(int argc, char** argv, uint16_t port) {
CAF_REQUIRE(nid);
CAF_REQUIRE_NOT_EQUAL(system.node(), *nid);
auto calc = mm.remote_spawn<calculator>(*nid, "calculator", make_message());
CAF_REQUIRE_EQUAL(calc, sec::unexpected_actor_messaging_interface);
CAF_REQUIRE(!calc);
CAF_REQUIRE_EQUAL(calc.error().category(), atom("system"));
CAF_REQUIRE_EQUAL(static_cast<sec>(calc.error().code()),
sec::unexpected_actor_messaging_interface);
calc = mm.remote_spawn<calculator>(*nid, "typed_calculator", make_message());
CAF_REQUIRE(calc);
auto f1 = make_function_view(*calc);
......@@ -96,7 +99,7 @@ void run_client(int argc, char** argv, uint16_t port) {
void run_server(int argc, char** argv) {
config cfg{argc, argv};
actor_system system{cfg};
CAF_EXP_THROW(port, system.middleman().open(0));
auto port = unbox(system.middleman().open(0));
std::thread child{[=] { run_client(argc, argv, port); }};
child.join();
}
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_typed_broker
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <memory>
#include <iostream>
......@@ -167,8 +167,8 @@ void run_client(int argc, char** argv, uint16_t port) {
actor_system system{cfg.load<io::middleman>().parse(argc, argv)};
auto p = system.spawn(ping, size_t{10});
CAF_MESSAGE("spawn_client_typed...");
CAF_EXP_THROW(cl, system.middleman().spawn_client(peer_fun, "localhost",
port, p));
auto cl = unbox(system.middleman().spawn_client(peer_fun,
"localhost", port, p));
CAF_MESSAGE("spawn_client_typed finished");
anon_send(p, kickoff_atom::value, cl);
CAF_MESSAGE("`kickoff_atom` has been send");
......
......@@ -79,16 +79,15 @@ void run_client(int argc, char** argv, uint16_t port) {
.add_message_type<ping>("ping")
.add_message_type<pong>("pong")
.parse(argc, argv);
actor_system system{cfg};
actor_system sys{cfg};
// check whether invalid_argument is thrown
// when trying to connect to get an untyped
// handle to the server
auto res = system.middleman().remote_actor("127.0.0.1", port);
auto res = sys.middleman().remote_actor("127.0.0.1", port);
CAF_REQUIRE(!res);
CAF_MESSAGE(system.render(res.error()));
CAF_MESSAGE(sys.render(res.error()));
CAF_MESSAGE("connect to typed_remote_actor");
CAF_EXP_THROW(serv,
system.middleman().remote_actor<server_type>("127.0.0.1",
auto serv = unbox(sys.middleman().remote_actor<server_type>("127.0.0.1",
port));
auto f = make_function_view(serv);
CAF_CHECK_EQUAL(f(ping{42}), pong{42});
......@@ -101,9 +100,8 @@ void run_server(int argc, char** argv) {
.add_message_type<ping>("ping")
.add_message_type<pong>("pong")
.parse(argc, argv);
actor_system system{cfg};
CAF_EXP_THROW(port, system.middleman().publish(system.spawn(server),
0, "127.0.0.1"));
actor_system sys{cfg};
auto port = unbox(sys.middleman().publish(sys.spawn(server), 0, "127.0.0.1"));
CAF_REQUIRE(port != 0);
CAF_MESSAGE("running on port " << port << ", start client");
std::thread child{[=] { run_client(argc, argv, port); }};
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE io_unpublish
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <new>
#include <thread>
......@@ -100,7 +100,7 @@ struct fixture {
CAF_TEST_FIXTURE_SCOPE(unpublish_tests, fixture)
CAF_TEST(unpublishing) {
CAF_EXP_THROW(port, system.middleman().publish(testee, 0));
auto port = unbox(system.middleman().publish(testee, 0));
CAF_REQUIRE(port != 0);
CAF_MESSAGE("published actor on port " << port);
CAF_MESSAGE("test invalid unpublish");
......
......@@ -26,6 +26,7 @@
#include "caf/all.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/raw_ptr.hpp"
#include "caf/detail/command_helper.hpp"
......@@ -84,20 +85,14 @@ public:
const char* kernel_name, const nd_range& range,
input_mapping map_args, output_mapping map_result,
Ts&&... xs) {
if (range.dimensions().empty()) {
auto str = "OpenCL kernel needs at least 1 global dimension.";
CAF_RAISE_ERROR(str);
}
auto check_vec = [&](const dim_vec& vec, const char* name) {
if (! vec.empty() && vec.size() != range.dimensions().size()) {
std::ostringstream oss;
oss << name << " vector is not empty, but "
<< "its size differs from global dimensions vector's size";
CAF_RAISE_ERROR(oss.str());
}
if (range.dimensions().empty())
CAF_RAISE_ERROR("OpenCL kernel needs at least 1 global dimension");
auto check_vec = [&](const dim_vec& vec) {
if (!vec.empty() && vec.size() != range.dimensions().size())
CAF_RAISE_ERROR("illegal vector size");
};
check_vec(range.offsets(), "offsets");
check_vec(range.local_dimensions(), "local dimensions");
check_vec(range.offsets());
check_vec(range.local_dimensions());
auto& sys = actor_conf.host->system();
auto itr = prog->available_kernels_.find(kernel_name);
if (itr == prog->available_kernels_.end()) {
......
......@@ -24,9 +24,10 @@
#include <algorithm>
#include <functional>
#include "caf/logger.hpp"
#include "caf/actor_cast.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/actor_cast.hpp"
#include "caf/logger.hpp"
#include "caf/raise_error.hpp"
#include "caf/response_promise.hpp"
#include "caf/detail/raw_ptr.hpp"
......@@ -194,7 +195,7 @@ private:
events.data(), &events.back());
if (err != CL_SUCCESS) {
this->deref(); // failed to enqueue command
CAF_RAISE_ERROR("clEnqueueReadBuffer: " + opencl_error(err));
CAF_RAISE_ERROR("failed to enqueue command");
}
pos += 1;
}
......
......@@ -20,6 +20,7 @@
#include <fstream>
#include "caf/detail/type_list.hpp"
#include "caf/raise_error.hpp"
#include "caf/opencl/device.hpp"
#include "caf/opencl/manager.hpp"
......@@ -95,10 +96,7 @@ program_ptr manager::create_program_from_file(const char* path,
static_cast<streamsize>(kernel_source.size()));
read_source.close();
} else {
ostringstream oss;
oss << "No file at '" << path << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
CAF_RAISE_ERROR("create_program_from_file: path not found");
}
return create_program(kernel_source.c_str(), options, device_id);
}
......@@ -108,10 +106,7 @@ program_ptr manager::create_program(const char* kernel_source,
uint32_t device_id) {
auto dev = find_device(device_id);
if (!dev) {
ostringstream oss;
oss << "No device with id '" << device_id << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
CAF_RAISE_ERROR("create_program: no device found");
}
return create_program(kernel_source, options, *dev);
}
......@@ -129,10 +124,7 @@ program_ptr manager::create_program_from_file(const char* path,
static_cast<streamsize>(kernel_source.size()));
read_source.close();
} else {
ostringstream oss;
oss << "No file at '" << path << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
CAF_RAISE_ERROR("create_program_from_file: path not found");
}
return create_program(kernel_source.c_str(), options, dev);
}
......@@ -150,8 +142,6 @@ program_ptr manager::create_program(const char* kernel_source,
auto dev_tmp = dev->device_id_.get();
auto err = clBuildProgram(pptr.get(), 1, &dev_tmp, options, nullptr, nullptr);
if (err != CL_SUCCESS) {
ostringstream oss;
oss << "clBuildProgram: " << opencl_error(err);
if (err == CL_BUILD_PROGRAM_FAILURE) {
size_t buildlog_buffer_size = 0;
// get the log length
......@@ -169,12 +159,11 @@ program_ptr manager::create_program(const char* kernel_source,
// seems that just apple implemented the
// pfn_notify callback, but we can get
// the build log
#ifndef __APPLE__
#ifndef CAF_MACOS
CAF_LOG_ERROR(CAF_ARG(ss.str()));
#endif
oss << endl << ss.str();
}
CAF_RAISE_ERROR(oss.str());
CAF_RAISE_ERROR("clBuildProgram failed");
}
cl_uint number_of_kernels = 0;
clCreateKernelsInProgram(pptr.get(), 0u, nullptr, &number_of_kernels);
......@@ -183,23 +172,16 @@ program_ptr manager::create_program(const char* kernel_source,
vector<cl_kernel> kernels(number_of_kernels);
err = clCreateKernelsInProgram(pptr.get(), number_of_kernels,
kernels.data(), nullptr);
if (err != CL_SUCCESS) {
ostringstream oss;
oss << "clCreateKernelsInProgram: " << opencl_error(err);
CAF_RAISE_ERROR(oss.str());
}
if (err != CL_SUCCESS)
CAF_RAISE_ERROR("clCreateKernelsInProgram failed");
for (cl_uint i = 0; i < number_of_kernels; ++i) {
size_t len;
clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, 0, nullptr, &len);
vector<char> name(len);
err = clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, len,
reinterpret_cast<void*>(name.data()), nullptr);
if (err != CL_SUCCESS) {
ostringstream oss;
oss << "clGetKernelInfo (CL_KERNEL_FUNCTION_NAME): "
<< opencl_error(err);
CAF_RAISE_ERROR(oss.str());
}
if (err != CL_SUCCESS)
CAF_RAISE_ERROR("clGetKernelInfo failed");
detail::raw_kernel_ptr kernel;
kernel.reset(move(kernels[i]));
available_kernels.emplace(string(name.data()), move(kernel));
......
......@@ -17,17 +17,16 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/opencl/opencl_err.hpp"
#include "caf/opencl/opencl_err.hpp"
#include "caf/logger.hpp"
namespace caf {
namespace opencl {
void throwcl(const char* fname, cl_int err) {
void throwcl(const char*, cl_int err) {
if (err != CL_SUCCESS) {
std::string errstr = fname;
errstr += ": ";
errstr += opencl_error(err);
CAF_RAISE_ERROR(std::move(errstr));
CAF_RAISE_ERROR("throwcl: unrecoverable OpenCL error");
}
}
......@@ -35,7 +34,7 @@ void CL_CALLBACK pfn_notify(const char* errinfo, const void*, size_t, void*) {
CAF_LOG_ERROR("\n##### Error message via pfn_notify #####\n"
<< errinfo <<
"\n########################################");
static_cast<void>(errinfo); // remove warning
CAF_IGNORE_UNUSED(errinfo);
}
} // namespace opencl
......
......@@ -63,11 +63,8 @@ platform_ptr platform::create(cl_platform_id platform_id,
device_information.push_back(device::create(context, device_id,
start_id++));
}
if (device_information.empty()) {
string errstr = "no devices for the platform found";
CAF_LOG_ERROR(CAF_ARG(errstr));
CAF_RAISE_ERROR(move(errstr));
}
if (device_information.empty())
CAF_RAISE_ERROR("no devices for the platform found");
auto name = platform_info(platform_id, CL_PLATFORM_NAME);
auto vendor = platform_info(platform_id, CL_PLATFORM_VENDOR);
auto version = platform_info(platform_id, CL_PLATFORM_VERSION);
......
......@@ -161,11 +161,13 @@ constexpr const char* kernel_source = R"__(
}
)__";
#ifndef CAF_NO_EXCEPTIONS
constexpr const char* kernel_source_error = R"__(
kernel void missing(global int*) {
size_t semicolon_missing
}
)__";
#endif // CAF_NO_EXCEPTIONS
constexpr const char* kernel_source_compiler_flag = R"__(
kernel void compiler_flag(global const int* restrict input,
......@@ -398,19 +400,15 @@ void test_opencl(actor_system& sys) {
expected2.data(), result.data());
}, others >> wrong_msg
);
#ifndef CAF_NO_EXCEPTIONS
CAF_MESSAGE("Expecting exception (compiling invalid kernel, "
"semicolon is missing).");
try {
/* auto expected_error = */ mngr.create_program(kernel_source_error);
} catch (const exception& exc) {
std::string starts_with("clBuildProgram: CL_BUILD_PROGRAM_FAILURE");
auto cond = (strncmp(exc.what(), starts_with.c_str(),
starts_with.size()) == 0);
CAF_CHECK(cond);
if (!cond)
CAF_ERROR("Wrong exception cought for program build failure.");
CAF_MESSAGE("got: " << exc.what());
}
#endif // CAF_NO_EXCEPTIONS
// create program with opencl compiler flags
auto prog5 = mngr.create_program(kernel_source_compiler_flag, compiler_flag);
opencl::nd_range range5{dims{array_size}};
......
......@@ -65,7 +65,6 @@ private:
size_t len, const char* debug_name);
SSL_CTX* create_ssl_context();
std::string get_ssl_error();
void raise_ssl_error(std::string msg);
bool handle_ssl_result(int ret);
actor_system& sys_;
......
......@@ -26,11 +26,12 @@ CAF_POP_WARNINGS
#include <vector>
#include <mutex>
#include "caf/expected.hpp"
#include "caf/actor_system.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/expected.hpp"
#include "caf/raise_error.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/io/middleman.hpp"
#include "caf/io/basp_broker.hpp"
......
......@@ -209,7 +209,7 @@ SSL_CTX* session::create_ssl_context() {
auto ctx = SSL_CTX_new(TLSv1_2_method());
#endif
if (!ctx)
raise_ssl_error("cannot create OpenSSL context");
CAF_RAISE_ERROR("cannot create OpenSSL context");
if (sys_.openssl_manager().authentication_enabled()) {
// Require valid certificates on both sides.
auto& cfg = sys_.config();
......@@ -217,7 +217,7 @@ SSL_CTX* session::create_ssl_context() {
&& SSL_CTX_use_certificate_chain_file(ctx,
cfg.openssl_certificate.c_str())
!= 1)
raise_ssl_error("cannot load certificate");
CAF_RAISE_ERROR("cannot load certificate");
if (cfg.openssl_passphrase.size() > 0) {
openssl_passphrase_ = cfg.openssl_passphrase;
SSL_CTX_set_default_passwd_cb(ctx, pem_passwd_cb);
......@@ -227,19 +227,19 @@ SSL_CTX* session::create_ssl_context() {
&& SSL_CTX_use_PrivateKey_file(ctx, cfg.openssl_key.c_str(),
SSL_FILETYPE_PEM)
!= 1)
raise_ssl_error("cannot load private key");
CAF_RAISE_ERROR("cannot load private key");
auto cafile =
(cfg.openssl_cafile.size() > 0 ? cfg.openssl_cafile.c_str() : nullptr);
auto capath =
(cfg.openssl_capath.size() > 0 ? cfg.openssl_capath.c_str() : nullptr);
if (cafile || capath) {
if (SSL_CTX_load_verify_locations(ctx, cafile, capath) != 1)
raise_ssl_error("cannot load trusted CA certificates");
CAF_RAISE_ERROR("cannot load trusted CA certificates");
}
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
nullptr);
if (SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!MD5") != 1)
raise_ssl_error("cannot set cipher list");
CAF_RAISE_ERROR("cannot set cipher list");
} else {
// No authentication.
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nullptr);
......@@ -248,7 +248,7 @@ SSL_CTX* session::create_ssl_context() {
#else
auto ecdh = EC_KEY_new_by_curve_name(NID_secp384r1);
if (!ecdh)
raise_ssl_error("cannot get ECDH curve");
CAF_RAISE_ERROR("cannot get ECDH curve");
CAF_PUSH_WARNINGS
SSL_CTX_set_tmp_ecdh(ctx, ecdh);
EC_KEY_free(ecdh);
......@@ -260,7 +260,7 @@ SSL_CTX* session::create_ssl_context() {
const char* cipher = "AECDH-AES256-SHA";
#endif
if (SSL_CTX_set_cipher_list(ctx, cipher) != 1)
raise_ssl_error("cannot set anonymous cipher");
CAF_RAISE_ERROR("cannot set anonymous cipher");
}
return ctx;
}
......@@ -277,10 +277,6 @@ std::string session::get_ssl_error() {
return msg;
}
void session::raise_ssl_error(std::string msg) {
CAF_RAISE_ERROR(std::string("[OpenSSL] ") + msg + ": " + get_ssl_error());
}
bool session::handle_ssl_result(int ret) {
auto err = SSL_get_error(ssl_, ret);
switch (err) {
......
......@@ -19,7 +19,7 @@
#include "caf/config.hpp"
#define CAF_SUITE openssl_authentication
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#ifndef CAF_WINDOWS
# include <unistd.h>
......@@ -206,12 +206,12 @@ CAF_TEST(authentication_success) {
exec_loop();
CAF_MESSAGE("publish pong");
loop_after_next_enqueue(server_side);
CAF_EXP_THROW(port, publish(spong, 0, local_host));
auto port = unbox(publish(spong, 0, local_host));
exec_loop();
// client side
CAF_MESSAGE("connect to pong via port " << port);
loop_after_next_enqueue(client_side);
CAF_EXP_THROW(pong, remote_actor(client_side, local_host, port));
auto pong = unbox(remote_actor(client_side, local_host, port));
CAF_MESSAGE("spawn ping and exchange messages");
auto sping = client_side.spawn(make_ping_behavior, pong);
while (!terminated(sping))
......@@ -230,7 +230,7 @@ CAF_TEST(authentication_failure) {
exec_loop();
loop_after_next_enqueue(server_side);
CAF_MESSAGE("publish pong");
CAF_EXP_THROW(port, publish(spong, 0, local_host));
auto port = unbox(publish(spong, 0, local_host));
exec_loop();
// client side
CAF_MESSAGE("connect to pong via port " << port);
......
......@@ -21,7 +21,7 @@
#include <signal.h>
#define CAF_SUITE openssl_dynamic_remote_actor
#include "caf/test/unit_test.hpp"
#include "caf/test/dsl.hpp"
#include <vector>
#include <sstream>
......@@ -151,14 +151,14 @@ using openssl::publish;
CAF_TEST(identity_semantics) {
// server side
auto server = server_side.spawn(make_pong_behavior);
CAF_EXP_THROW(port1, publish(server, 0, local_host));
CAF_EXP_THROW(port2, publish(server, 0, local_host));
auto port1 = unbox(publish(server, 0, local_host));
auto port2 = unbox(publish(server, 0, local_host));
CAF_REQUIRE_NOT_EQUAL(port1, port2);
CAF_EXP_THROW(same_server, remote_actor(server_side, local_host, port2));
auto same_server = unbox(remote_actor(server_side, local_host, port2));
CAF_REQUIRE_EQUAL(same_server, server);
CAF_CHECK_EQUAL(same_server->node(), server_side.node());
CAF_EXP_THROW(server1, remote_actor(client_side, local_host, port1));
CAF_EXP_THROW(server2, remote_actor(client_side, local_host, port2));
auto server1 = unbox(remote_actor(client_side, local_host, port1));
auto server2 = unbox(remote_actor(client_side, local_host, port2));
CAF_CHECK_EQUAL(server1, remote_actor(client_side, local_host, port1));
CAF_CHECK_EQUAL(server2, remote_actor(client_side, local_host, port2));
anon_send_exit(server, exit_reason::user_shutdown);
......@@ -166,28 +166,27 @@ CAF_TEST(identity_semantics) {
CAF_TEST(ping_pong) {
// server side
CAF_EXP_THROW(port,
publish(server_side.spawn(make_pong_behavior), 0, local_host));
auto port = unbox(publish(server_side.spawn(make_pong_behavior),
0, local_host));
// client side
CAF_EXP_THROW(pong, remote_actor(client_side, local_host, port));
auto pong = unbox(remote_actor(client_side, local_host, port));
client_side.spawn(make_ping_behavior, pong);
}
CAF_TEST(custom_message_type) {
// server side
CAF_EXP_THROW(port,
publish(server_side.spawn(make_sort_behavior), 0, local_host));
auto port = unbox(publish(server_side.spawn(make_sort_behavior),
0, local_host));
// client side
CAF_EXP_THROW(sorter, remote_actor(client_side, local_host, port));
auto sorter = unbox(remote_actor(client_side, local_host, port));
client_side.spawn(make_sort_requester_behavior, sorter);
}
CAF_TEST(remote_link) {
// server side
CAF_EXP_THROW(port,
publish(server_side.spawn(fragile_mirror), 0, local_host));
auto port = unbox(publish(server_side.spawn(fragile_mirror), 0, local_host));
// client side
CAF_EXP_THROW(mirror, remote_actor(client_side, local_host, port));
auto mirror = unbox(remote_actor(client_side, local_host, port));
auto linker = client_side.spawn(linking_actor, mirror);
scoped_actor self{client_side};
self->wait_for(linker);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment