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

Fix build with exceptions disabled, close #1086

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