about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-03-12 23:34:31 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-03-15 22:56:46 -0700
commit0015cab1fd7b4b47030c808a825bb5594cc1d4ac (patch)
treecf054fdf43843170e6479675e62a29b6213e2ce2 /src/libstd
parent17ad504fef35191fe53874bd2fe77ffd14d8e1b9 (diff)
downloadrust-0015cab1fd7b4b47030c808a825bb5594cc1d4ac.tar.gz
rust-0015cab1fd7b4b47030c808a825bb5594cc1d4ac.zip
Test fixes and rebase conflicts
This commit switches over the backtrace infrastructure from piggy-backing off
the RUST_LOG environment variable to using the RUST_BACKTRACE environment
variable (logging is now disabled in libstd).
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs11
-rw-r--r--src/libstd/rt/backtrace.rs22
-rw-r--r--src/libstd/rt/unwind.rs2
3 files changed, 25 insertions, 10 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 0c46a501299..040d5c0e175 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -1155,10 +1155,7 @@ impl MemoryMap {
                 MapAddr(addr_) => { lpAddress = addr_ as LPVOID; },
                 MapFd(fd_) => { fd = fd_; },
                 MapOffset(offset_) => { offset = offset_; },
-                MapNonStandardFlags(f) => {
-                    info!("MemoryMap::new: MapNonStandardFlags used on \
-                           Windows: {}", f)
-                }
+                MapNonStandardFlags(..) => {}
             }
         }
 
@@ -1256,15 +1253,15 @@ impl Drop for MemoryMap {
                 MapVirtual => {
                     if libc::VirtualFree(self.data as *mut c_void, 0,
                                          libc::MEM_RELEASE) == 0 {
-                        error!("VirtualFree failed: {}", errno());
+                        println!("VirtualFree failed: {}", errno());
                     }
                 },
                 MapFile(mapping) => {
                     if libc::UnmapViewOfFile(self.data as LPCVOID) == FALSE {
-                        error!("UnmapViewOfFile failed: {}", errno());
+                        println!("UnmapViewOfFile failed: {}", errno());
                     }
                     if libc::CloseHandle(mapping as HANDLE) == FALSE {
-                        error!("CloseHandle failed: {}", errno());
+                        println!("CloseHandle failed: {}", errno());
                     }
                 }
             }
diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs
index 831f6c73e35..bc75a98e085 100644
--- a/src/libstd/rt/backtrace.rs
+++ b/src/libstd/rt/backtrace.rs
@@ -16,15 +16,31 @@ use from_str::from_str;
 use io::{IoResult, Writer};
 use iter::Iterator;
 use option::{Some, None};
+use os;
 use result::{Ok, Err};
 use str::StrSlice;
+use sync::atomics;
 
 pub use self::imp::write;
 
-// This function is defined in this module so that the way to enable logging of
-// backtraces has the word 'backtrace' in it: std::rt::backtrace.
+// For now logging is turned off by default, and this function checks to see
+// whether the magical environment variable is present to see if it's turned on.
 pub fn log_enabled() -> bool {
-    log_enabled!(::logging::DEBUG)
+    static mut ENABLED: atomics::AtomicInt = atomics::INIT_ATOMIC_INT;
+    unsafe {
+        match ENABLED.load(atomics::SeqCst) {
+            1 => return false,
+            2 => return true,
+            _ => {}
+        }
+    }
+
+    let val = match os::getenv("RUST_BACKTRACE") {
+        Some(..) => 2,
+        None => 1,
+    };
+    unsafe { ENABLED.store(val, atomics::SeqCst); }
+    val == 2
 }
 
 #[cfg(target_word_size = "64")] static HEX_WIDTH: uint = 18;
diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs
index 3a06075ce48..7f54b8b3320 100644
--- a/src/libstd/rt/unwind.rs
+++ b/src/libstd/rt/unwind.rs
@@ -398,6 +398,8 @@ fn begin_unwind_inner(msg: ~Any, file: &'static str, line: uint) -> ! {
                 if backtrace::log_enabled() {
                     let mut err = ::rt::util::Stderr;
                     let _err = backtrace::write(&mut err);
+                } else {
+                    rterrln!("run with `RUST_BACKTRACE=1` to see a backtrace");
                 }
                 unsafe { intrinsics::abort() }
             }