-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RCUtils allocators in rosidl_generator_c #584
Conversation
13a1ded
to
bdeaa15
Compare
Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
938f2cc
to
286e2ac
Compare
Please @clalancette @sloretz let us know your opinions. CC: @Acuadros95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the package.xml
needs a <build_export_depend>rcutils</
so downstream projects get rcutils
when they build the generated target and a <exec_depend>rcutils</
so downstream projects have librcutils.so
around when their targets run.
@@ -235,14 +237,15 @@ for line in lines: | |||
@(message_typename) * | |||
@(message_typename)__create() | |||
{ | |||
@(message_typename) * msg = (@(message_typename) *)malloc(sizeof(@(message_typename))); | |||
rcutils_allocator_t allocator = rcutils_get_default_allocator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in some scenarios is not feasible to use the common dynamic memory API (malloc, free,...).
I think the default allocator uses malloc()
and free()
, and this appears to give no way to change which allocator is used. The __create()
function would need to accept an allocator as an argument for that to be changed.
I would also recommend adding an rcutils_allocator_t
to the message struct so the __destroy()
function is guaranteed to use the same allocator.
is there any possibility of backporting this to Foxy?
If we modify the function signature then this can't be backported because it breaks ABI. If hard coding the default allocator is good enough for your use case (maybe it's enough to be able to LD_PRELOAD
a replacement for rcutils_get_default_allocator()
?) then it seems like that could be backported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the allocation functions that are retrieved with rcutils_get_default_allocator
that's true that modifying the default allocators can be tricky.
But by now, in micro-ROS, we use a slightly modified version of the rcutils
(stunned for embedded purposes) that has rcutils_set_default_allocator
functionality. We re planning to PR some of these changes to the rcutils
mainline.
So, in that sense, in our opinion its ok to retrieve a global-wise allocator with rcutils_get_default_allocator
and ABI/API is not modified so we can backport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. Mind opening an issue to change these APIs to accept a non-default allocator in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm interested in being able to pass a non-default allocator. I think we can use this existing issue to track progress: #306
Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
5447cbd
to
4a09fa6
Compare
c78c806
to
f51e1b7
Compare
@sloretz I also have added in last commit with |
e70849e
to
897fc3f
Compare
Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
897fc3f
to
80db3fb
Compare
Friendly ping @sloretz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with green CI
Are these If they are not, as soon as you merge I'm going to prepare a backport to Thanks a lot for your reviews and time @sloretz. |
CI LGTM! Linux CI failure appears to be ros2/ros2cli#630
No need if it's just a cherry-pick then Mergify.io bot can handle that. |
@Mergifyio backport galactic foxy |
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> (cherry picked from commit 44105c6)
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> (cherry picked from commit 44105c6)
Command
|
Thanks for the contribution @pablogs9 ! |
@sloretz @pablogs9 This PR added a regression on all CI jobs; one example is https://ci.ros2.org/view/nightly/job/nightly_linux-aarch64_debug/1594/testReport/junit/(root)/projectroot/cpplint_rosidl_generated_c/ . The problem I think is that we re-use the |
Ah shoot. It looks like I put the repos file in the
|
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
* Initial Initial Signed-off-by: Your Name <you@example.com> * Move include Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Update package.xml Signed-off-by: Pablo Garrido <pablogs9@gmail.com> * Add rosidl_runtime_c rcutils allocators Signed-off-by: Pablo Garrido <pablogs9@gmail.com> Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
This PR updates the usage of dynamic memory in
rosidl_generator_c
to rely onrcutils
allocators.As discussed in #306 that had a not priority because
rosidl_generator_c
was mainly used inrclpy
and somercl
tests.But now micro-ROS relies completely on the C99 infrastructure of ROS 2 and, for us, in some scenarios is not feasible to use the common dynamic memory API (
malloc
,free
,...).