Skip to content

Instantly share code, notes, and snippets.

@krzysz00
Created April 13, 2015 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzysz00/d703210a6bf47d3de184 to your computer and use it in GitHub Desktop.
Save krzysz00/d703210a6bf47d3de184 to your computer and use it in GitHub Desktop.
Patch that makes panic = abort whin libcore is compiled with feature=trivial_panic
diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs
index 0b8a523..e7fd6e9 100644
--- a/src/libcore/panicking.rs
+++ b/src/libcore/panicking.rs
@@ -33,6 +33,7 @@
use fmt;
#[cold] #[inline(never)] // this is the slow path, always
+#[cfg(not(feature = "trivial_panic"))]
#[lang="panic"]
pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! {
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
@@ -45,7 +46,15 @@ pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! {
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), &(file, line))
}
+#[cold] #[inline(never)] // this is the slow path, always
+#[cfg(feature = "trivial_panic")]
+#[lang="panic"]
+pub fn panic(_expr_file_line: &(&'static str, &'static str, u32)) -> ! {
+ unsafe { ::core::intrinsics::abort(); }
+}
+
#[cold] #[inline(never)]
+#[cfg(not(feature = "trivial_panic"))]
#[lang="panic_bounds_check"]
fn panic_bounds_check(file_line: &(&'static str, u32),
index: usize, len: usize) -> ! {
@@ -54,6 +63,14 @@ fn panic_bounds_check(file_line: &(&'static str, u32),
}
#[cold] #[inline(never)]
+#[cfg(feature = "trivial_panic")]
+#[lang="panic_bounds_check"]
+fn panic_bounds_check(_file_line: &(&'static str, u32),
+ _index: usize, _len: usize) -> ! {
+ unsafe { ::core::intrinsics::abort(); }
+}
+
+#[cold] #[inline(never)]
pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
#[allow(improper_ctypes)]
extern {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment