Commit 9a614951 authored by Dominik Charousset's avatar Dominik Charousset

Fix build with exceptions disabled, close #1086

parent 64c40959
...@@ -59,6 +59,16 @@ config = [ ...@@ -59,6 +59,16 @@ config = [
tags: ['docker'], tags: ['docker'],
builds: ['debug', 'release'], builds: ['debug', 'release'],
]], ]],
// One extra debug build with exceptions disabled.
['centos-7', [
numCores: 4,
tags: ['docker'],
builds: ['debug'],
extraDebugFlags: [
'CAF_ENABLE_EXCEPTIONS:BOOL=OFF',
'CMAKE_CXX_FLAGS:STRING=-fno-exceptions',
],
]],
// Other UNIX systems. // Other UNIX systems.
['macOS', [ ['macOS', [
numCores: 4, numCores: 4,
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "caf/detail/padded_size.hpp" #include "caf/detail/padded_size.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/intrusive_cow_ptr.hpp" #include "caf/intrusive_cow_ptr.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
...@@ -188,7 +189,7 @@ message make_message(Ts&&... xs) { ...@@ -188,7 +189,7 @@ message make_message(Ts&&... xs) {
auto types = make_type_id_list<strip_and_convert_t<Ts>...>(); auto types = make_type_id_list<strip_and_convert_t<Ts>...>();
auto vptr = malloc(data_size); auto vptr = malloc(data_size);
if (vptr == nullptr) if (vptr == nullptr)
throw std::bad_alloc(); CAF_RAISE_ERROR(std::bad_alloc, "bad_alloc");
auto raw_ptr = new (vptr) message_data(types); auto raw_ptr = new (vptr) message_data(types);
intrusive_cow_ptr<message_data> ptr{raw_ptr, false}; intrusive_cow_ptr<message_data> ptr{raw_ptr, false};
message_data_init(raw_ptr->storage(), std::forward<Ts>(xs)...); message_data_init(raw_ptr->storage(), std::forward<Ts>(xs)...);
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "caf/detail/core_export.hpp" #include "caf/detail/core_export.hpp"
#include "caf/detail/pp.hpp" #include "caf/detail/pp.hpp"
#include <type_traits>
namespace caf::detail { namespace caf::detail {
CAF_CORE_EXPORT void log_cstring_error(const char* cstring); CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
...@@ -38,7 +40,10 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring); ...@@ -38,7 +40,10 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
# define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \ # define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \
do { \ do { \
::caf::detail::log_cstring_error(msg); \ ::caf::detail::log_cstring_error(msg); \
throw exception_type(msg); \ if constexpr (std::is_constructible<exception_type, const char*>::value) \
throw exception_type(msg); \
else \
throw exception_type(); \
} while (false) } while (false)
# define CAF_RAISE_ERROR_IMPL_1(msg) \ # define CAF_RAISE_ERROR_IMPL_1(msg) \
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "caf/detail/meta_object.hpp" #include "caf/detail/meta_object.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/error_code.hpp" #include "caf/error_code.hpp"
#include "caf/raise_error.hpp"
#include "caf/sec.hpp" #include "caf/sec.hpp"
#include "caf/span.hpp" #include "caf/span.hpp"
...@@ -55,7 +56,7 @@ message_data* message_data::copy() const { ...@@ -55,7 +56,7 @@ message_data* message_data::copy() const {
auto total_size = sizeof(message_data) + storage_size; auto total_size = sizeof(message_data) + storage_size;
auto vptr = malloc(total_size); auto vptr = malloc(total_size);
if (vptr == nullptr) if (vptr == nullptr)
throw std::bad_alloc(); CAF_RAISE_ERROR(std::bad_alloc, "bad_alloc");
auto ptr = new (vptr) message_data(types_); auto ptr = new (vptr) message_data(types_);
auto src = storage(); auto src = storage();
auto dst = ptr->storage(); auto dst = ptr->storage();
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/hash/fnv.hpp" #include "caf/hash/fnv.hpp"
#include "caf/raise_error.hpp"
#include "caf/type_id_list.hpp" #include "caf/type_id_list.hpp"
namespace caf::detail { namespace caf::detail {
...@@ -99,7 +100,7 @@ void type_id_list_builder::reserve(size_t new_capacity) { ...@@ -99,7 +100,7 @@ void type_id_list_builder::reserve(size_t new_capacity) {
reserved_ = new_capacity; reserved_ = new_capacity;
auto ptr = realloc(storage_, reserved_ * sizeof(type_id_t)); auto ptr = realloc(storage_, reserved_ * sizeof(type_id_t));
if (ptr == nullptr) if (ptr == nullptr)
throw std::bad_alloc(); CAF_RAISE_ERROR(std::bad_alloc, "bad_alloc");
storage_ = reinterpret_cast<type_id_t*>(ptr); storage_ = reinterpret_cast<type_id_t*>(ptr);
// Add the dummy for later inserting the size on first push_back. // Add the dummy for later inserting the size on first push_back.
if (size_ == 0) { if (size_ == 0) {
...@@ -144,7 +145,7 @@ type_id_list type_id_list_builder::copy_to_list() const { ...@@ -144,7 +145,7 @@ type_id_list type_id_list_builder::copy_to_list() const {
return make_type_id_list(); return make_type_id_list();
auto vptr = malloc(size_ * sizeof(type_id_t)); auto vptr = malloc(size_ * sizeof(type_id_t));
if (vptr == nullptr) if (vptr == nullptr)
throw std::bad_alloc(); CAF_RAISE_ERROR(std::bad_alloc, "bad_alloc");
auto copy = reinterpret_cast<type_id_t*>(vptr); auto copy = reinterpret_cast<type_id_t*>(vptr);
copy[0] = static_cast<type_id_t>(list_size); copy[0] = static_cast<type_id_t>(list_size);
memcpy(copy + 1, storage_ + 1, list_size * sizeof(type_id_t)); memcpy(copy + 1, storage_ + 1, list_size * sizeof(type_id_t));
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "caf/message_builder.hpp" #include "caf/message_builder.hpp"
#include "caf/raise_error.hpp"
namespace caf { namespace caf {
namespace { namespace {
...@@ -36,7 +38,7 @@ message to_message_impl(size_t storage_size, TypeListBuilder& types, ...@@ -36,7 +38,7 @@ message to_message_impl(size_t storage_size, TypeListBuilder& types,
return message{}; return message{};
auto vptr = malloc(sizeof(message_data) + storage_size); auto vptr = malloc(sizeof(message_data) + storage_size);
if (vptr == nullptr) if (vptr == nullptr)
throw std::bad_alloc(); CAF_RAISE_ERROR(std::bad_alloc, "bad_alloc");
message_data* raw_ptr; message_data* raw_ptr;
if constexpr (Policy == move_msg) if constexpr (Policy == move_msg)
raw_ptr = new (vptr) message_data(types.move_to_list()); raw_ptr = new (vptr) message_data(types.move_to_list());
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <cstdint> #include <cstdint>
#include "caf/detail/parser/add_ascii.hpp" #include "caf/detail/parser/add_ascii.hpp"
#include "caf/raise_error.hpp"
using namespace caf; using namespace caf;
...@@ -36,13 +37,14 @@ byte operator"" _b(const char* str, size_t n) { ...@@ -36,13 +37,14 @@ byte operator"" _b(const char* str, size_t n) {
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
if (str[i] != '\'') { if (str[i] != '\'') {
if (!detail::parser::add_ascii<2>(result, str[i])) if (!detail::parser::add_ascii<2>(result, str[i]))
throw std::logic_error("invalid character or over-/underflow"); CAF_RAISE_ERROR(std::logic_error,
"invalid character or over-/underflow");
else else
++consumed; ++consumed;
} }
} }
if (consumed != 8) if (consumed != 8)
throw std::logic_error("too few digits, expected exactly 8"); CAF_RAISE_ERROR(std::logic_error, "too few digits, expected exactly 8");
return static_cast<byte>(result); return static_cast<byte>(result);
} }
......
...@@ -163,7 +163,7 @@ CAF_TEST(lookup) { ...@@ -163,7 +163,7 @@ CAF_TEST(lookup) {
CAF_CHECK_EQUAL(cxs.find(5), xs.end()); CAF_CHECK_EQUAL(cxs.find(5), xs.end());
} }
#ifndef CAF_NO_EXCEPTIONS #ifdef CAF_ENABLE_EXCEPTIONS
CAF_TEST(exceptions) { CAF_TEST(exceptions) {
fill_xs(); fill_xs();
try { try {
...@@ -175,7 +175,7 @@ CAF_TEST(exceptions) { ...@@ -175,7 +175,7 @@ CAF_TEST(exceptions) {
CAF_FAIL("got an expected exception"); CAF_FAIL("got an expected exception");
} }
} }
#endif // CAF_NO_EXCEPTIONS #endif // CAF_ENABLE_EXCEPTIONS
// We repeat several tests with strings as value type instead of integers to // We repeat several tests with strings as value type instead of integers to
// trigger non-trivial destructors. // trigger non-trivial destructors.
......
...@@ -180,7 +180,7 @@ CAF_TEST(requesters support fan_out_request) { ...@@ -180,7 +180,7 @@ CAF_TEST(requesters support fan_out_request) {
CAF_CHECK_EQUAL(*sum, 9); CAF_CHECK_EQUAL(*sum, 9);
} }
#ifndef CAF_NO_EXCEPTIONS #ifdef CAF_ENABLE_EXCEPTIONS
CAF_TEST(exceptions while processing requests trigger error messages) { CAF_TEST(exceptions while processing requests trigger error messages) {
auto worker = sys.spawn([] { auto worker = sys.spawn([] {
...@@ -199,6 +199,6 @@ CAF_TEST(exceptions while processing requests trigger error messages) { ...@@ -199,6 +199,6 @@ CAF_TEST(exceptions while processing requests trigger error messages) {
expect((error), from(worker).to(client).with(sec::runtime_error)); expect((error), from(worker).to(client).with(sec::runtime_error));
} }
#endif // CAF_NO_EXCEPTIONS #endif // CAF_ENABLE_EXCEPTIONS
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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