From accef1411ae69214ae6485efb1edb91e22f667ea Mon Sep 17 00:00:00 2001 From: Nikolai Morin Date: Sat, 9 Jul 2022 22:24:47 +0200 Subject: [PATCH 1/2] Make loaned messages const on the subscription side Signed-off-by: Nikolai Morin --- rcl/include/rcl/subscription.h | 4 ++-- rcl/src/rcl/subscription.c | 4 ++-- rcl/test/rcl/test_subscription.cpp | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rcl/include/rcl/subscription.h b/rcl/include/rcl/subscription.h index 28bbf1713..1d48d0775 100644 --- a/rcl/include/rcl/subscription.h +++ b/rcl/include/rcl/subscription.h @@ -630,7 +630,7 @@ RCL_WARN_UNUSED rcl_ret_t rcl_take_loaned_message( const rcl_subscription_t * subscription, - void ** loaned_message, + const void ** loaned_message, rmw_message_info_t * message_info, rmw_subscription_allocation_t * allocation); @@ -662,7 +662,7 @@ RCL_WARN_UNUSED rcl_ret_t rcl_return_loaned_message_from_subscription( const rcl_subscription_t * subscription, - void * loaned_message); + const void * loaned_message); /// Get the topic name for the subscription. /** diff --git a/rcl/src/rcl/subscription.c b/rcl/src/rcl/subscription.c index fd5984ded..af14585c4 100644 --- a/rcl/src/rcl/subscription.c +++ b/rcl/src/rcl/subscription.c @@ -610,7 +610,7 @@ rcl_take_serialized_message( rcl_ret_t rcl_take_loaned_message( const rcl_subscription_t * subscription, - void ** loaned_message, + const void ** loaned_message, rmw_message_info_t * message_info, rmw_subscription_allocation_t * allocation) { @@ -646,7 +646,7 @@ rcl_take_loaned_message( rcl_ret_t rcl_return_loaned_message_from_subscription( const rcl_subscription_t * subscription, - void * loaned_message) + const void * loaned_message) { RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription releasing loaned message"); if (!rcl_subscription_is_valid(subscription)) { diff --git a/rcl/test/rcl/test_subscription.cpp b/rcl/test/rcl/test_subscription.cpp index 46bd15213..33df6c904 100644 --- a/rcl/test/rcl/test_subscription.cpp +++ b/rcl/test/rcl/test_subscription.cpp @@ -703,9 +703,9 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_subscription }); } - test_msgs__msg__Strings * msg_loaned = nullptr; + const test_msgs__msg__Strings * msg_loaned = nullptr; ret = rcl_take_loaned_message( - &subscription, reinterpret_cast(&msg_loaned), nullptr, nullptr); + &subscription, reinterpret_cast(&msg_loaned), nullptr, nullptr); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; EXPECT_EQ( std::string(test_string), @@ -764,8 +764,9 @@ TEST_F(CLASSNAME(TestSubscriptionFixture, RMW_IMPLEMENTATION), test_bad_take_loa &subscription_options); ASSERT_EQ(RMW_RET_OK, ret) << rcl_get_error_string().str; - test_msgs__msg__Strings * loaned_message = nullptr; - void ** type_erased_loaned_message_pointer = reinterpret_cast(&loaned_message); + const test_msgs__msg__Strings * loaned_message = nullptr; + const void ** type_erased_loaned_message_pointer = + reinterpret_cast(&loaned_message); rmw_message_info_t * message_info = nullptr; // is a valid argument rmw_subscription_allocation_t * allocation = nullptr; // is a valid argument EXPECT_EQ( From b8ef6a76b455848aa250ed799dc2c00ff12ba071 Mon Sep 17 00:00:00 2001 From: Nikolai Morin Date: Tue, 12 Jul 2022 15:00:41 +0200 Subject: [PATCH 2/2] Fix compiler warnings by casting away constness explicitly Signed-off-by: Nikolai Morin --- rcl/src/rcl/subscription.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rcl/src/rcl/subscription.c b/rcl/src/rcl/subscription.c index af14585c4..6f2442eac 100644 --- a/rcl/src/rcl/subscription.c +++ b/rcl/src/rcl/subscription.c @@ -630,7 +630,8 @@ rcl_take_loaned_message( // Call rmw_take_with_info. bool taken = false; rmw_ret_t ret = rmw_take_loaned_message_with_info( - subscription->impl->rmw_handle, loaned_message, &taken, message_info_local, allocation); + subscription->impl->rmw_handle, (void **) loaned_message, &taken, message_info_local, + allocation); if (ret != RMW_RET_OK) { RCL_SET_ERROR_MSG(rmw_get_error_string().str); return rcl_convert_rmw_ret_to_rcl_ret(ret); @@ -655,7 +656,7 @@ rcl_return_loaned_message_from_subscription( RCL_CHECK_ARGUMENT_FOR_NULL(loaned_message, RCL_RET_INVALID_ARGUMENT); return rcl_convert_rmw_ret_to_rcl_ret( rmw_return_loaned_message_from_subscription( - subscription->impl->rmw_handle, loaned_message)); + subscription->impl->rmw_handle, (void *) loaned_message)); } const char *