-
Notifications
You must be signed in to change notification settings - Fork 462
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
Conversation
This comment has been minimized.
This comment has been minimized.
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 like this a lot !
(edit: I see there is a full explanation already in #387, so all good)
This comment has been minimized.
This comment has been minimized.
v1 -> v2
|
rust/kernel/types.rs
Outdated
// 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)) } |
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.
Nit: left out a cast()
here?
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.
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]>
Review of
|
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.
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. |
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.
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 tofrom_pointer()
?
If so, does this merit a follow-up PR?
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.
Yes, this should be clarified. I'll prepare a follow-up PR.
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
, butRef<T>
will provide access to&Ref<T>
so that we can increment therefcount when needed.
Signed-off-by: Wedson Almeida Filho [email protected]