about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2014-12-27 23:57:43 +0200
committerEduard Burtescu <edy.burt@gmail.com>2014-12-27 23:57:43 +0200
commit647e54d6d154e1a267e84c8ae9f1315e3f9b93fc (patch)
treea25d8f7f938435e2dfcb2056353cbd4c3c3d8a55 /src/libstd/rt
parentfc3f22bf2510dacb1fc4f5422b025a51bfda410e (diff)
downloadrust-647e54d6d154e1a267e84c8ae9f1315e3f9b93fc.tar.gz
rust-647e54d6d154e1a267e84c8ae9f1315e3f9b93fc.zip
Fallout of changing format_args!(f, args) to f(format_args!(args)).
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/macros.rs18
-rw-r--r--src/libstd/rt/unwind.rs49
-rw-r--r--src/libstd/rt/util.rs15
3 files changed, 80 insertions, 2 deletions
diff --git a/src/libstd/rt/macros.rs b/src/libstd/rt/macros.rs
index bee8b5b82f4..095a27203f9 100644
--- a/src/libstd/rt/macros.rs
+++ b/src/libstd/rt/macros.rs
@@ -15,6 +15,16 @@
 
 #![macro_escape]
 
+// NOTE(stage0): Remove cfg after a snapshot
+#[cfg(not(stage0))]
+macro_rules! rterrln {
+    ($fmt:expr $($arg:tt)*) => ( {
+        ::rt::util::dumb_print(format_args!(concat!($fmt, "\n") $($arg)*))
+    } )
+}
+
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
 macro_rules! rterrln {
     ($fmt:expr $($arg:tt)*) => ( {
         format_args!(::rt::util::dumb_print, concat!($fmt, "\n") $($arg)*)
@@ -40,6 +50,14 @@ macro_rules! rtassert {
     } )
 }
 
+// NOTE(stage0): Remove cfg after a snapshot
+#[cfg(not(stage0))]
+macro_rules! rtabort {
+    ($($arg:tt)*) => (::rt::util::abort(format_args!($($arg)*)))
+}
+
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
 macro_rules! rtabort {
     ($($arg:tt)*) => (format_args!(::rt::util::abort, $($arg)*))
 }
diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs
index eb15a7ba378..261a8335173 100644
--- a/src/libstd/rt/unwind.rs
+++ b/src/libstd/rt/unwind.rs
@@ -477,14 +477,61 @@ pub mod eabi {
     }
 }
 
-// Entry point of panic from the libcore crate
+// NOTE(stage0): Remove cfg after a snapshot
+#[cfg(not(stage0))]
 #[cfg(not(test))]
+/// Entry point of panic from the libcore crate.
+#[lang = "panic_fmt"]
+pub extern fn rust_begin_unwind(msg: fmt::Arguments,
+                                file: &'static str, line: uint) -> ! {
+    begin_unwind_fmt(msg, &(file, line))
+}
+
+// NOTE(stage0): Remove function after a snapshot
+#[cfg(stage0)]
+#[cfg(not(test))]
+/// Entry point of panic from the libcore crate.
 #[lang = "panic_fmt"]
 pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
                                 file: &'static str, line: uint) -> ! {
     begin_unwind_fmt(msg, &(file, line))
 }
 
+// NOTE(stage0): Remove cfg after a snapshot
+#[cfg(not(stage0))]
+/// The entry point for unwinding with a formatted message.
+///
+/// This is designed to reduce the amount of code required at the call
+/// site as much as possible (so that `panic!()` has as low an impact
+/// on (e.g.) the inlining of other functions as possible), by moving
+/// the actual formatting into this shared place.
+#[inline(never)] #[cold]
+pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
+    use fmt::FormatWriter;
+
+    // We do two allocations here, unfortunately. But (a) they're
+    // required with the current scheme, and (b) we don't handle
+    // panic + OOM properly anyway (see comment in begin_unwind
+    // below).
+
+    struct VecWriter<'a> { v: &'a mut Vec<u8> }
+
+    impl<'a> fmt::FormatWriter for VecWriter<'a> {
+        fn write(&mut self, buf: &[u8]) -> fmt::Result {
+            self.v.push_all(buf);
+            Ok(())
+        }
+    }
+
+    let mut v = Vec::new();
+    let _ = write!(&mut VecWriter { v: &mut v }, "{}", msg);
+
+    let msg = box String::from_utf8_lossy(v.as_slice()).into_owned();
+    begin_unwind_inner(msg, file_line)
+}
+
+// NOTE(stage0): Remove function after a snapshot
+#[cfg(stage0)]
 /// The entry point for unwinding with a formatted message.
 ///
 /// This is designed to reduce the amount of code required at the call
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index d8cd8455deb..26dadfd9fb1 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -112,12 +112,25 @@ impl fmt::FormatWriter for Stdio {
     }
 }
 
+// NOTE(stage0): Remove cfg after a snapshot
+#[cfg(not(stage0))]
+pub fn dumb_print(args: fmt::Arguments) {
+    let _ = Stderr.write_fmt(args);
+}
+
+// NOTE(stage0): Remove function after a snapshot
+#[cfg(stage0)]
 pub fn dumb_print(args: &fmt::Arguments) {
     let mut w = Stderr;
     let _ = write!(&mut w, "{}", args);
 }
 
-pub fn abort(args: &fmt::Arguments) -> ! {
+// NOTE(stage0): Remove wrappers after a snapshot
+#[cfg(not(stage0))] pub fn abort(args: fmt::Arguments) -> ! { abort_(&args) }
+#[cfg(stage0)] pub fn abort(args: &fmt::Arguments) -> ! { abort_(args) }
+
+// NOTE(stage0): Change to `pub fn abort(args: fmt::Arguments) -> !` after a snapshot
+fn abort_(args: &fmt::Arguments) -> ! {
     use fmt::FormatWriter;
 
     struct BufWriter<'a> {