diff options
| author | Stepan Koltsov <stepan.koltsov@gmail.com> | 2015-02-23 02:58:22 +0300 |
|---|---|---|
| committer | Stepan Koltsov <stepan.koltsov@gmail.com> | 2015-02-23 02:59:17 +0300 |
| commit | 26d9f0ab1aeb3d7b440911104cf17741f83aa0f5 (patch) | |
| tree | eea0a5891102880a9ce3bb76a8d3098f263aa7a9 /src/libstd/sync/mpsc/spsc_queue.rs | |
| parent | 554022e58392b173092e707b4c553713d07ed44d (diff) | |
| download | rust-26d9f0ab1aeb3d7b440911104cf17741f83aa0f5.tar.gz rust-26d9f0ab1aeb3d7b440911104cf17741f83aa0f5.zip | |
Use boxed functions instead of transmute
... to convert between Box and raw pointers. E. g. use ``` let b: Box<Foo> = Box::from_raw(p); ``` instead of ``` let b: Box<Foo> = mem::transmute(p); ``` Patch also changes closure release code in `src/libstd/sys/unix/thread.rs` when `pthread_create` failed. Raw pointer was transmuted to box of `FnOnce()` instead of `Thunk`. This code was probably never executed, because `pthread_create` rarely fails in practice.
Diffstat (limited to 'src/libstd/sync/mpsc/spsc_queue.rs')
| -rw-r--r-- | src/libstd/sync/mpsc/spsc_queue.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index f111e13975f..7b5c614536d 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -37,8 +37,8 @@ use core::prelude::*; +use alloc::boxed; use alloc::boxed::Box; -use core::mem; use core::ptr; use core::cell::UnsafeCell; @@ -81,7 +81,7 @@ unsafe impl<T: Send> Sync for Queue<T> { } impl<T: Send> Node<T> { fn new() -> *mut Node<T> { unsafe { - mem::transmute(box Node { + boxed::into_raw(box Node { value: None, next: AtomicPtr::new(ptr::null_mut::<Node<T>>()), }) @@ -200,7 +200,7 @@ impl<T: Send> Queue<T> { .next.store(next, Ordering::Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. - let _: Box<Node<T>> = mem::transmute(tail); + let _: Box<Node<T>> = Box::from_raw(tail); } } return ret; @@ -233,7 +233,7 @@ impl<T: Send> Drop for Queue<T> { let mut cur = *self.first.get(); while !cur.is_null() { let next = (*cur).next.load(Ordering::Relaxed); - let _n: Box<Node<T>> = mem::transmute(cur); + let _n: Box<Node<T>> = Box::from_raw(cur); cur = next; } } |
