diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-01 10:47:18 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-07 08:16:14 -0700 |
| commit | e4271cae54c7f4a868c60a1822b91e702e511947 (patch) | |
| tree | 96f723ffcdfc21f98b7ff29406f14f77d6ca6689 /src/libstd/rt | |
| parent | 4686cf201804c999fbc24fa3a3245e9c4dc4afe1 (diff) | |
| download | rust-e4271cae54c7f4a868c60a1822b91e702e511947.tar.gz rust-e4271cae54c7f4a868c60a1822b91e702e511947.zip | |
core: Add a limited implementation of failure
This adds an small of failure to libcore, hamstrung by the fact that std::fmt hasn't been migrated yet. A few asserts were re-worked to not use std::fmt features, but these asserts can go back to their original form once std::fmt has migrated. The current failure implementation is to just have some symbols exposed by std::rt::unwind that are linked against by libcore. This is an explicit circular dependency, unfortunately. This will be officially supported in the future through compiler support with much nicer failure messages. Additionally, there are two depended-upon symbols today, but in the future there will only be one (once std::fmt has migrated).
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 42 |
2 files changed, 12 insertions, 32 deletions
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index e79e3056838..5b9c314d42b 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -70,7 +70,7 @@ use self::task::{Task, BlockedTask}; pub use self::util::default_sched_threads; // Export unwinding facilities used by the failure macros -pub use self::unwind::{begin_unwind, begin_unwind_raw, begin_unwind_fmt}; +pub use self::unwind::{begin_unwind, begin_unwind_fmt}; pub use self::util::{Stdio, Stdout, Stderr}; diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 3ba97f381ab..5f3731eb819 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -58,7 +58,6 @@ // Currently Rust uses unwind runtime provided by libgcc. use any::{Any, AnyRefExt}; -use c_str::CString; use cast; use fmt; use kinds::Send; @@ -298,42 +297,23 @@ pub mod eabi { } #[cold] -#[lang="fail_"] +#[no_mangle] #[cfg(not(test))] -pub fn fail_(expr: *u8, file: *u8, line: uint) -> ! { - begin_unwind_raw(expr, file, line); -} - -#[cold] -#[lang="fail_bounds_check"] -#[cfg(not(test))] -pub fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! { - use c_str::ToCStr; +pub extern fn rust_fail_bounds_check(file: *u8, line: uint, + index: uint, len: uint) -> ! { + use str::raw::c_str_to_static_slice; let msg = format!("index out of bounds: the len is {} but the index is {}", len as uint, index as uint); - msg.with_c_str(|buf| fail_(buf as *u8, file, line)) + begin_unwind(msg, unsafe { c_str_to_static_slice(file as *i8) }, line) } -/// This is the entry point of unwinding for things like lang items and such. -/// The arguments are normally generated by the compiler, and need to -/// have static lifetimes. -#[inline(never)] #[cold] // this is the slow path, please never inline this -pub fn begin_unwind_raw(msg: *u8, file: *u8, line: uint) -> ! { - use libc::c_char; - #[inline] - fn static_char_ptr(p: *u8) -> &'static str { - let s = unsafe { CString::new(p as *c_char, false) }; - match s.as_str() { - Some(s) => unsafe { cast::transmute::<&str, &'static str>(s) }, - None => rtabort!("message wasn't utf8?") - } - } - - let msg = static_char_ptr(msg); - let file = static_char_ptr(file); - - begin_unwind(msg, file, line as uint) +// Entry point of failure from the libcore crate +#[no_mangle] +#[cfg(not(test))] +pub extern fn rust_begin_unwind(msg: &str, file: &'static str, line: uint) -> ! { + use str::StrAllocating; + begin_unwind(msg.to_owned(), file, line) } /// The entry point for unwinding with a formatted message. |
