diff --git a/mason-receipt.json b/mason-receipt.json new file mode 100644 index 0000000..ca10bb8 --- /dev/null +++ b/mason-receipt.json @@ -0,0 +1 @@ +{"schema_version":"1.1","primary_source":{"type":"local"},"name":"clangd","links":{"share":{"mason-schemas/lsp/clangd.json":"mason-schemas/lsp.json"}}} diff --git a/rmw_iceoryx2_cxx/src/rmw/node.cpp b/rmw_iceoryx2_cxx/src/rmw/node.cpp index cf57c7b..0612a2e 100644 --- a/rmw_iceoryx2_cxx/src/rmw/node.cpp +++ b/rmw_iceoryx2_cxx/src/rmw/node.cpp @@ -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(node->data); - deallocate(node->data); + if (rmw_node) { + deallocate(rmw_node->name); + deallocate(rmw_node->namespace_); + if (rmw_node->data) { + destruct(rmw_node->data); + deallocate(rmw_node->data); } - rmw_node_free(node); + rmw_node_free(rmw_node); } } @@ -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(); - if (ptr.has_error()) { - destroy_node_impl(node); + auto impl_allocation = allocate(); + 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(ptr.value(), *context->impl, node->name, node->namespace_); + if (auto construction = create_in_place(impl_ptr, *context->impl, rmw_node->name, rmw_node->namespace_); construction.has_error()) { - destruct(ptr.value()); - deallocate(ptr.value()); - destroy_node_impl(node); + destruct(impl_ptr); + deallocate(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; @@ -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(node->data); + auto node_impl = unsafe_cast(rmw_node->data); if (node_impl.has_error()) { RMW_IOX2_CHAIN_ERROR_MSG("failed to retrieve NodeImpl"); return nullptr; diff --git a/rmw_iceoryx2_cxx/test/test_rmw_allocator.cpp b/rmw_iceoryx2_cxx/test/test_rmw_allocator.cpp index 8bba5ef..37f1ba0 100644 --- a/rmw_iceoryx2_cxx/test/test_rmw_allocator.cpp +++ b/rmw_iceoryx2_cxx/test/test_rmw_allocator.cpp @@ -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(ptr); + ASSERT_EQ(ptr->value, 0); - rmw::iox2::destruct(obj); - ASSERT_EQ(obj->value, 0); - - rmw::iox2::deallocate(obj); + rmw::iox2::deallocate(ptr); } TEST_F(AllocatorHelpersTest, destruct_nullptr) { diff --git a/rmw_iceoryx2_cxx/test/test_rmw_guard_condition.cpp b/rmw_iceoryx2_cxx/test/test_rmw_guard_condition.cpp index 77f10c3..445321d 100644 --- a/rmw_iceoryx2_cxx/test/test_rmw_guard_condition.cpp +++ b/rmw_iceoryx2_cxx/test/test_rmw_guard_condition.cpp @@ -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; diff --git a/rmw_iceoryx2_cxx/test/test_rmw_waitset.cpp b/rmw_iceoryx2_cxx/test/test_rmw_waitset.cpp index 12fbe00..f694638 100644 --- a/rmw_iceoryx2_cxx/test/test_rmw_waitset.cpp +++ b/rmw_iceoryx2_cxx/test/test_rmw_waitset.cpp @@ -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)); } }