Skip to content

Commit

Permalink
added fno-exceptions support.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Apr 21, 2024
1 parent c0f0768 commit 77d3d89
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 38 deletions.
7 changes: 3 additions & 4 deletions include/boost/cobalt/detail/detached.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ struct detached_promise
std::suspend_never final_suspend() noexcept {return {};}

void return_void() {}
void unhandled_exception()
{
throw ;
}
#if !defined(BOOST_NO_EXCEPTIONS)
void unhandled_exception() { throw ; }
#endif
};

}
Expand Down
10 changes: 6 additions & 4 deletions include/boost/cobalt/detail/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct gather_variadic_impl
// GCC doesn't like member funs
template<std::size_t Idx>
static detail::fork await_impl(awaitable & this_)
try
BOOST_TRY
{
auto & aw = std::get<Idx>(this_.aws);
// check manually if we're ready
Expand Down Expand Up @@ -124,10 +124,11 @@ struct gather_variadic_impl
std::get<Idx>(this_.result).template emplace<1u>(aw.await_resume());
}
}
catch(...)
BOOST_CATCH(...)
{
std::get<Idx>(this_.result).template emplace<2u>(std::current_exception());
}
BOOST_CATCH_END

std::array<detail::fork(*)(awaitable&), tuple_size> impls {
[]<std::size_t ... Idx>(std::index_sequence<Idx...>)
Expand Down Expand Up @@ -301,7 +302,7 @@ struct gather_ranged_impl
}

static detail::fork await_impl(awaitable & this_, std::size_t idx)
try
BOOST_TRY
{
auto & aw = *std::next(std::begin(this_.aws), idx);
auto rd = aw.await_ready();
Expand All @@ -328,11 +329,12 @@ struct gather_ranged_impl
this_.result[idx].template emplace<1u>(aw.await_resume());
}
}
catch(...)
BOOST_CATCH(...)
{
this_.result[idx].template emplace<2u>(std::current_exception());

}
BOOST_CATCH_END

detail::fork last_forked;
std::size_t last_index = 0u;
Expand Down
11 changes: 6 additions & 5 deletions include/boost/cobalt/detail/join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ struct join_variadic_impl
});
}


// GCC doesn't like member funs
template<std::size_t Idx>
static detail::fork await_impl(awaitable & this_)
try
BOOST_TRY
{
auto & aw = std::get<Idx>(this_.aws);
// check manually if we're ready
Expand Down Expand Up @@ -152,12 +151,13 @@ struct join_variadic_impl
}

}
catch(...)
BOOST_CATCH(...)
{
if (!this_.error)
this_.error = std::current_exception();
this_.cancel_all();
}
BOOST_CATCH_END

std::array<detail::fork(*)(awaitable&), tuple_size> impls {
[]<std::size_t ... Idx>(std::index_sequence<Idx...>)
Expand Down Expand Up @@ -393,7 +393,7 @@ struct join_ranged_impl


static detail::fork await_impl(awaitable & this_, std::size_t idx)
try
BOOST_TRY
{
auto & aw = *std::next(std::begin(this_.aws), idx);
auto rd = aw.await_ready();
Expand All @@ -415,12 +415,13 @@ struct join_ranged_impl
this_.result[idx].emplace(aw.await_resume());
}
}
catch(...)
BOOST_CATCH(...)
{
if (!this_.error)
this_.error = std::current_exception();
this_.cancel_all();
}
BOOST_CATCH_END

detail::fork last_forked;
std::size_t last_index = 0u;
Expand Down
2 changes: 2 additions & 0 deletions include/boost/cobalt/detail/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct main_promise : signal_helper,
BOOST_COBALT_DECL
auto final_suspend() noexcept -> std::suspend_never;

#if !defined(BOOST_NO_EXCEPTIONS)
void unhandled_exception() { throw ; }
#endif
void return_value(int res = 0)
{
if (result)
Expand Down
21 changes: 13 additions & 8 deletions include/boost/cobalt/detail/race.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/core/no_exceptions_support.hpp>


#include <boost/intrusive_ptr.hpp>
Expand Down Expand Up @@ -149,14 +150,15 @@ struct race_variadic_impl

template<typename T, typename Error>
void assign_error(system::result<T, Error> & res)
try
BOOST_TRY
{
std::move(res).value(loc);
}
catch(...)
BOOST_CATCH(...)
{
error = std::current_exception();
}
BOOST_CATCH_END

template<typename T>
void assign_error(system::result<T, std::exception_ptr> & res)
Expand All @@ -166,7 +168,7 @@ struct race_variadic_impl

template<std::size_t Idx>
static detail::fork await_impl(awaitable & this_)
try
BOOST_TRY
{
using traits = race_traits<mp11::mp_at_c<mp11::mp_list<Args...>, Idx>>;

Expand Down Expand Up @@ -273,14 +275,15 @@ struct race_variadic_impl
this_.cancel_all();
this_.working[Idx] = nullptr;
}
catch(...)
BOOST_CATCH(...)
{
if (!this_.has_result())
this_.index = Idx;
if (this_.index == Idx)
this_.error = std::current_exception();
this_.working[Idx] = nullptr;
}
BOOST_CATCH_END

std::array<detail::fork(*)(awaitable&), tuple_size> impls {
[]<std::size_t ... Idx>(std::index_sequence<Idx...>)
Expand Down Expand Up @@ -488,14 +491,15 @@ struct race_ranged_impl

template<typename T, typename Error>
void assign_error(system::result<T, Error> & res)
try
BOOST_TRY
{
std::move(res).value(loc);
}
catch(...)
BOOST_CATCH(...)
{
error = std::current_exception();
}
BOOST_CATCH_END

template<typename T>
void assign_error(system::result<T, std::exception_ptr> & res)
Expand All @@ -504,7 +508,7 @@ struct race_ranged_impl
}

static detail::fork await_impl(awaitable & this_, std::size_t idx)
try
BOOST_TRY
{
typename traits::actual_awaitable aw_{
get_awaitable_type(
Expand Down Expand Up @@ -591,7 +595,7 @@ struct race_ranged_impl
if constexpr (traits::interruptible)
this_.working[idx] = nullptr;
}
catch(...)
BOOST_CATCH(...)
{
if (!this_.has_result())
this_.index = idx;
Expand All @@ -600,6 +604,7 @@ struct race_ranged_impl
if constexpr (traits::interruptible)
this_.working[idx] = nullptr;
}
BOOST_CATCH_END

detail::fork last_forked;

Expand Down
2 changes: 2 additions & 0 deletions include/boost/cobalt/detail/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ struct thread_promise : signal_helper_2,
return {};
}

#if !defined(BOOST_NO_EXCEPTIONS)
void unhandled_exception() { throw; }
#endif
void return_void() { }

using executor_type = typename cobalt::executor;
Expand Down
6 changes: 4 additions & 2 deletions include/boost/cobalt/detail/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/cobalt/config.hpp>
#include <boost/cobalt/this_thread.hpp>

#include <boost/core/no_exceptions_support.hpp>
#include <boost/system/result.hpp>
#include <boost/variant2/variant.hpp>

Expand Down Expand Up @@ -104,7 +105,7 @@ template<typename Awaitable>
auto get_resume_result(Awaitable & aw) -> system::result<decltype(aw.await_resume()), std::exception_ptr>
{
using type = decltype(aw.await_resume());
try
BOOST_TRY
{
if constexpr (std::is_void_v<type>)
{
Expand All @@ -114,10 +115,11 @@ auto get_resume_result(Awaitable & aw) -> system::result<decltype(aw.await_resum
else
return aw.await_resume();
}
catch(...)
BOOST_CATCH(...)
{
return std::current_exception();
}
BOOST_CATCH_END
}

#if BOOST_COBALT_NO_SELF_DELETE
Expand Down
2 changes: 1 addition & 1 deletion include/boost/cobalt/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct cobalt_category_t final : system::error_category
}
}

const char * name() const BOOST_NOEXCEPT override
const char * name() const noexcept override
{
return "boost.cobalt";
}
Expand Down
6 changes: 4 additions & 2 deletions include/boost/cobalt/op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/cobalt/detail/handler.hpp>
#include <boost/cobalt/detail/sbo_resource.hpp>
#include <boost/cobalt/result.hpp>
#include <boost/core/no_exceptions_support.hpp>

namespace boost::cobalt
{
Expand Down Expand Up @@ -54,7 +55,7 @@ struct op
#endif
) noexcept
{
try
BOOST_TRY
{
completed_immediately = detail::completed_immediately_t::initiating;

Expand All @@ -67,11 +68,12 @@ struct op
completed_immediately = detail::completed_immediately_t::no;
return completed_immediately != detail::completed_immediately_t::yes;
}
catch(...)
BOOST_CATCH(...)
{
init_ep = std::current_exception();
return false;
}
BOOST_CATCH_END
}

auto await_resume(const boost::source_location & loc = BOOST_CURRENT_LOCATION)
Expand Down
34 changes: 25 additions & 9 deletions include/boost/cobalt/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <boost/cobalt/concepts.hpp>

#include <boost/core/no_exceptions_support.hpp>
#include <boost/system/result.hpp>

namespace boost::cobalt
Expand Down Expand Up @@ -101,27 +102,29 @@ struct as_result_t
if constexpr (std::is_void_v<type>)
{
using res_t = system::result<type, std::exception_ptr>;
try
BOOST_TRY
{
aw_.await_resume();
return res_t{system::in_place_value};
}
catch (...)
BOOST_CATCH (...)
{
return res_t{system::in_place_error, std::current_exception()};
}
BOOST_CATCH_END
}
else
{
using res_t = system::result<type, std::exception_ptr>;
try
BOOST_TRY
{
return res_t{system::in_place_value, aw_.await_resume()};
}
catch (...)
BOOST_CATCH (...)
{
return res_t{system::in_place_error, std::current_exception()};
}
BOOST_CATCH_END
}
}
}
Expand Down Expand Up @@ -188,33 +191,46 @@ struct as_tuple_t

auto await_resume()
{
using type = decltype(aw_.await_resume());
if constexpr (requires {aw_.await_resume(as_tuple_tag{});})
return aw_.await_resume(as_tuple_tag{});
else if (noexcept(aw_.await_resume()))
{
if constexpr (std::is_void_v<type>)
{
aw_.await_resume();
return std::make_tuple();
}
else
return std::make_tuple(aw_.await_resume());

}
else
{
using type = decltype(aw_.await_resume());
if constexpr (std::is_void_v<type>)
{
try
BOOST_TRY
{
aw_.await_resume();
return std::make_tuple(std::exception_ptr());
}
catch (...)
BOOST_CATCH (...)
{
return make_tuple_(std::current_exception());
}
BOOST_CATCH_END
}
else
{
try
BOOST_TRY
{
return make_tuple_(std::exception_ptr(), aw_.await_resume());
}
catch (...)
BOOST_CATCH (...)
{
return make_tuple_(std::current_exception(), type());
}
BOOST_CATCH_END
}
}
}
Expand Down
Loading

0 comments on commit 77d3d89

Please sign in to comment.