diff options
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/Cargo.toml | 3 | ||||
-rw-r--r-- | components/util/lib.rs | 3 | ||||
-rw-r--r-- | components/util/panicking.rs | 52 | ||||
-rw-r--r-- | components/util/thread.rs | 42 |
4 files changed, 1 insertions, 99 deletions
diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index c713aac2957..e5f0bc9b5d3 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -11,12 +11,11 @@ path = "lib.rs" [features] # servo as opposed to geckolib -servo = ["serde", "serde_macros", "backtrace", "ipc-channel", "app_units/plugins", +servo = ["serde", "serde_macros", "ipc-channel", "app_units/plugins", "euclid/plugins", "euclid/unstable", "url/heap_size", "url/serde", "plugins"] [dependencies] app_units = "0.2.5" -backtrace = {version = "0.2.1", optional = true} bitflags = "0.7" euclid = "0.7.1" getopts = "0.2.11" diff --git a/components/util/lib.rs b/components/util/lib.rs index 6b906f83c8d..c36ec47a4cb 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #![cfg_attr(feature = "servo", feature(custom_derive))] -#![cfg_attr(feature = "servo", feature(fnbox))] #![cfg_attr(feature = "servo", feature(plugin))] #![cfg_attr(feature = "servo", feature(reflect_marker))] #![cfg_attr(feature = "servo", plugin(serde_macros))] @@ -12,7 +11,6 @@ #![deny(unsafe_code)] extern crate app_units; -#[cfg(feature = "servo")] extern crate backtrace; #[allow(unused_extern_crates)] #[macro_use] extern crate bitflags; extern crate euclid; extern crate getopts; @@ -31,7 +29,6 @@ pub mod basedir; pub mod geometry; #[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod ipc; #[allow(unsafe_code)] pub mod opts; -#[cfg(feature = "servo")] pub mod panicking; pub mod prefs; pub mod resource_files; pub mod thread; diff --git a/components/util/panicking.rs b/components/util/panicking.rs deleted file mode 100644 index 20b3d002443..00000000000 --- a/components/util/panicking.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use std::any::Any; -use std::boxed::FnBox; -use std::cell::RefCell; -use std::panic::{PanicInfo, take_hook, set_hook}; -use std::sync::{Once, ONCE_INIT}; -use std::thread; - -// only set the panic hook once -static HOOK_SET: Once = ONCE_INIT; - -/// TLS data pertaining to how failures should be reported -pub struct PanicHandlerLocal { - /// failure handler passed through spawn_named_with_send_on_failure - pub fail: Box<FnBox(&Any)> -} - -thread_local!(pub static LOCAL_INFO: RefCell<Option<PanicHandlerLocal>> = RefCell::new(None)); - -/// Set the thread-local panic hook -pub fn set_thread_local_hook(local: Box<FnBox(&Any)>) { - LOCAL_INFO.with(|i| *i.borrow_mut() = Some(PanicHandlerLocal { fail: local })); -} - -/// Initiates the custom panic hook -/// Should be called in main() after arguments have been parsed -pub fn initiate_panic_hook() { - // Set the panic handler only once. It is global. - HOOK_SET.call_once(|| { - // The original backtrace-printing hook. We still want to call this - let hook = take_hook(); - - let new_hook = move |info: &PanicInfo| { - let payload = info.payload(); - let name = thread::current().name().unwrap_or("<unknown thread>").to_string(); - // Notify error handlers stored in LOCAL_INFO if any - LOCAL_INFO.with(|i| { - if let Some(local_info) = i.borrow_mut().take() { - debug!("Thread `{}` failed, notifying error handlers", name); - (local_info.fail).call_box((payload, )); - } else { - hook(&info); - } - }); - }; - set_hook(Box::new(new_hook)); - }); - -} diff --git a/components/util/thread.rs b/components/util/thread.rs index 571d3529d9f..130187244db 100644 --- a/components/util/thread.rs +++ b/components/util/thread.rs @@ -2,12 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#[cfg(feature = "servo")] use backtrace::Backtrace; -#[cfg(feature = "servo")] use ipc_channel::ipc::IpcSender; -#[cfg(feature = "servo")] use panicking; -#[cfg(feature = "servo")] use serde::Serialize; -#[cfg(feature = "servo")] use std::any::Any; -#[cfg(feature = "servo")] use thread_state; use std::thread; pub fn spawn_named<F>(name: String, f: F) @@ -15,39 +9,3 @@ pub fn spawn_named<F>(name: String, f: F) { thread::Builder::new().name(name).spawn(f).expect("Thread spawn failed"); } - -/// Arrange to send a particular message to a channel if the thread fails. -#[cfg(feature = "servo")] -pub fn spawn_named_with_send_on_panic<F, Id>(name: String, - state: thread_state::ThreadState, - f: F, - id: Id, - panic_chan: IpcSender<(Id, String, String)>) - where F: FnOnce() + Send + 'static, - Id: Copy + Send + Serialize + 'static, -{ - thread::Builder::new().name(name).spawn(move || { - thread_state::initialize(state); - panicking::set_thread_local_hook(Box::new(move |payload: &Any| { - debug!("Thread failed, notifying constellation"); - let reason = payload.downcast_ref::<String>().map(|s| String::from(&**s)) - .or(payload.downcast_ref::<&'static str>().map(|s| String::from(*s))) - .unwrap_or_else(|| String::from("<unknown reason>")); - // FIXME(ajeffrey): Really we should send the backtrace itself, - // not just a string representation. Unfortunately we can't, because - // Servo won't compile backtrace with the serialize-serde feature: - // - // .../quasi_macros-0.9.0/src/lib.rs:19:29: 19:32 error: mismatched types: - // expected `&mut syntex::Registry`, - // found `&mut rustc_plugin::Registry<'_>` - // (expected struct `syntex::Registry`, - // found struct `rustc_plugin::Registry`) [E0308] - // .../quasi_macros-0.9.0/src/lib.rs:19 quasi_codegen::register(reg); - // - // so for the moment we just send a debug string. - let backtrace = format!("{:?}", Backtrace::new()); - let _ = panic_chan.send((id, reason, backtrace)); - })); - f() - }).expect("Thread spawn failed"); -} |