Skip to content

Reallocate default-initialized strings once on deserialization - #87

Merged
David-LP99 merged 2 commits into
rollingfrom
fix/string_reservation_v3
Oct 14, 2026
Merged

David-LP99 merged 2 commits into
rollingfrom
fix/string_reservation_v3

Conversation

@David-LP99

Copy link
Copy Markdown

Description

This PR addresses received strings that are still in the state left by rosidl_runtime_c__String__init() (capacity 1). Since strings are deserialized in place, those buffers can only hold an empty string, so longer ones are skipped.

Before ros2/rclc#455, the default size was 50, which allow not having to reallocate. This broke, for example, the rclc parameter server requests. Those buffers are now reallocated once to a reserved size, while user-provided buffers are left untouched.

Main changes

  • Add rosidl_typesupport_microxrcedds_c__deserialize_string() to message_type_support.h, used by the message template for both single strings and string sequences
  • Reallocate strings with capacity 1 once, using the rcutils default allocator, to ROSIDL_TYPESUPPORT_MICROXRCEDDS_C_STRING_RESERVATION bytes (50 by default, 0 disables it). Strings longer than the reservation are still skipped without reallocating
  • Declare the rcutils dependency in package.xml and CMakeLists.txt
  • The reservation can be changed by adding -DROSIDL_TYPESUPPORT_MICROXRCEDDS_C_STRING_RESERVATION=<n> to CMAKE_C_FLAGS. This does not reach the tests, which are C++ and keep using the default value
  • Add test_string_reservation.cpp, covering the reservation limit, string sequences, user-provided buffers and the alignment of the members following a string

Signed-off-by: David Laseca Perez <davidlaseca@eprosima.com>
Signed-off-by: David Laseca Perez <davidlaseca@eprosima.com>
@mergify

mergify Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

David-LP99 added a commit to micro-ROS/micro_ros_renesas_testbench that referenced this pull request Oct 14, 2026
The rolling parameter server requests fail to deserialize on the board
because rclc preallocates the request strings with capacity 1. Clone
the typesupport from the fix/string_reservation_v3 branch in every
component until micro-ROS/rosidl_typesupport_microxrcedds#87 is merged,
and print the commit each library was built with.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@EugenioCollado EugenioCollado left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@David-LP99
David-LP99 merged commit 5412994 into rolling Oct 14, 2026
4 checks passed
@David-LP99
David-LP99 deleted the fix/string_reservation_v3 branch October 14, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants