-
Notifications
You must be signed in to change notification settings - Fork 174
Add support for loaned messages #212
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
Conversation
bfeb3b6
to
ae39b4b
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.
One small comment tweak. However, I'm curious about how cloning might affect this... Is it possible to get a double-free error if you clone a loaned message, then drop both? Or am I just being paranoid?
if !self.msg_ptr.is_null() { | ||
unsafe { | ||
// SAFETY: These two pointers are valid, and the msg_ptr is not used afterwards. | ||
rcl_return_loaned_message_from_publisher( |
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.
What happens if a user does something like .clone()
a loaned message? Would that affect this?
{ | ||
fn drop(&mut self) { | ||
unsafe { | ||
rcl_return_loaned_message_from_subscription( |
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.
What happens if a user .clone()
s a loaned message? Will that affect this function?
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.
Yep, that would be bad, that's why loaned messages don't implement Clone
.
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.
My biggest concern was addressed in a comment, and the documentation change isn't worth holding up the PR.
@esteve Do you also want to have a look at this? |
Co-authored-by: jhdcs <48914066+jhdcs@users.noreply.github.com>
@esteve Please review (or let me know if Jacob's review is sufficient for you). |
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.
Great work!
Thanks! Don't be surprised if this fails on master; see #239 (comment) |
I tested it with CycloneDDS and it worked.
The only interesting things are
publish()
a method on theLoanedMessage
that takes no argument, since it can only be used with the publisher that was used to create it, and that publisher is stored inside the message. So this design statically guarantees that a loaned message cannot be published to the wrong publisher.Closes #136