(index<- ) ./libcore/failure.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Failure support for libcore
12
13 #![allow(dead_code)]
14
15 #[cfg(not(test))]
16 use str::raw::c_str_to_static_slice;
17
18 // FIXME: Once std::fmt is in libcore, all of these functions should delegate
19 // to a common failure function with this signature:
20 //
21 // extern {
22 // fn rust_unwind(f: &fmt::Arguments, file: &str, line: uint) -> !;
23 // }
24 //
25 // Each of these functions can create a temporary fmt::Arguments
26 // structure to pass to this function.
27
28 #[cold] #[inline(never)] // this is the slow path, always
29 #[lang="fail_"]
30 #[cfg(not(test))]
31 fn fail_(expr: *u8, file: *u8, line: uint) -> ! {
32 unsafe {
33 let expr = c_str_to_static_slice(expr as *i8);
34 let file = c_str_to_static_slice(file as *i8);
35 begin_unwind(expr, file, line)
36 }
37 }
38
39 #[cold]
40 #[lang="fail_bounds_check"]
41 #[cfg(not(test))]
42 fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! {
43 #[allow(ctypes)]
44 extern { fn rust_fail_bounds_check(file: *u8, line: uint,
45 index: uint, len: uint,) -> !; }
46 unsafe { rust_fail_bounds_check(file, line, index, len) }
47 }
48
49 #[cold]
50 pub fn begin_unwind(msg: &str, file: &'static str, line: uint) -> ! {
51 #[allow(ctypes)]
52 extern { fn rust_begin_unwind(msg: &str, file: &'static str,
53 line: uint) -> !; }
54 unsafe { rust_begin_unwind(msg, file, line) }
55 }