Skip to content
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

Fix 394 #419

Merged
merged 3 commits into from
Dec 6, 2017
Merged

Fix 394 #419

merged 3 commits into from
Dec 6, 2017

Conversation

Karsten1987
Copy link
Contributor

Connects to #394

This is a redo of #395 split up into each individual issue, which is associated to it. This should help the review process.

This can only be merged after #418 has been merged.

@Karsten1987 Karsten1987 added the in review Waiting for review (Kanban column) label Dec 5, 2017
@Karsten1987 Karsten1987 self-assigned this Dec 5, 2017
@Karsten1987 Karsten1987 changed the base branch from master to fix-393 December 5, 2017 03:15
@dirk-thomas
Copy link
Member

If the classes ensure that the state_handle_ / transition_handle_ are never null (as described in the comments on #418) this should simplify some of the logic in this patch.

auto ret = rcl_lifecycle_state_init(
state_handle_, rhs.id(), rhs.label().c_str(), &allocator_);
if (ret != RCL_RET_OK) {
reset();
Copy link
Member

Choose a reason for hiding this comment

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

Again, state_handle_ has not been zero initialized, so no guarantee that reset can do the right thing.

Same below.

Copy link
Contributor Author

@Karsten1987 Karsten1987 Dec 6, 2017

Choose a reason for hiding this comment

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

I don't see how. If the init returns false, it means that the label pointer is null and thus can be freed correctly.
The same with transitions. We call init on it with two nullptr.

Alternatively, we could manually initialize it to null after calling allocate.

copy and assignment operator for transition

remove unused const_casts

address comments

check for null in copy constructor

up

use init and fini functions from rcl

remove unused include
@Karsten1987
Copy link
Contributor Author

CI:
Build Status
Build Status
Build Status

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

ok to merge, with a follow up tomorrow to change the fini functions

state_handle_ = static_cast<rcl_lifecycle_state_t *>(
allocator_.allocate(sizeof(rcl_lifecycle_state_t), allocator_.state));
if (!state_handle_) {
throw std::runtime_error("failed to allocate memory for rcl_lifecycle_state_t");
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: probably should be std::bad_alloc (http://en.cppreference.com/w/cpp/memory/new/bad_alloc)

(I don't think this needs to be in for this release, just a fyi)


// we own the handle, so we have to deep-copy the rhs object
transition_handle_ = static_cast<rcl_lifecycle_transition_t *>(
allocator_.allocate(sizeof(rcl_lifecycle_transition_t), allocator_.state));
Copy link
Member

Choose a reason for hiding this comment

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

So I noticed that the allocation here's matching deallocation is in the fini function for this struct (same for above rcl struct in State class). While this isn't wrong, it's definitely different from how the rest of the fini functions work. Rather than iterate over the internet, I'm giving @Karsten1987 the ok to merge (since it's not broken, just weird) and tomorrow I'll help him clean up the implementation.

@Karsten1987 Karsten1987 merged commit 6d13bcb into master Dec 6, 2017
@Karsten1987 Karsten1987 removed the in review Waiting for review (Kanban column) label Dec 6, 2017
@Karsten1987 Karsten1987 deleted the fix-394 branch December 6, 2017 06:52
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
…os2#456)

If the maximum number is exceeded fail with an informative error message.

Fixes ros2#419.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
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.

3 participants