about summary refs log tree commit diff
path: root/src/libstd/rt/task.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-11 08:56:19 -0700
committerbors <bors@rust-lang.org>2013-10-11 08:56:19 -0700
commited37b00b06f14e41740bd296e99b4ece0ce63c84 (patch)
treea74535aa073dcd760a72a105c35004efee0075ec /src/libstd/rt/task.rs
parent93a08f49fa0d6f1451b9cf4f4042401b1b02561a (diff)
parent8b4423b04f519b78e0e9196ae1521531c80c743b (diff)
downloadrust-ed37b00b06f14e41740bd296e99b4ece0ce63c84.tar.gz
rust-ed37b00b06f14e41740bd296e99b4ece0ce63c84.zip
auto merge of #9803 : alexcrichton/rust/less-pub2, r=brson
This change was waiting for privacy to get sorted out, which should be true now
that #8215 has landed.

Closes #4427
Diffstat (limited to 'src/libstd/rt/task.rs')
-rw-r--r--src/libstd/rt/task.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index 71ab3b571c4..d5278975d8d 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -17,7 +17,7 @@ use borrow;
 use cast::transmute;
 use cleanup;
 use local_data;
-use libc::{c_void, uintptr_t};
+use libc::{c_void, uintptr_t, c_char, size_t};
 use prelude::*;
 use option::{Option, Some, None};
 use rt::borrowck;
@@ -465,6 +465,48 @@ impl Unwinder {
     }
 }
 
+/// This is the entry point of unwinding for things like lang items and such.
+/// The arguments are normally generated by the compiler.
+pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! {
+    use rt::in_green_task_context;
+    use rt::task::Task;
+    use rt::local::Local;
+    use rt::logging::Logger;
+    use str::Str;
+    use c_str::CString;
+
+    unsafe {
+        let msg = CString::new(msg, false);
+        let file = CString::new(file, false);
+        let msg = match msg.as_str() {
+            Some(s) => s, None => rtabort!("message wasn't utf8?")
+        };
+        let file = match file.as_str() {
+            Some(s) => s, None => rtabort!("message wasn't utf8?")
+        };
+
+        if in_green_task_context() {
+            // Be careful not to allocate in this block, if we're failing we may
+            // have been failing due to a lack of memory in the first place...
+            do Local::borrow |task: &mut Task| {
+                let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
+                format_args!(|args| { task.logger.log(args) },
+                             "task '{}' failed at '{}', {}:{}",
+                             n, msg, file, line);
+            }
+        } else {
+            rterrln!("failed in non-task context at '{}', {}:{}",
+                     msg, file, line as int);
+        }
+
+        let task: *mut Task = Local::unsafe_borrow();
+        if (*task).unwinder.unwinding {
+            rtabort!("unwinding again");
+        }
+        (*task).unwinder.begin_unwind();
+    }
+}
+
 #[cfg(test)]
 mod test {
     use rt::test::*;