Repository navigation
fix: Use default rcl allocator if allocator is std::allocator - #3058
Conversation
fujitatomoya
left a comment
There was a problem hiding this comment.
@jmachowinski thanks for fixing this issue. (it's been a looooong time... 😓 )
the approach looks good to me. a couple of things.
- you happened to miss the DCO.
- a few deprecated warning (which are added by this PR) detected on else where.
btw, the custom allocator path is still left broken? i think this PR explicitly leaves the retyped_allocate/retyped_deallocate bugs in place for non-std::allocator users. it means users with custom allocators will still hit the same ASAN/valgrind issues. It would be worth a comment or deprecation warning on the non-default path as well?
|
@fujitatomoya This is the 'tick' version of this patch. It is also a first draft version (which I should have written in the pr...) as I did not wont to polish it if the patch got turned down again. #3054 was discussed in the last PMC meeting and was turned down for two reasons :
The big drawback of #3054 was that users of custom allocators would silently fall back to malloc / free for everything happening in rcl. I am not planning on fixing the code path for custom allocators, as the plan is to remove it altogether after the next release. I will mark it as deprecated though. |
66eb056 to
1aa75b5
Compare
This fixes a bunch of warnings if using ASAN / valgrind on newer OS versions. It also fixed a real bug, as giving the wrong size on deallocate is undefined behavior according to the C++ standard. This version of the patch keeps the behavior for users that specified an own allocator the same and in therefore back portable. Signed-off-by: Janosch Machowinski <[email protected]>
1aa75b5 to
62ab1f6
Compare
|
Pulls: #3058 |
This commit adds the feature, that the user can now specify a method rcl_allocator_t get_rcl_allocator() on the given allocator. This method will be called if present, to get the rcl allocator. If the method is not present, the code will fall back to the old (and faulty) implementation and show a deprecation warning. Signed-off-by: Janosch Machowinski <[email protected]>
62ab1f6 to
449b653
Compare
|
Pulls: #3058 |
|
@jmachowinski any chance for this to be backported on Jazzy? BTW thanks a lot for working on this |
|
@jmachowinski we need to backport this to kilted? |
|
@Mergifyio backport kilted |
✅ Backports have been createdDetails
|
* fix: Use default rcl allocator if allocator is std::allocator This fixes a bunch of warnings if using ASAN / valgrind on newer OS versions. It also fixed a real bug, as giving the wrong size on deallocate is undefined behavior according to the C++ standard. This version of the patch keeps the behavior for users that specified an own allocator the same and in therefore back portable. Signed-off-by: Janosch Machowinski <[email protected]> * feat: Provide a way to suppress the deprecation warning This commit adds the feature, that the user can now specify a method rcl_allocator_t get_rcl_allocator() on the given allocator. This method will be called if present, to get the rcl allocator. If the method is not present, the code will fall back to the old (and faulty) implementation and show a deprecation warning. Signed-off-by: Janosch Machowinski <[email protected]> --------- Signed-off-by: Janosch Machowinski <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]> (cherry picked from commit 9f79f40)
) * fix: Use default rcl allocator if allocator is std::allocator This fixes a bunch of warnings if using ASAN / valgrind on newer OS versions. It also fixed a real bug, as giving the wrong size on deallocate is undefined behavior according to the C++ standard. This version of the patch keeps the behavior for users that specified an own allocator the same and in therefore back portable. Signed-off-by: Janosch Machowinski <[email protected]> * feat: Provide a way to suppress the deprecation warning This commit adds the feature, that the user can now specify a method rcl_allocator_t get_rcl_allocator() on the given allocator. This method will be called if present, to get the rcl allocator. If the method is not present, the code will fall back to the old (and faulty) implementation and show a deprecation warning. Signed-off-by: Janosch Machowinski <[email protected]> --------- Signed-off-by: Janosch Machowinski <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]>
rclcpp falls back to a deprecated C++-to-rcl allocator conversion when the allocator has no get_rcl_allocator() member; that conversion passes a wrong size to deallocate (see ros2/rclcpp#3058). Explain why rcl needs its own allocator, show a std::pmr::polymorphic_allocator wrapper that provides one by storing the block size in a header, and use it in the example main. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]>
…#7296) * Allocator tutorial: provide get_rcl_allocator() for the pmr allocator rclcpp falls back to a deprecated C++-to-rcl allocator conversion when the allocator has no get_rcl_allocator() member; that conversion passes a wrong size to deallocate (see ros2/rclcpp#3058). Explain why rcl needs its own allocator, show a std::pmr::polymorphic_allocator wrapper that provides one by storing the block size in a header, and use it in the example main. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]> * Allocator tutorial: show the full PmrAllocator implementation Replace the elided allocate/deallocate bodies with the complete code from demo_nodes_cpp's allocator_tutorial_pmr.cpp, including reallocate_block, zero_allocate_block and the required includes, and drop the note about the fallback conversion. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Maurice <[email protected]> * Apply batched suggestions from code review Co-authored-by: Katherine Scott <[email protected]> Signed-off-by: Maurice Alexander Purnawan <[email protected]> * Clarify allocator tutorial code and fix sentence lint Signed-off-by: Maurice <[email protected]> --------- Signed-off-by: Maurice <[email protected]> Signed-off-by: Maurice Alexander Purnawan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Katherine Scott <[email protected]> Co-authored-by: Tomoya Fujita <[email protected]>
…#7296) (#7456) * Allocator tutorial: provide get_rcl_allocator() for the pmr allocator rclcpp falls back to a deprecated C++-to-rcl allocator conversion when the allocator has no get_rcl_allocator() member; that conversion passes a wrong size to deallocate (see ros2/rclcpp#3058). Explain why rcl needs its own allocator, show a std::pmr::polymorphic_allocator wrapper that provides one by storing the block size in a header, and use it in the example main. * Allocator tutorial: show the full PmrAllocator implementation Replace the elided allocate/deallocate bodies with the complete code from demo_nodes_cpp's allocator_tutorial_pmr.cpp, including reallocate_block, zero_allocate_block and the required includes, and drop the note about the fallback conversion. * Apply batched suggestions from code review * Clarify allocator tutorial code and fix sentence lint --------- (cherry picked from commit 2108c88) Signed-off-by: Maurice <[email protected]> Signed-off-by: Maurice Alexander Purnawan <[email protected]> Co-authored-by: Maurice Alexander Purnawan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Katherine Scott <[email protected]> Co-authored-by: Tomoya Fujita <[email protected]>
`rclcpp` is removing the deprecated conversion of C++ allocators to rcl allocators, since it is not valid, so allocators other than `std::allocator<void>` need to define `rcl_allocator_t get_rcl_allocator()`, as recommended since ros2/rclcpp#3058 (Lyrical). This allocator uses `malloc()` and `free()`, so its rcl allocator can count calls and forward them. Signed-off-by: Christophe Bedard <[email protected]>
Converting a C++ allocator to an rcl allocator with the generic `allocator::get_rcl_allocator()` and the `retyped_*()` functions has been deprecated since #3058 (Lyrical), since it is not valid: the size on deallocate cannot be determined. Allocators other than `std::allocator<void>` now need to define `rcl_allocator_t get_rcl_allocator()`, which is enforced with a `static_assert`. Signed-off-by: Christophe Bedard <[email protected]>
This fixes a bunch of warnings if using ASAN / valgrind on newer OS versions. It also fixed a real bug, as giving the wrong size on deallocate is undefined behavior according to the C++ standard.
This version of the patch keeps the behavior for users that specified an own allocator the same and in therefore back portable.
Alternative to #3054
USED AI:
Yes, chatgpt to generate the template methods to check for the existence of a method on a class in c++17.