Skip to content

Commit

Permalink
Fixing component multiple inheritance
Browse files Browse the repository at this point in the history
- flyby: fixing get_ptr<>(sync)
  • Loading branch information
hkaiser committed Jul 29, 2022
1 parent acdb34f commit 882063b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 3 deletions.
3 changes: 2 additions & 1 deletion libs/full/components/include/hpx/components/get_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ namespace hpx {
naming::get_locality_id_from_gid(gid) == agas::get_locality_id(ec))
{
return std::shared_ptr<Component>(
get_lva<Component>::call(gid.get_lsb()),
get_lva<Component>::call(
reinterpret_cast<hpx::naming::address_type>(gid.get_lsb())),
detail::get_ptr_no_unpin_deleter(id));
}

Expand Down
22 changes: 21 additions & 1 deletion libs/full/components/tests/regressions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Copyright (c) 2020-2021 The STE||AR-Group
# Copyright (c) 2022 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set(tests multiple_inheritance_5964)

foreach(test ${tests})
set(sources ${test}.cpp)

source_group("Source Files" FILES ${sources})

set(folder_name "Tests/Regressions/Modules/Full/Components")

# add example executable
add_hpx_executable(
${test}_test INTERNAL_FLAGS
SOURCES ${sources} ${${test}_FLAGS}
EXCLUDE_FROM_ALL
FOLDER ${folder_name}
)

add_hpx_regression_test("modules.components" ${test} ${${test}_PARAMETERS})
endforeach()
107 changes: 107 additions & 0 deletions libs/full/components/tests/regressions/multiple_inheritance_5964.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) 2022 Joseph Kleinhenz
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// This test illustrates the problem reported by #5964: component with multiple
// inheritance

#include <hpx/config.hpp>

#if !defined(HPX_COMPUTE_DEVICE_CODE)
#include <hpx/hpx_init.hpp>
#include <hpx/include/actions.hpp>
#include <hpx/include/async.hpp>
#include <hpx/include/components.hpp>
#include <hpx/include/runtime.hpp>
#include <hpx/include/util.hpp>
#include <hpx/modules/testing.hpp>

#include <atomic>
#include <cstddef>
#include <utility>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
struct foo_t
{
int a;
int b;

foo_t() = default;
foo_t(int a, int b)
: a(a)
, b(b)
{
}

friend class hpx::serialization::access;
template <typename Archive>
inline void serialize(Archive& ar, const unsigned int)
{
// clang-format off
ar & a & b;
// clang-format on
}
};

struct component_server
: hpx::components::component_base<component_server>
, foo_t
{
explicit component_server(foo_t foo)
: foo_t(std::move(foo))
{
}
};

HPX_REGISTER_COMPONENT(
hpx::components::component<component_server>, component_server_component)

struct component_server2
: foo_t
, hpx::components::component_base<component_server2>

{
explicit component_server2(foo_t foo)
: foo_t(std::move(foo))
{
}
};

HPX_REGISTER_COMPONENT(
hpx::components::component<component_server2>, component_server2_component)

int hpx_main()
{
foo_t in{1, 2};

{
hpx::id_type id =
hpx::new_<component_server>(hpx::find_here(), in).get();
auto out = hpx::get_ptr<component_server>(hpx::launch::sync, id);

HPX_TEST_EQ(out->a, in.a);
HPX_TEST_EQ(out->b, in.b);
}

{
hpx::id_type id =
hpx::new_<component_server2>(hpx::find_here(), in).get();
auto out = hpx::get_ptr<component_server2>(hpx::launch::sync, id);

HPX_TEST_EQ(out->a, in.a);
HPX_TEST_EQ(out->b, in.b);
}

return hpx::finalize();
}

int main(int argc, char** argv)
{
HPX_TEST_EQ(hpx::init(argc, argv), 0);
return hpx::util::report_errors();
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace hpx { namespace components {
return naming::address(
naming::get_gid_from_locality_id(agas::get_locality_id()),
components::get_component_type<wrapped_type>(),
const_cast<component_base*>(this));
const_cast<Component*>(static_cast<Component const*>(this)));
}

hpx::id_type get_id() const
Expand Down

0 comments on commit 882063b

Please sign in to comment.