Repository navigation
Make rmw_send_response take a const response - #437
Conversation
In ros2/examples#478 I've noticed that rclcpp send_reponse takes a mutable reference to the response. I think this a bug in the API as you only need a constant reference to serialize a message. The documentation for rmw verifies that: Access to the given ROS service response is read-only but it is not synchronized. https://github.com/ros2/rmw/blob/0932be49fb6b3c9a8f3de82cf894bb628d7af59c/rmw/include/rmw/rmw.h#L2403 This bug affects multiple layers, so I'm starting the discussion here if my assumptions are correct. Can we change the message to a const reference? If we want this, this change must be accompanied by changes in the following packages: - rmw_implementation - rmw_fastrtps rmw_fastrtps_cpp - rcl - rclcpp - Other rmw implementations (Cyclone DDS, Connext, Zenoh, ...) need the same signature change. The alternative to this is to do a const_cast in rclcpp. Co-authored-by: Copilot <[email protected]> Signed-off-by: Ramon Wijnands <[email protected]>
|
Yeah, I think this is the right move, and you have already identified the packages that would need to be updated (as well as any other rmw implementation). |
|
@skyegalaxy @Rayman i created the corresponding PRs above to go with this PR, all of them are quick patches, can you review and approve? |
|
Pulls: ros2/rmw_implementation#313, ros2/rmw_fastrtps#968, ros2/rmw_cyclonedds#640, ros2/rmw_connextdds#267, ros2/rclcpp#3400, ros2/rcl#1358, #437, ros2/rmw_zenoh#1100 |
|
I had all the diffs the same as you, except the |
|
Ready to merge? |
|
Pulls: ros2/rmw_implementation#313, ros2/rmw_fastrtps#968, ros2/rmw_cyclonedds#640, ros2/rmw_connextdds#267, ros2/rclcpp#3400, ros2/rcl#1358, #437, ros2/rmw_zenoh#1100 |
Update the rmw_send_response forwarding signature to const void * ros_response. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Update rmw_send_response and the shared __rmw_send_response helper to take const void * ros_response. The response is already passed to the DataWriter through a const_cast, so no behavior changes. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Update rmw_send_response to take const void * ros_response. The internal rmw_send_response_request helper already took a const pointer, so no behavior changes. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Update rmw_send_response (Connext Pro and Micro entry points) and rmw_api_connextdds_send_response to take const void * ros_response. RMW_Connext_Service::send_response already took a const pointer, so no behavior changes. Both the rmw_connextdds and rmw_connextdds_common copies of the sources are updated. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Service<ServiceT>::send_response now takes const ServiceT::Response &, and GenericService::send_response takes const SharedResponse &. The response is only forwarded to rcl_send_response, which now takes a const pointer. Existing callers passing non-const responses continue to compile. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
Update rcl_send_response and the rcl_action_send_{goal,result,cancel}_response functions to take const void * for the response. The response is only read and forwarded to rmw_send_response, and the documentation already states that it is left unmodified. This is also consistent with rcl_send_request and the rcl_action_send_*_request functions, which already take const void *.
Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.
Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Update rmw_send_response and ServiceData::send_response to take const void * ros_response. The type support serialization functions already take a const pointer, so no behavior changes. Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request. Signed-off-by: Tomoya Fujita <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
…w 7.11.4) (#104) ros2/rmw#437, released in rmw 7.11.4 on Rolling, changed the response parameter of rmw_send_response from `void *` to `const void *`. Our definition sits in an extern "C" block, so the old signature is now a "conflicting declaration of C function" and the Rolling build farm job (Rbin_unv8_uRv8 rmw_unix_socket_cpp #2) fails. Gate the parameter on rmw_VERSION >= 7.11.4. jazzy (7.3.4) and lyrical (7.10.3) keep `void *`; the body already passes the pointer to shm_serialize_prepare_send, which takes `const void *`.
Description
In ros2/examples#478 I've noticed that rclcpp send_reponse takes a mutable reference to the response. I think this a bug in the API as you only need a constant reference to serialize a message. The documentation for rmw verifies that:
This bug affects multiple layers, so I'm starting the discussion here if my assumptions are correct. Can we change the message to a const reference?
If we want this, this change must be accompanied by changes in the following packages:
The alternative to this is to do a const_cast in rclcpp.
Fixes # (issue)
Is this user-facing behavior change?
Did you use Generative AI?
GitHub Copilot with sonnet 5.5
Additional Information