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..6f2442eac 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) { @@ -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); @@ -646,7 +647,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)) { @@ -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 * 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(