Commit 66d9e98c authored by Dominik Charousset's avatar Dominik Charousset

Deprecate .unsafe functions, close #507

parent 98e3e2b3
......@@ -115,6 +115,11 @@ public:
return static_cast<bool>(ptr_);
}
/// Queries whether this actor handle is invalid.
inline bool operator!() const {
return !ptr_;
}
/// Returns the address of the stored actor.
actor_addr address() const noexcept;
......@@ -138,7 +143,7 @@ public:
/// Queries whether this object was constructed using
/// `unsafe_actor_handle_init` or is in moved-from state.
bool unsafe() const {
bool unsafe() const CAF_DEPRECATED {
return !ptr_;
}
......
......@@ -148,14 +148,14 @@ public:
}
~function_view() {
if (!impl_.unsafe())
if (impl_)
self_.~scoped_actor();
}
function_view(function_view&& x)
: timeout(x.timeout),
impl_(std::move(x.impl_)) {
if (!impl_.unsafe()) {
if (impl_) {
new (&self_) scoped_actor(impl_.home_system()); //(std::move(x.self_));
x.self_.~scoped_actor();
}
......@@ -179,7 +179,7 @@ public:
>...
>::tuple_type>>
expected<R> operator()(Ts&&... xs) {
if (impl_.unsafe())
if (!impl_)
return sec::bad_function_call;
error err;
function_view_result<R> result;
......@@ -221,7 +221,7 @@ private:
}
void new_self(const Actor& x) {
if (!x.unsafe())
if (x)
new (&self_) scoped_actor(x->home_system());
}
......
......@@ -58,35 +58,31 @@ public:
/// Links this actor to `x`.
void link_to(const actor_addr& x) {
auto ptr = actor_cast<strong_actor_ptr>(x);
if (!ptr || ptr->get() == this)
return;
link_impl(establish_link_op, ptr->get());
if (ptr && ptr->get() != this)
link_impl(establish_link_op, ptr->get());
}
/// Links this actor to `x`.
template <class ActorHandle>
void link_to(const ActorHandle& x) {
auto ptr = actor_cast<abstract_actor*>(x);
if (!ptr || ptr == this)
return;
link_impl(establish_link_op, ptr);
if (ptr && ptr != this)
link_impl(establish_link_op, ptr);
}
/// Unlinks this actor from `x`.
void unlink_from(const actor_addr& x) {
auto ptr = actor_cast<strong_actor_ptr>(x);
if (!ptr || ptr->get() == this)
return;
link_impl(remove_link_op, ptr->get());
if (ptr && ptr->get() != this)
link_impl(remove_link_op, ptr->get());
}
/// Links this actor to `x`.
template <class ActorHandle>
void unlink_from(const ActorHandle& x) {
auto ptr = actor_cast<abstract_actor*>(x);
if (!ptr || ptr == this)
return;
link_impl(remove_link_op, ptr);
if (ptr && ptr != this)
link_impl(remove_link_op, ptr);
}
/// @cond PRIVATE
......
......@@ -174,6 +174,11 @@ class typed_actor : detail::comparable<typed_actor<Sigs...>>,
return static_cast<bool>(ptr_);
}
/// Queries whether this actor handle is invalid.
inline bool operator!() const {
return !ptr_;
}
/// Queries the address of the stored actor.
actor_addr address() const noexcept {
return {ptr_.get(), true};
......
......@@ -33,7 +33,7 @@ forwarding_actor_proxy::forwarding_actor_proxy(actor_config& cfg, actor mgr)
}
forwarding_actor_proxy::~forwarding_actor_proxy() {
if (!manager_.unsafe())
if (manager_)
anon_send(manager_, make_message(delete_atom::value, node(), id()));
}
......@@ -54,7 +54,7 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender,
<< CAF_ARG(mid) << CAF_ARG(msg));
forwarding_stack tmp;
shared_lock<detail::shared_spinlock> guard_(manager_mtx_);
if (!manager_.unsafe())
if (manager_)
manager_->enqueue(nullptr, invalid_message_id,
make_message(forward_atom::value, std::move(sender),
fwd ? *fwd : tmp,
......
......@@ -75,18 +75,17 @@ void local_actor::request_response_timeout(const duration& d, message_id mid) {
}
void local_actor::monitor(abstract_actor* ptr) {
if (!ptr)
return;
ptr->attach(default_attachable::make_monitor(ptr->address(), address()));
if (ptr)
ptr->attach(default_attachable::make_monitor(ptr->address(), address()));
}
void local_actor::demonitor(const actor_addr& whom) {
CAF_LOG_TRACE(CAF_ARG(whom));
auto ptr = actor_cast<strong_actor_ptr>(whom);
if (!ptr)
return;
default_attachable::observe_token tk{address(), default_attachable::monitor};
ptr->get()->detach(tk);
if (ptr) {
default_attachable::observe_token tk{address(), default_attachable::monitor};
ptr->get()->detach(tk);
}
}
void local_actor::on_exit() {
......
......@@ -174,7 +174,7 @@ struct fixture {
template <class T>
bool value_is(const char* key, const T& what) {
if (!config_server.unsafe())
if (config_server)
return config_server_has(key, what);
auto& cv = values[key];
using type =
......@@ -192,7 +192,7 @@ struct fixture {
}
size_t num_values() {
if (!config_server.unsafe()) {
if (config_server) {
size_t result = 0;
scoped_actor self{system};
self->request(config_server, infinite, get_atom::value, "*").receive(
......
......@@ -47,7 +47,7 @@ second_stage::behavior_type typed_second_stage() {
return x * y;
},
[](double x) {
return 23.0f * x;
return 23.0 * x;
}
};
}
......
......@@ -85,9 +85,9 @@ struct fixture {
}
);
if (expect_fail)
CAF_REQUIRE(result.unsafe());
CAF_REQUIRE(!result);
else
CAF_REQUIRE(!result.unsafe());
CAF_REQUIRE(result);
return result;
}
......@@ -121,7 +121,7 @@ CAF_TEST(unpublishing) {
down_msg{testee.address(), exit_reason::normal});
// must fail now
auto x2 = remote_actor("127.0.0.1", port, true);
CAF_CHECK(x2.unsafe());
CAF_CHECK(!x2);
}
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