diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-05-17 11:57:07 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-05-24 09:00:39 -0700 |
| commit | cae91d7c8c21aa860bda29c62207a6726837952b (patch) | |
| tree | 3c1a8d50e4fded7eaa1830188b013d3d5f998100 /src/liblog | |
| parent | 30422de32d905dca54e503ec7990c4d7d11334da (diff) | |
| download | rust-cae91d7c8c21aa860bda29c62207a6726837952b.tar.gz rust-cae91d7c8c21aa860bda29c62207a6726837952b.zip | |
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:
Stabilized:
* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`
Deprecated:
* `StaticCondvar` - this, and all other static synchronization primitives
below, are usable today through the lazy-static crate on
stable Rust today. Additionally, we'd like the non-static
versions to be directly usable in a static context one day,
so they're unlikely to be the final forms of the APIs in any
case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`
Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
Diffstat (limited to 'src/liblog')
| -rw-r--r-- | src/liblog/lib.rs | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 011f5a744dc..a71f6efe54e 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -170,10 +170,7 @@ #![deny(missing_docs)] #![cfg_attr(not(stage0), deny(warnings))] -#![feature(box_syntax)] -#![feature(const_fn)] #![feature(staged_api)] -#![feature(static_mutex)] use std::cell::RefCell; use std::fmt; @@ -181,9 +178,8 @@ use std::io::{self, Stderr}; use std::io::prelude::*; use std::mem; use std::env; -use std::ptr; use std::slice; -use std::sync::{Once, StaticMutex}; +use std::sync::{Once, Mutex, ONCE_INIT}; use directive::LOG_LEVEL_NAMES; @@ -199,18 +195,13 @@ pub const MAX_LOG_LEVEL: u32 = 255; /// The default logging level of a crate if no other is specified. const DEFAULT_LOG_LEVEL: u32 = 1; -static LOCK: StaticMutex = StaticMutex::new(); +static mut LOCK: *mut Mutex<(Vec<directive::LogDirective>, Option<String>)> = 0 as *mut _; /// An unsafe constant that is the maximum logging level of any module /// specified. This is the first line of defense to determining whether a /// logging statement should be run. static mut LOG_LEVEL: u32 = MAX_LOG_LEVEL; -static mut DIRECTIVES: *mut Vec<directive::LogDirective> = ptr::null_mut(); - -/// Optional filter. -static mut FILTER: *mut String = ptr::null_mut(); - /// Debug log level pub const DEBUG: u32 = 4; /// Info log level @@ -287,14 +278,10 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) { // Test the literal string from args against the current filter, if there // is one. unsafe { - let _g = LOCK.lock(); - match FILTER as usize { - 0 => {} - n => { - let filter = mem::transmute::<_, &String>(n); - if !args.to_string().contains(filter) { - return; - } + let filter = (*LOCK).lock().unwrap(); + if let Some(ref filter) = filter.1 { + if !args.to_string().contains(filter) { + return; } } } @@ -302,10 +289,10 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) { // Completely remove the local logger from TLS in case anyone attempts to // frob the slot while we're doing the logging. This will destroy any logger // set during logging. - let mut logger: Box<Logger + Send> = LOCAL_LOGGER.with(|s| s.borrow_mut().take()) - .unwrap_or_else(|| { - box DefaultLogger { handle: io::stderr() } - }); + let logger = LOCAL_LOGGER.with(|s| s.borrow_mut().take()); + let mut logger = logger.unwrap_or_else(|| { + Box::new(DefaultLogger { handle: io::stderr() }) + }); logger.log(&LogRecord { level: LogLevel(level), args: args, @@ -363,7 +350,7 @@ pub struct LogLocation { /// module's log statement should be emitted or not. #[doc(hidden)] pub fn mod_enabled(level: u32, module: &str) -> bool { - static INIT: Once = Once::new(); + static INIT: Once = ONCE_INIT; INIT.call_once(init); // It's possible for many threads are in this function, only one of them @@ -378,10 +365,9 @@ pub fn mod_enabled(level: u32, module: &str) -> bool { // This assertion should never get tripped unless we're in an at_exit // handler after logging has been torn down and a logging attempt was made. - let _g = LOCK.lock(); unsafe { - assert!(DIRECTIVES as usize != 0); - enabled(level, module, (*DIRECTIVES).iter()) + let directives = (*LOCK).lock().unwrap(); + enabled(level, module, directives.0.iter()) } } @@ -422,14 +408,8 @@ fn init() { unsafe { LOG_LEVEL = max_level; - assert!(FILTER.is_null()); - match filter { - Some(f) => FILTER = Box::into_raw(box f), - None => {} - } - - assert!(DIRECTIVES.is_null()); - DIRECTIVES = Box::into_raw(box directives); + assert!(LOCK.is_null()); + LOCK = Box::into_raw(Box::new(Mutex::new((directives, filter)))); } } |
