Commit 423f372e authored by Dominik Charousset's avatar Dominik Charousset

Move CAF_RAISE_ERROR to its own header

Improve the utility macro by (1) allowing users to specify the exception
type, and (2) always log the exception text as error.
parent 175c195a
...@@ -88,6 +88,7 @@ set(LIBCAF_CORE_SRCS ...@@ -88,6 +88,7 @@ set(LIBCAF_CORE_SRCS
src/pretty_type_name.cpp src/pretty_type_name.cpp
src/private_thread.cpp src/private_thread.cpp
src/proxy_registry.cpp src/proxy_registry.cpp
src/raise_error.cpp
src/raw_event_based_actor.cpp src/raw_event_based_actor.cpp
src/ref_counted.cpp src/ref_counted.cpp
src/replies_to.cpp src/replies_to.cpp
......
...@@ -55,10 +55,11 @@ ...@@ -55,10 +55,11 @@
#include "caf/actor_proxy.hpp" #include "caf/actor_proxy.hpp"
#include "caf/exit_reason.hpp" #include "caf/exit_reason.hpp"
#include "caf/local_actor.hpp" #include "caf/local_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/ref_counted.hpp" #include "caf/ref_counted.hpp"
#include "caf/stream_slot.hpp"
#include "caf/thread_hook.hpp" #include "caf/thread_hook.hpp"
#include "caf/typed_actor.hpp" #include "caf/typed_actor.hpp"
#include "caf/stream_slot.hpp"
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/config_value.hpp" #include "caf/config_value.hpp"
#include "caf/deserializer.hpp" #include "caf/deserializer.hpp"
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "caf/buffered_downstream_manager.hpp" #include "caf/buffered_downstream_manager.hpp"
#include "caf/outbound_path.hpp" #include "caf/outbound_path.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/algorithms.hpp" #include "caf/detail/algorithms.hpp"
#include "caf/detail/path_state.hpp" #include "caf/detail/path_state.hpp"
......
...@@ -259,12 +259,3 @@ ...@@ -259,12 +259,3 @@
__FILE__, __LINE__, error); \ __FILE__, __LINE__, error); \
::abort(); \ ::abort(); \
} while (false) } while (false)
#ifdef CAF_NO_EXCEPTIONS
# define CAF_RAISE_ERROR(msg) \
CAF_CRITICAL(msg)
#else // CAF_NO_EXCEPTIONS
# define CAF_RAISE_ERROR(msg) \
throw std::runtime_error(msg)
#endif // CAF_NO_EXCEPTIONS
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "caf/dictionary.hpp" #include "caf/dictionary.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/raise_error.hpp"
#include "caf/string_algorithms.hpp" #include "caf/string_algorithms.hpp"
#include "caf/sum_type.hpp" #include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp" #include "caf/sum_type_access.hpp"
......
...@@ -23,14 +23,9 @@ ...@@ -23,14 +23,9 @@
#include <utility> #include <utility>
#include <type_traits> #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/data_processor.hpp"
#include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
#include <cstddef> #include <cstddef>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <stdexcept>
#include <type_traits> #include <type_traits>
#include <initializer_list> #include <initializer_list>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
......
...@@ -21,13 +21,11 @@ ...@@ -21,13 +21,11 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <stdexcept>
#include <functional> #include <functional>
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp" #include "caf/detail/comparable.hpp"
#include "caf/detail/type_traits.hpp" #include "caf/detail/type_traits.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
...@@ -231,7 +229,8 @@ public: ...@@ -231,7 +229,8 @@ public:
mapped_type& at(const K& key) { mapped_type& at(const K& key) {
auto i = find(key); auto i = find(key);
if (i == end()) if (i == end())
CAF_RAISE_ERROR("caf::detail::unordered_flat_map::at out of range"); CAF_RAISE_ERROR(std::out_of_range,
"caf::detail::unordered_flat_map::at out of range");
return i->second; return i->second;
} }
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 @@ ...@@ -18,19 +18,18 @@
#pragma once #pragma once
#include "caf/config.hpp"
#include <deque> #include <deque>
#include <chrono> #include <chrono>
#include <limits> #include <limits>
#include <cstddef> #include <cstddef>
#include <algorithm> #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/scheduled_actor.hpp"
#include "caf/scheduler/abstract_coordinator.hpp" #include "caf/scheduler/abstract_coordinator.hpp"
#include "caf/detail/test_actor_clock.hpp"
namespace caf { namespace caf {
namespace scheduler { namespace scheduler {
......
...@@ -22,14 +22,9 @@ ...@@ -22,14 +22,9 @@
#include <cstddef> // size_t #include <cstddef> // size_t
#include <type_traits> #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/data_processor.hpp"
#include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/default_sum_type_access.hpp" #include "caf/default_sum_type_access.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/raise_error.hpp"
#include "caf/static_visitor.hpp" #include "caf/static_visitor.hpp"
#include "caf/sum_type.hpp" #include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp" #include "caf/sum_type_access.hpp"
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
#include <unordered_set> #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/actor_system_config.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/raw_event_based_actor.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_sharing.hpp"
#include "caf/policy/work_stealing.hpp" #include "caf/policy/work_stealing.hpp"
......
...@@ -16,13 +16,14 @@ ...@@ -16,13 +16,14 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#include "caf/message.hpp"
#include "caf/make_counted.hpp"
#include "caf/detail/concatenated_tuple.hpp" #include "caf/detail/concatenated_tuple.hpp"
#include <numeric> #include <numeric>
#include "caf/make_counted.hpp"
#include "caf/message.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
namespace detail { namespace detail {
...@@ -115,7 +116,7 @@ std::pair<message_data*, size_t> concatenated_tuple::select(size_t pos) const { ...@@ -115,7 +116,7 @@ std::pair<message_data*, size_t> concatenated_tuple::select(size_t pos) const {
else else
return {m.get(), idx}; 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 } // namespace detail
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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 @@ ...@@ -24,6 +24,7 @@
#include <stdexcept> #include <stdexcept>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/raise_error.hpp"
namespace { namespace {
...@@ -56,7 +57,7 @@ string_view::const_reverse_iterator string_view::crend() const noexcept { ...@@ -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 { string_view::const_reference string_view::at(size_type pos) const {
if (pos < size_) if (pos < size_)
return data_[pos]; 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 ---------------------------------------------------------------- // -- modifiers ----------------------------------------------------------------
......
...@@ -20,9 +20,10 @@ ...@@ -20,9 +20,10 @@
#include <limits> #include <limits>
#include "caf/resumable.hpp"
#include "caf/monitorable_actor.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/monitorable_actor.hpp"
#include "caf/raise_error.hpp"
#include "caf/resumable.hpp"
namespace caf { namespace caf {
namespace scheduler { namespace scheduler {
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
#include "caf/type_erased_tuple.hpp" #include "caf/type_erased_tuple.hpp"
#include "caf/error.hpp"
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/error.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/try_match.hpp" #include "caf/detail/try_match.hpp"
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "caf/default_sum_type_access.hpp" #include "caf/default_sum_type_access.hpp"
#include "caf/detail/overload.hpp" #include "caf/detail/overload.hpp"
#include "caf/raise_error.hpp"
#include "caf/static_visitor.hpp" #include "caf/static_visitor.hpp"
#include "caf/sum_type.hpp" #include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp" #include "caf/sum_type_access.hpp"
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <unordered_map> #include <unordered_map>
#include "caf/logger.hpp" #include "caf/logger.hpp"
#include "caf/raise_error.hpp"
#include "caf/ref_counted.hpp" #include "caf/ref_counted.hpp"
#include "caf/io/fwd.hpp" #include "caf/io/fwd.hpp"
......
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
#include <utility> #include <utility>
#include "caf/detail/get_mac_addresses.hpp" #include "caf/detail/get_mac_addresses.hpp"
#include "caf/io/network/ip_endpoint.hpp" #include "caf/io/network/ip_endpoint.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
namespace io { namespace io {
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
#include "caf/io/network/test_multiplexer.hpp" #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/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 caf {
namespace io { namespace io {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "caf/all.hpp" #include "caf/all.hpp"
#include "caf/intrusive_ptr.hpp" #include "caf/intrusive_ptr.hpp"
#include "caf/raise_error.hpp"
#include "caf/detail/raw_ptr.hpp" #include "caf/detail/raw_ptr.hpp"
#include "caf/detail/command_helper.hpp" #include "caf/detail/command_helper.hpp"
...@@ -84,20 +85,14 @@ public: ...@@ -84,20 +85,14 @@ public:
const char* kernel_name, const nd_range& range, const char* kernel_name, const nd_range& range,
input_mapping map_args, output_mapping map_result, input_mapping map_args, output_mapping map_result,
Ts&&... xs) { Ts&&... xs) {
if (range.dimensions().empty()) { if (range.dimensions().empty())
auto str = "OpenCL kernel needs at least 1 global dimension."; CAF_RAISE_ERROR("OpenCL kernel needs at least 1 global dimension");
CAF_RAISE_ERROR(str); auto check_vec = [&](const dim_vec& vec) {
} if (!vec.empty() && vec.size() != range.dimensions().size())
auto check_vec = [&](const dim_vec& vec, const char* name) { CAF_RAISE_ERROR("illegal vector size");
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());
}
}; };
check_vec(range.offsets(), "offsets"); check_vec(range.offsets());
check_vec(range.local_dimensions(), "local dimensions"); check_vec(range.local_dimensions());
auto& sys = actor_conf.host->system(); auto& sys = actor_conf.host->system();
auto itr = prog->available_kernels_.find(kernel_name); auto itr = prog->available_kernels_.find(kernel_name);
if (itr == prog->available_kernels_.end()) { if (itr == prog->available_kernels_.end()) {
......
...@@ -24,9 +24,10 @@ ...@@ -24,9 +24,10 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include "caf/logger.hpp"
#include "caf/actor_cast.hpp"
#include "caf/abstract_actor.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/response_promise.hpp"
#include "caf/detail/raw_ptr.hpp" #include "caf/detail/raw_ptr.hpp"
...@@ -194,7 +195,7 @@ private: ...@@ -194,7 +195,7 @@ private:
events.data(), &events.back()); events.data(), &events.back());
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
this->deref(); // failed to enqueue command this->deref(); // failed to enqueue command
CAF_RAISE_ERROR("clEnqueueReadBuffer: " + opencl_error(err)); CAF_RAISE_ERROR("failed to enqueue command");
} }
pos += 1; pos += 1;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <fstream> #include <fstream>
#include "caf/detail/type_list.hpp" #include "caf/detail/type_list.hpp"
#include "caf/raise_error.hpp"
#include "caf/opencl/device.hpp" #include "caf/opencl/device.hpp"
#include "caf/opencl/manager.hpp" #include "caf/opencl/manager.hpp"
...@@ -95,10 +96,7 @@ program_ptr manager::create_program_from_file(const char* path, ...@@ -95,10 +96,7 @@ program_ptr manager::create_program_from_file(const char* path,
static_cast<streamsize>(kernel_source.size())); static_cast<streamsize>(kernel_source.size()));
read_source.close(); read_source.close();
} else { } else {
ostringstream oss; CAF_RAISE_ERROR("create_program_from_file: path not found");
oss << "No file at '" << path << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
} }
return create_program(kernel_source.c_str(), options, device_id); return create_program(kernel_source.c_str(), options, device_id);
} }
...@@ -108,10 +106,7 @@ program_ptr manager::create_program(const char* kernel_source, ...@@ -108,10 +106,7 @@ program_ptr manager::create_program(const char* kernel_source,
uint32_t device_id) { uint32_t device_id) {
auto dev = find_device(device_id); auto dev = find_device(device_id);
if (!dev) { if (!dev) {
ostringstream oss; CAF_RAISE_ERROR("create_program: no device found");
oss << "No device with id '" << device_id << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
} }
return create_program(kernel_source, options, *dev); return create_program(kernel_source, options, *dev);
} }
...@@ -129,10 +124,7 @@ program_ptr manager::create_program_from_file(const char* path, ...@@ -129,10 +124,7 @@ program_ptr manager::create_program_from_file(const char* path,
static_cast<streamsize>(kernel_source.size())); static_cast<streamsize>(kernel_source.size()));
read_source.close(); read_source.close();
} else { } else {
ostringstream oss; CAF_RAISE_ERROR("create_program_from_file: path not found");
oss << "No file at '" << path << "' found.";
CAF_LOG_ERROR(CAF_ARG(oss.str()));
CAF_RAISE_ERROR(oss.str());
} }
return create_program(kernel_source.c_str(), options, dev); return create_program(kernel_source.c_str(), options, dev);
} }
...@@ -169,12 +161,12 @@ program_ptr manager::create_program(const char* kernel_source, ...@@ -169,12 +161,12 @@ program_ptr manager::create_program(const char* kernel_source,
// seems that just apple implemented the // seems that just apple implemented the
// pfn_notify callback, but we can get // pfn_notify callback, but we can get
// the build log // the build log
#ifndef __APPLE__ #ifndef CAF_MACOS
CAF_LOG_ERROR(CAF_ARG(ss.str())); CAF_LOG_ERROR(CAF_ARG(ss.str()));
#endif #endif
oss << endl << ss.str(); oss << endl << ss.str();
} }
CAF_RAISE_ERROR(oss.str()); CAF_RAISE_ERROR("clBuildProgram failed");
} }
cl_uint number_of_kernels = 0; cl_uint number_of_kernels = 0;
clCreateKernelsInProgram(pptr.get(), 0u, nullptr, &number_of_kernels); clCreateKernelsInProgram(pptr.get(), 0u, nullptr, &number_of_kernels);
...@@ -183,23 +175,16 @@ program_ptr manager::create_program(const char* kernel_source, ...@@ -183,23 +175,16 @@ program_ptr manager::create_program(const char* kernel_source,
vector<cl_kernel> kernels(number_of_kernels); vector<cl_kernel> kernels(number_of_kernels);
err = clCreateKernelsInProgram(pptr.get(), number_of_kernels, err = clCreateKernelsInProgram(pptr.get(), number_of_kernels,
kernels.data(), nullptr); kernels.data(), nullptr);
if (err != CL_SUCCESS) { if (err != CL_SUCCESS)
ostringstream oss; CAF_RAISE_ERROR("clCreateKernelsInProgram failed");
oss << "clCreateKernelsInProgram: " << opencl_error(err);
CAF_RAISE_ERROR(oss.str());
}
for (cl_uint i = 0; i < number_of_kernels; ++i) { for (cl_uint i = 0; i < number_of_kernels; ++i) {
size_t len; size_t len;
clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, 0, nullptr, &len); clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, 0, nullptr, &len);
vector<char> name(len); vector<char> name(len);
err = clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, len, err = clGetKernelInfo(kernels[i], CL_KERNEL_FUNCTION_NAME, len,
reinterpret_cast<void*>(name.data()), nullptr); reinterpret_cast<void*>(name.data()), nullptr);
if (err != CL_SUCCESS) { if (err != CL_SUCCESS)
ostringstream oss; CAF_RAISE_ERROR("clGetKernelInfo failed");
oss << "clGetKernelInfo (CL_KERNEL_FUNCTION_NAME): "
<< opencl_error(err);
CAF_RAISE_ERROR(oss.str());
}
detail::raw_kernel_ptr kernel; detail::raw_kernel_ptr kernel;
kernel.reset(move(kernels[i])); kernel.reset(move(kernels[i]));
available_kernels.emplace(string(name.data()), move(kernel)); available_kernels.emplace(string(name.data()), move(kernel));
......
...@@ -17,17 +17,16 @@ ...@@ -17,17 +17,16 @@
* http://www.boost.org/LICENSE_1_0.txt. * * 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 caf {
namespace opencl { namespace opencl {
void throwcl(const char* fname, cl_int err) { void throwcl(const char*, cl_int err) {
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
std::string errstr = fname; CAF_RAISE_ERROR("throwcl: unrecoverable OpenCL error");
errstr += ": ";
errstr += opencl_error(err);
CAF_RAISE_ERROR(std::move(errstr));
} }
} }
...@@ -35,7 +34,7 @@ void CL_CALLBACK pfn_notify(const char* errinfo, const void*, size_t, void*) { ...@@ -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" CAF_LOG_ERROR("\n##### Error message via pfn_notify #####\n"
<< errinfo << << errinfo <<
"\n########################################"); "\n########################################");
static_cast<void>(errinfo); // remove warning CAF_IGNORE_UNUSED(errinfo);
} }
} // namespace opencl } // namespace opencl
......
...@@ -63,11 +63,8 @@ platform_ptr platform::create(cl_platform_id platform_id, ...@@ -63,11 +63,8 @@ platform_ptr platform::create(cl_platform_id platform_id,
device_information.push_back(device::create(context, device_id, device_information.push_back(device::create(context, device_id,
start_id++)); start_id++));
} }
if (device_information.empty()) { if (device_information.empty())
string errstr = "no devices for the platform found"; CAF_RAISE_ERROR("no devices for the platform found");
CAF_LOG_ERROR(CAF_ARG(errstr));
CAF_RAISE_ERROR(move(errstr));
}
auto name = platform_info(platform_id, CL_PLATFORM_NAME); auto name = platform_info(platform_id, CL_PLATFORM_NAME);
auto vendor = platform_info(platform_id, CL_PLATFORM_VENDOR); auto vendor = platform_info(platform_id, CL_PLATFORM_VENDOR);
auto version = platform_info(platform_id, CL_PLATFORM_VERSION); auto version = platform_info(platform_id, CL_PLATFORM_VERSION);
......
...@@ -161,11 +161,13 @@ constexpr const char* kernel_source = R"__( ...@@ -161,11 +161,13 @@ constexpr const char* kernel_source = R"__(
} }
)__"; )__";
#ifndef CAF_NO_EXCEPTIONS
constexpr const char* kernel_source_error = R"__( constexpr const char* kernel_source_error = R"__(
kernel void missing(global int*) { kernel void missing(global int*) {
size_t semicolon_missing size_t semicolon_missing
} }
)__"; )__";
#endif // CAF_NO_EXCEPTIONS
constexpr const char* kernel_source_compiler_flag = R"__( constexpr const char* kernel_source_compiler_flag = R"__(
kernel void compiler_flag(global const int* restrict input, kernel void compiler_flag(global const int* restrict input,
...@@ -398,19 +400,15 @@ void test_opencl(actor_system& sys) { ...@@ -398,19 +400,15 @@ void test_opencl(actor_system& sys) {
expected2.data(), result.data()); expected2.data(), result.data());
}, others >> wrong_msg }, others >> wrong_msg
); );
#ifndef CAF_NO_EXCEPTIONS
CAF_MESSAGE("Expecting exception (compiling invalid kernel, " CAF_MESSAGE("Expecting exception (compiling invalid kernel, "
"semicolon is missing)."); "semicolon is missing).");
try { try {
/* auto expected_error = */ mngr.create_program(kernel_source_error); /* auto expected_error = */ mngr.create_program(kernel_source_error);
} catch (const exception& exc) { } catch (const exception& exc) {
std::string starts_with("clBuildProgram: CL_BUILD_PROGRAM_FAILURE"); CAF_MESSAGE("got: " << exc.what());
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.");
} }
#endif // CAF_NO_EXCEPTIONS
// create program with opencl compiler flags // create program with opencl compiler flags
auto prog5 = mngr.create_program(kernel_source_compiler_flag, compiler_flag); auto prog5 = mngr.create_program(kernel_source_compiler_flag, compiler_flag);
opencl::nd_range range5{dims{array_size}}; opencl::nd_range range5{dims{array_size}};
......
...@@ -65,7 +65,6 @@ private: ...@@ -65,7 +65,6 @@ private:
size_t len, const char* debug_name); size_t len, const char* debug_name);
SSL_CTX* create_ssl_context(); SSL_CTX* create_ssl_context();
std::string get_ssl_error(); std::string get_ssl_error();
void raise_ssl_error(std::string msg);
bool handle_ssl_result(int ret); bool handle_ssl_result(int ret);
actor_system& sys_; actor_system& sys_;
......
...@@ -26,11 +26,12 @@ CAF_POP_WARNINGS ...@@ -26,11 +26,12 @@ CAF_POP_WARNINGS
#include <vector> #include <vector>
#include <mutex> #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_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.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/middleman.hpp"
#include "caf/io/basp_broker.hpp" #include "caf/io/basp_broker.hpp"
......
...@@ -209,7 +209,7 @@ SSL_CTX* session::create_ssl_context() { ...@@ -209,7 +209,7 @@ SSL_CTX* session::create_ssl_context() {
auto ctx = SSL_CTX_new(TLSv1_2_method()); auto ctx = SSL_CTX_new(TLSv1_2_method());
#endif #endif
if (!ctx) if (!ctx)
raise_ssl_error("cannot create OpenSSL context"); CAF_RAISE_ERROR("cannot create OpenSSL context");
if (sys_.openssl_manager().authentication_enabled()) { if (sys_.openssl_manager().authentication_enabled()) {
// Require valid certificates on both sides. // Require valid certificates on both sides.
auto& cfg = sys_.config(); auto& cfg = sys_.config();
...@@ -217,7 +217,7 @@ SSL_CTX* session::create_ssl_context() { ...@@ -217,7 +217,7 @@ SSL_CTX* session::create_ssl_context() {
&& SSL_CTX_use_certificate_chain_file(ctx, && SSL_CTX_use_certificate_chain_file(ctx,
cfg.openssl_certificate.c_str()) cfg.openssl_certificate.c_str())
!= 1) != 1)
raise_ssl_error("cannot load certificate"); CAF_RAISE_ERROR("cannot load certificate");
if (cfg.openssl_passphrase.size() > 0) { if (cfg.openssl_passphrase.size() > 0) {
openssl_passphrase_ = cfg.openssl_passphrase; openssl_passphrase_ = cfg.openssl_passphrase;
SSL_CTX_set_default_passwd_cb(ctx, pem_passwd_cb); SSL_CTX_set_default_passwd_cb(ctx, pem_passwd_cb);
...@@ -227,19 +227,19 @@ SSL_CTX* session::create_ssl_context() { ...@@ -227,19 +227,19 @@ SSL_CTX* session::create_ssl_context() {
&& SSL_CTX_use_PrivateKey_file(ctx, cfg.openssl_key.c_str(), && SSL_CTX_use_PrivateKey_file(ctx, cfg.openssl_key.c_str(),
SSL_FILETYPE_PEM) SSL_FILETYPE_PEM)
!= 1) != 1)
raise_ssl_error("cannot load private key"); CAF_RAISE_ERROR("cannot load private key");
auto cafile = auto cafile =
(cfg.openssl_cafile.size() > 0 ? cfg.openssl_cafile.c_str() : nullptr); (cfg.openssl_cafile.size() > 0 ? cfg.openssl_cafile.c_str() : nullptr);
auto capath = auto capath =
(cfg.openssl_capath.size() > 0 ? cfg.openssl_capath.c_str() : nullptr); (cfg.openssl_capath.size() > 0 ? cfg.openssl_capath.c_str() : nullptr);
if (cafile || capath) { if (cafile || capath) {
if (SSL_CTX_load_verify_locations(ctx, cafile, capath) != 1) 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, SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
nullptr); nullptr);
if (SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!MD5") != 1) 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 { } else {
// No authentication. // No authentication.
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nullptr); SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, nullptr);
...@@ -248,7 +248,7 @@ SSL_CTX* session::create_ssl_context() { ...@@ -248,7 +248,7 @@ SSL_CTX* session::create_ssl_context() {
#else #else
auto ecdh = EC_KEY_new_by_curve_name(NID_secp384r1); auto ecdh = EC_KEY_new_by_curve_name(NID_secp384r1);
if (!ecdh) if (!ecdh)
raise_ssl_error("cannot get ECDH curve"); CAF_RAISE_ERROR("cannot get ECDH curve");
CAF_PUSH_WARNINGS CAF_PUSH_WARNINGS
SSL_CTX_set_tmp_ecdh(ctx, ecdh); SSL_CTX_set_tmp_ecdh(ctx, ecdh);
EC_KEY_free(ecdh); EC_KEY_free(ecdh);
...@@ -260,7 +260,7 @@ SSL_CTX* session::create_ssl_context() { ...@@ -260,7 +260,7 @@ SSL_CTX* session::create_ssl_context() {
const char* cipher = "AECDH-AES256-SHA"; const char* cipher = "AECDH-AES256-SHA";
#endif #endif
if (SSL_CTX_set_cipher_list(ctx, cipher) != 1) 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; return ctx;
} }
...@@ -277,10 +277,6 @@ std::string session::get_ssl_error() { ...@@ -277,10 +277,6 @@ std::string session::get_ssl_error() {
return msg; 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) { bool session::handle_ssl_result(int ret) {
auto err = SSL_get_error(ssl_, ret); auto err = SSL_get_error(ssl_, ret);
switch (err) { switch (err) {
......
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