Skip to content

rust: enhance PointerWrapper. #386

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

Merged
merged 1 commit into from
Jun 23, 2021
Merged

Conversation

wedsonaf
Copy link

This formalises how wrapped values can be accessed after they've been
converted to 'pointers'.

In upcoming PRs, we will have Box<T> instances access &T, but
Ref<T> will provide access to &Ref<T> so that we can increment the
refcount when needed.

Signed-off-by: Wedson Almeida Filho [email protected]

@ksquirrel

This comment has been minimized.

Copy link
Collaborator

@TheSven73 TheSven73 left a comment

Choose a reason for hiding this comment

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

I like this a lot !

(edit: I see there is a full explanation already in #387, so all good)

@ksquirrel

This comment has been minimized.

@wedsonaf
Copy link
Author

wedsonaf commented Jun 23, 2021

v1 -> v2

  • Rebase
  • Use cast()
  • Rename UnsafeBorrow to UnsafeReference

// so it is safe to dereference the raw pointer.
// The safety requirements also ensure that the object remains alive for the lifetime of
// the returned value.
unsafe { UnsafeReference::new(&*(ptr as *const T)) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: left out a cast() here?

Copy link
Author

Choose a reason for hiding this comment

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

Oops. I had missed this one because it goes away when I update Ref's implementation.

Anyway, fixed it now. PTAL.

This formalises how wrapped values can be accessed after they've been
converted to 'pointers'.

In upcoming PRs, we will have `Box<T>` instances access `&T`, but
`Ref<T>` will provide access to `&Ref<T>` so that we can increment the
refcount when needed.

Signed-off-by: Wedson Almeida Filho <[email protected]>
@ksquirrel
Copy link
Member

Review of 20bf0d4fb254:

  • ✔️ Commit 20bf0d4: Looks fine!

Copy link
Collaborator

@TheSven73 TheSven73 left a comment

Choose a reason for hiding this comment

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

LGTM !

///
/// `ptr` must have been returned by a previous call to [`PointerWrapper::into_pointer`].
/// Additionally, [`PointerWrapper::from_pointer`] can only be called after *all* values
/// returned by [`PointerWrapper::borrow`] have been dropped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there a couple of safety constraints we've omitted here?
Following these # Safety instructions, are we allowed to:

  • call from_pointer() multiple times on the same pointer?
  • call borrow() after the call to from_pointer() ?

If so, does this merit a follow-up PR?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this should be clarified. I'll prepare a follow-up PR.

@wedsonaf wedsonaf merged commit 3c47616 into Rust-for-Linux:rust Jun 23, 2021
@wedsonaf wedsonaf deleted the borrowed branch June 23, 2021 13:14
@adamrk adamrk mentioned this pull request Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants