-
Notifications
You must be signed in to change notification settings - Fork 42
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
Include type hash in liveliness token and fill endpoint info #202
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It feels to me like there are two problems with this implementation:
type_hash_c_str
in this function is very unclear. In particular, this function (rmw_create_publisher
) allocates it (via callingrosidl_stringify_type_hash
), but then it hands off ownership toTopicInfo
to eventually free. While that works, it is really easy for the code to change and for a memory leak to happen later.rosidl_type_hash_t
inGraphCache::get_entities_info_by_topic
. That just seems like unnecessary work.To fix this, I suggest two changes:
publisher_data->type_hash
in here, and just have theTopicInfo
hold onto that.type_hash_c_str
in this function (probably via arclcpp::make_scope_exit
). This is actually an existing memory leak, but we may as well fix it while we are looking at things here.The same goes for all uses of the type_hash below.
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 was relying on implicit conversion to a string when passing
type_hash_c_str
to theTopicInfo
constructor. That should create a copy right? I can also explcitly pass astd::string(type_hash_c_str)
.it's only unnecessary when the topics are created in the current session. However we still need to convert the string to a
rosidl_type_hash_t
for endpoints in other nodes in the graph since this information is gotten from liveliness tokens.Correct me if i'm wrong but after I address #171 (comment), it should be clear that the pointer is freed and that we pass a newly instantiated string to
TopicInfo
?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.
Oh yes, good point. OK, never mind my comment on this.
Hm, I guess you are right. Converting a
char *
to astd::string
does indeed seem to do a copy of the string. That's good to know. Personally, I prefer this to be explicit, and so I would pass thechar *
into theTopicInfo
, and have TopicInfo be responsible for both copying and releasing the string. But I leave it to you.