-
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
Conversation
rmw_zenoh_cpp::liveliness::TopicInfo{ | ||
rmw_publisher->topic_name, | ||
publisher_data->type_support->get_name(), | ||
type_hash_c_str, |
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:
- The ownership of
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. - We convert the type hash to a string in this function, and then convert it back to a
rosidl_type_hash_t
inGraphCache::get_entities_info_by_topic
. That just seems like unnecessary work.
To fix this, I suggest two changes:
- Pass
publisher_data->type_hash
in here, and just have theTopicInfo
hold onto that. - Make sure to free
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 the TopicInfo
constructor. That should create a copy right? I can also explcitly pass a std::string(type_hash_c_str)
.
We convert the type hash to a string in this function, and then convert it back to a rosidl_type_hash_t in GraphCache::get_entities_info_by_topic. That just seems like unnecessary work.
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.
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.
Oh yes, good point. OK, never mind my comment on this.
I was relying on implicit conversion to a string when passing
type_hash_c_str
to theTopicInfo
constructor. That should create a copy right?
Hm, I guess you are right. Converting a char *
to a std::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 the char *
into the TopicInfo
, and have TopicInfo be responsible for both copying and releasing the string. But I leave it to you.
54c33bc
to
8d5c271
Compare
Signed-off-by: Yadunund <[email protected]>
dd3e34f
to
37e272b
Compare
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've left one comment, but it is non-blocking. I'll leave it to you whether to leave the code as-is or make a slight adjustment. Either way this is looking good to me.
rmw_zenoh_cpp::liveliness::TopicInfo{ | ||
rmw_publisher->topic_name, | ||
publisher_data->type_support->get_name(), | ||
type_hash_c_str, |
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'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.
Oh yes, good point. OK, never mind my comment on this.
I was relying on implicit conversion to a string when passing
type_hash_c_str
to theTopicInfo
constructor. That should create a copy right?
Hm, I guess you are right. Converting a char *
to a std::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 the char *
into the TopicInfo
, and have TopicInfo be responsible for both copying and releasing the string. But I leave it to you.
I think we can keep things as they are right now. The constructor args make it apparent that a copy of a string should be passed. I could convert some of them to |
Builds off #171 to include the type hash in the liveliness token and populate the same when filling out endpoint info. As a result the type hash is now available when introspecting topics. Previously the type hash would show
INVALID
.To test:
# terminal 1 ros2 run demo_nodes_cpp talker
# terminal 2 ros2 topic info -v /chatter
The type hash should be filled in the result