Update rosidl cpp path to emit rosidl::Buffer for uint8[] type#942
Update rosidl cpp path to emit rosidl::Buffer for uint8[] type#942
Conversation
0f9fd11 to
986d123
Compare
3085e51 to
f06ac85
Compare
326b4f8 to
c53b788
Compare
20ba671 to
4623bdf
Compare
4623bdf to
d04fd63
Compare
a19b54f to
6ec582e
Compare
c3f83ab to
a79158a
Compare
57e8d58 to
2bd85fd
Compare
|
Pulls: #942 |
|
This PR depends on ros2/rosidl_typesupport_fastrtps#144 so can't be CI-tested alone. |
|
Triggered with custom ros2.repos that contain all PRs: https://raw.githubusercontent.com/nvcyc/ros2/refs/heads/rolling-native-buffer-prs/ros2.repos Started by user CY Chen |
Signed-off-by: CY Chen <cyc@nvidia.com>
Signed-off-by: CY Chen <cyc@nvidia.com>
2bd85fd to
3a8edd9
Compare
* Add support for rosidl::Buffer in rosidl C path for rclpy Signed-off-by: CY Chen <cyc@nvidia.com> * Add rosidl_buffer_py to rosidl_runtime_packages group Signed-off-by: CY Chen <cyc@nvidia.com> * Remove unused has_buffer_fields_ field from introspection C Signed-off-by: CY Chen <cyc@nvidia.com> * Simplify rosidl_buffer Python bindings Signed-off-by: CY Chen <cyc@nvidia.com> * Add owns_rosidl_buffer in sequence struct to handle buffer lifecycle Signed-off-by: CY Chen <cyc@nvidia.com> * Add Python type stub for Buffer class Signed-off-by: CY Chen <cyc@nvidia.com> * Remove unused test assertion for introspection Signed-off-by: CY Chen <cyc@nvidia.com> * Add comments for the limitation of _take_buffer_from_ptr Signed-off-by: CY Chen <cyc@nvidia.com> * Revert adding a line in msg__functions.c.em Signed-off-by: CY Chen <cyc@nvidia.com> * Update rosidl_buffer/c_helpers.h to use the right comment style Signed-off-by: CY Chen <cyc@nvidia.com> --------- Signed-off-by: CY Chen <cyc@nvidia.com>
) ROS 2 Rolling merged ros2/rosidl#941 and ros2/rosidl#942 as part of the native buffer feature. The ROSIDL_RUNTIME_C__PRIMITIVE_SEQUENCE macro now emits two extra boolean fields (is_rosidl_buffer, owns_rosidl_buffer) in every primitive sequence struct, growing them from 24 to 32 bytes. Non-primitive sequences (e.g. Parameter__Sequence) are unchanged at 24 bytes. The rclnodejs code generator produces ref-struct-di definitions for these sequence types. Because the generated layout lacked the new fields, every message containing a primitive sequence had misaligned field offsets when serialized, causing Fast DDS to segfault in get_serialized_size_* during rcl_publish. Changes: 1. rosidl_gen/templates/message-template.js — Detect Rolling+ at generation time via DistroUtils.getDistroId() and compute needsRosidlBufferFields once per message. Conditionally emit is_rosidl_buffer and owns_rosidl_buffer in the generated sequence struct only for primitive-package types (Bool, Byte, Int8, …, Float64, String) on Rolling+. Generated files get clean, static struct definitions with no runtime require() or ternary. 2. .github/workflows/linux-x64-build-and-test.yml — Add rosidl_buffer_py and pybind11 to rosdep --skip-keys for the Rolling nightly install, since these new packages from the native buffer feature have unresolvable rosdep keys in the tarball context. Verified: Rolling: test-parameters (33), test-parameter-service (9), test-action-client (19) — all pass. Jazzy: test-parameters (33), test-parameter-service (9), test-action-client (18+1 pending) — all pass. Fix: #1481
Description
This pull request makes the C++ rosidl layer Buffer-aware, enabling
rclcppmessage types to userosidl::Buffer<uint8_t>foruint8[]fields. It modifiesrosidl_runtime_cpp,rosidl_generator_cpp, androsidl_typesupport_introspection_cppso that generated C++ messages, trait utilities, and introspection metadata all understand the new Buffer type introduced in PR #941.This pull request consists of the following key changes:
rosidl_runtime_cpp: Added trait specializations forBuffer<T>and a dependency onrosidl_buffer.rosidl_generator_cpp: The code generator now emitsrosidl::Buffer<uint8_t>instead ofstd::vector<uint8_t>foruint8[]message fields.rosidl_typesupport_introspection_cpp: The goal for the changes in C++ introspection is to keep it working with CPU-based buffers. The buffer-based introspection accessors throw exceptions for non-CPU backends.Is this user-facing behavior change?
With this PR, all C++ message types with
uint8[]fields (e.g.,sensor_msgs::msg::Image::data) will have their field type changed fromstd::vector<uint8_t>torosidl::Buffer<uint8_t>. By default, a CPU-basedBuffer<T>type is used, which is a transparent drop-in replacement forstd::vector<T>, so existing user code should compile and work unchanged.Did you use Generative AI?
Yes. Claude (claude-4.6-opus) via Cursor was used to assist with creating an initial prototype version of the changes contained in this PR.
Additional Information
This PR is part of the broader ROS 2 native buffer feature introduced in this post. It depends on PR #941 (
rosidl_buffer+rosidl_buffer_backend).