From 9f23e8ade8bc59ca3d9c57a9310ededcbf70daf4 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 13 Jan 2024 09:29:08 -0600 Subject: [PATCH] Attempting to avoid segfault in OctoTiger during initialization --- .../include/hpx/futures/future_or_value.hpp | 14 ++++----- .../include/hpx/type_support/extra_data.hpp | 30 +++++++++---------- libs/full/agas/src/detail/interface.cpp | 2 +- .../async_colocated/src/get_colocation_id.cpp | 6 ++-- .../hpx/async_distributed/put_parcel.hpp | 2 +- .../include/hpx/components/client_base.hpp | 5 ++-- .../include/hpx/components/get_ptr.hpp | 4 ++- libs/full/components/src/client_base.cpp | 14 ++++----- .../components_base/src/agas_interface.cpp | 4 ++- 9 files changed, 42 insertions(+), 39 deletions(-) diff --git a/libs/core/futures/include/hpx/futures/future_or_value.hpp b/libs/core/futures/include/hpx/futures/future_or_value.hpp index a549ee12659e..eeb60dcd0096 100644 --- a/libs/core/futures/include/hpx/futures/future_or_value.hpp +++ b/libs/core/futures/include/hpx/futures/future_or_value.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Hartmut Kaiser +// Copyright (c) 2022-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -30,11 +30,11 @@ namespace hpx { { } - constexpr bool has_value() const noexcept + [[nodiscard]] constexpr bool has_value() const noexcept { return hpx::holds_alternative(data); } - constexpr bool has_future() const noexcept + [[nodiscard]] constexpr bool has_future() const noexcept { return hpx::holds_alternative>(data); } @@ -43,11 +43,11 @@ namespace hpx { { return hpx::get(data); } - constexpr T const& get_value() const& + [[nodiscard]] constexpr T const& get_value() const& { return hpx::get(data); } - constexpr T&& get_value() && + constexpr T get_value() && { return hpx::get(HPX_MOVE(data)); } @@ -56,11 +56,11 @@ namespace hpx { { return hpx::get>(data); } - constexpr hpx::future const& get_future() const& + [[nodiscard]] constexpr hpx::future const& get_future() const& { return hpx::get>(data); } - constexpr hpx::future&& get_future() && + constexpr hpx::future get_future() && { return hpx::get>(HPX_MOVE(data)); } diff --git a/libs/core/type_support/include/hpx/type_support/extra_data.hpp b/libs/core/type_support/include/hpx/type_support/extra_data.hpp index c55d72cc2361..c4fe86fbb7e4 100644 --- a/libs/core/type_support/include/hpx/type_support/extra_data.hpp +++ b/libs/core/type_support/include/hpx/type_support/extra_data.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2019 Thomas Heller -// Copyright (c) 2019-2023 Hartmut Kaiser +// Copyright (c) 2019-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,15 +7,13 @@ #pragma once -#include - #include #include #include namespace hpx::util { - using extra_data_id_type = void*; + using extra_data_id_type = void const*; template struct extra_data_helper @@ -61,7 +59,12 @@ namespace hpx::util { ~extra_data_node() = default; template - [[nodiscard]] T* get() const noexcept; + [[nodiscard]] constexpr T* get() const noexcept; + + [[nodiscard]] explicit constexpr operator bool() const noexcept + { + return id_ != nullptr && ptr_; + } std::unique_ptr ptr_; extra_data_id_type id_ = nullptr; @@ -89,7 +92,7 @@ namespace hpx::util { }; template - struct extra_data_member : extra_data_member_base + struct extra_data_member final : extra_data_member_base { explicit constexpr extra_data_member(extra_data_node&& next) noexcept : extra_data_member_base(HPX_MOVE(next)) @@ -124,17 +127,14 @@ namespace hpx::util { } template - T* extra_data_node::get() const noexcept + constexpr T* extra_data_node::get() const noexcept { - auto id = extra_data_id(); - if (id_ == nullptr) + if (!*this) { - HPX_ASSERT(!ptr_); return nullptr; } - HPX_ASSERT(ptr_); - if (id_ == id) + if (id_ == extra_data_id()) { return static_cast*>(ptr_.get())->value(); } @@ -144,7 +144,7 @@ namespace hpx::util { struct extra_data { - extra_data() noexcept = default; + constexpr extra_data() noexcept = default; template T& get() @@ -159,9 +159,9 @@ namespace hpx::util { } template - [[nodiscard]] T* try_get() const noexcept + [[nodiscard]] constexpr T* try_get() const noexcept { - return head_.get(); + return head_ ? head_.get() : nullptr; } // reset all extra archive data diff --git a/libs/full/agas/src/detail/interface.cpp b/libs/full/agas/src/detail/interface.cpp index e9e1cd63567e..e72fb2c6eb34 100644 --- a/libs/full/agas/src/detail/interface.cpp +++ b/libs/full/agas/src/detail/interface.cpp @@ -377,7 +377,7 @@ namespace hpx::agas::detail::impl { return naming::invalid_gid; } - // during bootstrap we use the id pool + // during bootstrap, we use the id pool if (rt->get_state() == state::invalid) { return hpx::detail::get_next_id(count); diff --git a/libs/full/async_colocated/src/get_colocation_id.cpp b/libs/full/async_colocated/src/get_colocation_id.cpp index fa6b48a1bffb..e3d7ffb108b9 100644 --- a/libs/full/async_colocated/src/get_colocation_id.cpp +++ b/libs/full/async_colocated/src/get_colocation_id.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2020 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -28,6 +28,8 @@ namespace hpx { { return hpx::make_ready_future(HPX_MOVE(result).get_value()); } - return HPX_MOVE(result).get_future(); + + auto f = HPX_MOVE(result).get_future(); + return f; } } // namespace hpx diff --git a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp index a1e2a26ddb6c..449979cd5fb3 100644 --- a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp +++ b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp @@ -141,7 +141,7 @@ namespace hpx::parcelset { { HPX_ASSERT(result.has_future()); - auto&& split_gid = HPX_MOVE(result).get_future(); + auto split_gid = HPX_MOVE(result).get_future(); if (split_gid.is_ready()) { pp(detail::create_parcel::call_with_action( diff --git a/libs/full/components/include/hpx/components/client_base.hpp b/libs/full/components/include/hpx/components/client_base.hpp index 97d3829c0277..1d3117f00d86 100644 --- a/libs/full/components/include/hpx/components/client_base.hpp +++ b/libs/full/components/include/hpx/components/client_base.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -183,7 +183,8 @@ template <> struct hpx::util::extra_data_helper { HPX_EXPORT static extra_data_id_type id() noexcept; - HPX_EXPORT static void reset(lcos::detail::registered_name_tracker*); + HPX_EXPORT static void reset( + lcos::detail::registered_name_tracker*) noexcept; }; // namespace hpx::util // Specialization for shared state of id_type, additionally (optionally) holds a diff --git a/libs/full/components/include/hpx/components/get_ptr.hpp b/libs/full/components/include/hpx/components/get_ptr.hpp index 5c072fbc9c45..6ce60786c3bb 100644 --- a/libs/full/components/include/hpx/components/get_ptr.hpp +++ b/libs/full/components/include/hpx/components/get_ptr.hpp @@ -224,7 +224,9 @@ namespace hpx { { return hpx::make_ready_future(HPX_MOVE(result).get_value()); } - return HPX_MOVE(result).get_future(); + + auto f = HPX_MOVE(result).get_future(); + return f; } /// \brief Returns a future referring to the pointer to the diff --git a/libs/full/components/src/client_base.cpp b/libs/full/components/src/client_base.cpp index 347f15949095..f2ec0911c8a0 100644 --- a/libs/full/components/src/client_base.cpp +++ b/libs/full/components/src/client_base.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2007-2024 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -28,9 +28,9 @@ namespace hpx::util { } void extra_data_helper::reset( - lcos::detail::registered_name_tracker* registered_name) + lcos::detail::registered_name_tracker* registered_name) noexcept { - if (!registered_name->empty()) + if (registered_name != nullptr && !registered_name->empty()) { std::string name; std::swap(name, *registered_name); @@ -45,12 +45,8 @@ namespace hpx::lcos::detail { void future_data::tidy() const noexcept { - auto* registered_name = try_get_extra_data(); - if (registered_name != nullptr && !registered_name->empty()) - { - error_code ec(throwmode::lightweight); - agas::unregister_name(launch::sync, HPX_MOVE(*registered_name), ec); - } + hpx::util::extra_data_helper::reset( + try_get_extra_data()); } std::string const& future_data::get_registered_name() diff --git a/libs/full/components_base/src/agas_interface.cpp b/libs/full/components_base/src/agas_interface.cpp index 9f152c84888a..f09228bd1f72 100644 --- a/libs/full/components_base/src/agas_interface.cpp +++ b/libs/full/components_base/src/agas_interface.cpp @@ -163,7 +163,9 @@ namespace hpx::agas { { return hpx::make_ready_future(HPX_MOVE(result).get_value()); } - return HPX_MOVE(result).get_future(); + + auto f = HPX_MOVE(result).get_future(); + return f; } naming::address resolve(