Skip to content

Commit

Permalink
[#15] Fix GCC build
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Dec 21, 2024
1 parent e2b86ae commit 0bb15a6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 55 deletions.
1 change: 1 addition & 0 deletions mason-receipt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schema_version":"1.1","primary_source":{"type":"local"},"name":"clangd","links":{"share":{"mason-schemas/lsp/clangd.json":"mason-schemas/lsp.json"}}}
85 changes: 42 additions & 43 deletions rmw_iceoryx2_cxx/src/rmw/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ extern "C" {
namespace
{

void inline destroy_node_impl(rmw_node_t* node) noexcept {
void inline destroy_rmw_node(rmw_node_t* rmw_node) noexcept {
using rmw::iox2::deallocate;
using rmw::iox2::destruct;
using rmw::iox2::NodeImpl;

if (node) {
deallocate(node->name);
deallocate(node->namespace_);
if (node->data) {
destruct<NodeImpl>(node->data);
deallocate(node->data);
if (rmw_node) {
deallocate(rmw_node->name);
deallocate(rmw_node->namespace_);
if (rmw_node->data) {
destruct<NodeImpl>(rmw_node->data);
deallocate(rmw_node->data);
}
rmw_node_free(node);
rmw_node_free(rmw_node);
}
}

Expand All @@ -64,71 +64,70 @@ rmw_node_t* rmw_create_node(rmw_context_t* context, const char* name, const char

RMW_IOX2_LOG_DEBUG("Creating node '%s' in namespace '%s'", name, namespace_);

rmw_node_t* node = rmw_node_allocate();
if (!node) {
rmw_node_t* rmw_node = rmw_node_allocate();
if (!rmw_node) {
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for node handle");
return nullptr;
}
node->context = context;
node->implementation_identifier = rmw_get_implementation_identifier();
rmw_node->context = context;
rmw_node->implementation_identifier = rmw_get_implementation_identifier();

auto name_ptr = allocate_copy(name);
if (name_ptr.has_error()) {
destroy_node_impl(node);
auto name_copy = allocate_copy(name);
if (name_copy.has_error()) {
destroy_rmw_node(rmw_node);
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for node name");
return nullptr;
}
node->name = name_ptr.value();
rmw_node->name = name_copy.value();

auto namespace_ptr = allocate_copy(namespace_);
if (namespace_ptr.has_error()) {
destroy_node_impl(node);
auto namespace_copy = allocate_copy(namespace_);
if (namespace_copy.has_error()) {
destroy_rmw_node(rmw_node);
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for node namespace");
return nullptr;
}
node->namespace_ = namespace_ptr.value();
rmw_node->namespace_ = namespace_copy.value();

auto ptr = allocate<NodeImpl>();
if (ptr.has_error()) {
destroy_node_impl(node);
auto impl_allocation = allocate<NodeImpl>();
if (impl_allocation.has_error()) {
destroy_rmw_node(rmw_node);
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for NodeImpl");
return nullptr;
}
auto impl_ptr = impl_allocation.value();

if (auto construction = create_in_place<NodeImpl>(ptr.value(), *context->impl, node->name, node->namespace_);
if (auto construction = create_in_place<NodeImpl>(impl_ptr, *context->impl, rmw_node->name, rmw_node->namespace_);
construction.has_error()) {
destruct<NodeImpl>(ptr.value());
deallocate<NodeImpl>(ptr.value());
destroy_node_impl(node);
destruct<NodeImpl>(impl_ptr);
deallocate<NodeImpl>(impl_ptr);
destroy_rmw_node(rmw_node);
RMW_IOX2_CHAIN_ERROR_MSG("failed to construct NodeImpl");
return nullptr;
}
node->data = ptr.value();
rmw_node->data = impl_allocation.value();

return node;
return rmw_node;
}

rmw_ret_t rmw_destroy_node(rmw_node_t* node) {
rmw_ret_t rmw_destroy_node(rmw_node_t* rmw_node) {
// Invariants ----------------------------------------------------------------------------------

RMW_IOX2_ENSURE_NOT_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);

// Implementation -------------------------------------------------------------------------------
RMW_IOX2_LOG_DEBUG("Destroying node '%s' in namespace '%s'", rmw_node->name, rmw_node->namespace_);

RMW_IOX2_LOG_DEBUG("Destroying node '%s' in namespace '%s'", node->name, node->namespace_);

destroy_node_impl(node);
destroy_rmw_node(rmw_node);

return RMW_RET_OK;
}

const rmw_guard_condition_t* rmw_node_get_graph_guard_condition(const rmw_node_t* node) {
const rmw_guard_condition_t* rmw_node_get_graph_guard_condition(const rmw_node_t* rmw_node) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(node, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(node->context, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(node->context->impl, nullptr);
RMW_IOX2_ENSURE_IMPLEMENTATION(node->implementation_identifier, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node->context, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node->context->impl, nullptr);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_node->implementation_identifier, nullptr);

// Implementation -------------------------------------------------------------------------------
using rmw::iox2::NodeImpl;
Expand All @@ -141,9 +140,9 @@ const rmw_guard_condition_t* rmw_node_get_graph_guard_condition(const rmw_node_t
}

guard_condition->implementation_identifier = rmw_get_implementation_identifier();
guard_condition->context = node->context;
guard_condition->context = rmw_node->context;

auto node_impl = unsafe_cast<NodeImpl*>(node->data);
auto node_impl = unsafe_cast<NodeImpl*>(rmw_node->data);
if (node_impl.has_error()) {
RMW_IOX2_CHAIN_ERROR_MSG("failed to retrieve NodeImpl");
return nullptr;
Expand Down
12 changes: 5 additions & 7 deletions rmw_iceoryx2_cxx/test/test_rmw_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ TEST_F(AllocatorHelpersTest, construct_and_destruct) {

auto ptr = allocation.value();
auto constructed = rmw::iox2::construct(ptr);
ASSERT_TRUE(constructed.has_value());
ASSERT_FALSE(constructed.has_error());
ASSERT_EQ(ptr->value, 42);

auto obj = constructed.value();
ASSERT_EQ(obj->value, 42);
rmw::iox2::destruct<DummyClass>(ptr);
ASSERT_EQ(ptr->value, 0);

rmw::iox2::destruct<DummyClass>(obj);
ASSERT_EQ(obj->value, 0);

rmw::iox2::deallocate(obj);
rmw::iox2::deallocate(ptr);
}

TEST_F(AllocatorHelpersTest, destruct_nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion rmw_iceoryx2_cxx/test/test_rmw_guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RmwGuardConditionTest : public TestBase
auto listener = service.listener_builder().create().expect("failed to create test listener");

return listener;
};
}

private:
iox::optional<::rmw::iox2::Iceoryx2> m_iox2;
Expand Down
8 changes: 4 additions & 4 deletions rmw_iceoryx2_cxx/test/test_rmw_waitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class WaitSetTestContext

~WaitSetTestContext() {
for (size_t i = 0; i < m_subscriptions.size(); i++) {
(void)rmw_destroy_publisher(m_rmw_node, m_publishers.at(i).publisher);
(void)rmw_destroy_subscription(m_rmw_node, m_subscriptions.at(i).subscriber);
EXPECT_RMW_OK(rmw_destroy_publisher(m_rmw_node, m_publishers.at(i).publisher));
EXPECT_RMW_OK(rmw_destroy_subscription(m_rmw_node, m_subscriptions.at(i).subscriber));
}
for (size_t i = 0; i < m_guard_conditions.size(); i++) {
(void)rmw_destroy_guard_condition(m_guard_conditions.at(i));
EXPECT_RMW_OK(rmw_destroy_guard_condition(m_guard_conditions.at(i)));
}
if (m_waitset) {
(void)rmw_destroy_wait_set(m_waitset);
EXPECT_RMW_OK(rmw_destroy_wait_set(m_waitset));
}
}

Expand Down

0 comments on commit 0bb15a6

Please sign in to comment.