Windows TLS: ManuallyDrop instead of mem::forget by RalfJung · Pull Request #798...
source link: https://github.com/rust-lang/rust/pull/79893
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Collaborator
rust-highfive commented 10 days ago
(rust-highfive has picked a reviewer for you, use r? to override)
@@ -111,16 +111,13 @@ struct Node {
}
unsafe fn register_dtor(key: Key, dtor: Dtor) {
let mut node = Box::new(Node { key, dtor, next: ptr::null_mut() });
let mut node = ManuallyDrop::new(Box::new(Node { key, dtor, next: ptr::null_mut() }));
oli-obk 10 days ago
Contributor
Since we never drop this anyway, couldn't we also just Box::into_raw
here and then compare_exchange
ing the raw pointer directly? I guess that would mean node.next = head
needs to be (*node).next = head
and is now unsafe, so maybe the ManuallyDrop is better, but I am somewhat unhappy with the &mut **node
(the previous &mut *node
was not better imo). I know we can rely on the deref ops on boxes, but it still seems wrong to me to not be using Box::into_raw
when this is technically what we want.
RalfJung 10 days ago
Author
Member
I guess that would mean node.next = head needs to be (*node).next = head and is now unsafe
I went with into_raw
first and decided to use ManuallyDrop
when I realized this.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK