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/sys/windows | |
| 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/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread_local.rs | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index f3a27877e5c..7fe8dce1a3e 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -10,6 +10,8 @@ use prelude::v1::*; +use boxed; +use boxed::Box; use cmp; use io; use mem; @@ -45,7 +47,8 @@ pub mod guard { } pub unsafe fn create(stack: uint, p: Thunk) -> io::Result<rust_thread> { - let arg: *mut libc::c_void = mem::transmute(box p); + let raw_p = boxed::into_raw(box p); + let arg = raw_p as *mut libc::c_void; // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least // PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's @@ -61,7 +64,7 @@ pub unsafe fn create(stack: uint, p: Thunk) -> io::Result<rust_thread> { if ret as uint == 0 { // be sure to not leak the closure - let _p: Box<Thunk> = mem::transmute(arg); + let _p: Box<Thunk> = Box::from_raw(raw_p); Err(io::Error::last_os_error()) } else { Ok(ret) diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 0c24ab1fa09..cf942b5d025 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -133,13 +133,13 @@ unsafe fn init_dtors() { if !DTORS.is_null() { return } let dtors = box Vec::<(Key, Dtor)>::new(); - DTORS = mem::transmute(dtors); + DTORS = boxed::into_raw(dtors); rt::at_exit(move|| { DTOR_LOCK.lock(); let dtors = DTORS; DTORS = ptr::null_mut(); - mem::transmute::<_, Box<Vec<(Key, Dtor)>>>(dtors); + Boxed::from_raw(dtors); assert!(DTORS.is_null()); // can't re-init after destructing DTOR_LOCK.unlock(); }); |
