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/liblog/lib.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/liblog/lib.rs')
| -rw-r--r-- | src/liblog/lib.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index c2c7f20ce9c..68f8931313b 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -167,6 +167,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![deny(missing_docs)] +#![feature(alloc)] #![feature(staged_api)] #![feature(box_syntax)] #![feature(int_uint)] @@ -175,6 +176,7 @@ #![feature(std_misc)] #![feature(env)] +use std::boxed; use std::cell::RefCell; use std::fmt; use std::old_io::LineBufferedWriter; @@ -205,11 +207,11 @@ const DEFAULT_LOG_LEVEL: u32 = 1; /// logging statement should be run. static mut LOG_LEVEL: u32 = MAX_LOG_LEVEL; -static mut DIRECTIVES: *const Vec<directive::LogDirective> = - 0 as *const Vec<directive::LogDirective>; +static mut DIRECTIVES: *mut Vec<directive::LogDirective> = + 0 as *mut Vec<directive::LogDirective>; /// Optional filter. -static mut FILTER: *const String = 0 as *const _; +static mut FILTER: *mut String = 0 as *mut _; /// Debug log level pub const DEBUG: u32 = 4; @@ -419,23 +421,23 @@ fn init() { assert!(FILTER.is_null()); match filter { - Some(f) => FILTER = mem::transmute(box f), + Some(f) => FILTER = boxed::into_raw(box f), None => {} } assert!(DIRECTIVES.is_null()); - DIRECTIVES = mem::transmute(box directives); + DIRECTIVES = boxed::into_raw(box directives); // Schedule the cleanup for the globals for when the runtime exits. rt::at_exit(move || { assert!(!DIRECTIVES.is_null()); let _directives: Box<Vec<directive::LogDirective>> = - mem::transmute(DIRECTIVES); - DIRECTIVES = ptr::null(); + Box::from_raw(DIRECTIVES); + DIRECTIVES = ptr::null_mut(); if !FILTER.is_null() { - let _filter: Box<String> = mem::transmute(FILTER); - FILTER = 0 as *const _; + let _filter: Box<String> = Box::from_raw(FILTER); + FILTER = 0 as *mut _; } }); } |
