summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Deng <jeffreydeng@live.com>2017-01-30 11:36:56 -0500
committerJeffrey Deng <jeffreydeng@live.com>2017-02-02 16:54:44 -0500
commit09bc83526b51f8c2728dbaee2754a3020243d752 (patch)
tree8611828765180c5ddcb83dec3aeb83685a27881d
parentc1aaa6a400d4a92ae442bfeaa188c5303810611b (diff)
Added catch_unwind to catch panic at generator due to missing or incorrect flags
-rw-r--r--src/chooser.rs3
-rw-r--r--src/lib.rs5
-rw-r--r--src/main.rs21
3 files changed, 26 insertions, 3 deletions
diff --git a/src/chooser.rs b/src/chooser.rs
index 51392d70..d7a20771 100644
--- a/src/chooser.rs
+++ b/src/chooser.rs
@@ -3,10 +3,11 @@
pub use ir::int::IntKind;
pub use ir::enum_ty::{EnumVariantValue, EnumVariantCustomBehavior};
use std::fmt;
+use std::panic::UnwindSafe;
/// A trait to allow configuring different kinds of types in different
/// situations.
-pub trait TypeChooser: fmt::Debug {
+pub trait TypeChooser: fmt::Debug + UnwindSafe {
/// The integer kind an integer macro should have, given a name and the
/// value of that macro, or `None` if you want the default to be chosen.
fn int_macro(&self, _name: &str, _value: i64) -> Option<IntKind> {
diff --git a/src/lib.rs b/src/lib.rs
index d6f3c66e..f2fdc7b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -555,6 +555,11 @@ pub struct BindgenOptions {
pub objc_extern_crate: bool,
}
+/// TODO(emilio): This is sort of a lie (see the error message that results from
+/// removing this), but since we don't share references across panic boundaries
+/// it's ok.
+impl ::std::panic::UnwindSafe for BindgenOptions {}
+
impl BindgenOptions {
fn build(&mut self) {
self.whitelisted_vars.build();
diff --git a/src/main.rs b/src/main.rs
index a7bd9618..c5d2b063 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@ extern crate rustc_serialize;
use bindgen::clang_version;
use std::env;
+use std::panic;
mod options;
use options::builder_from_flags;
@@ -44,8 +45,24 @@ pub fn main() {
match builder_from_flags(bind_args.into_iter()) {
Ok((builder, output)) => {
- let mut bindings = builder.generate()
- .expect("Unable to generate bindings");
+
+ let builder_result =
+ panic::catch_unwind(||
+ builder.generate().expect("Unable to generate bindings")
+ );
+
+ if builder_result.is_err() {
+ println!("Bindgen unexpectedly panicked");
+ println!("This may be caused by one of the known-unsupported \
+ things (https://github.com/servo/rust-bindgen#c), \
+ please modify the bindgen flags to work around it as \
+ described in https://github.com/servo/rust-bindgen#c");
+ println!("Otherwise, please file an issue at \
+ https://github.com/servo/rust-bindgen/issues/new");
+ std::process::exit(1);
+ }
+
+ let mut bindings = builder_result.unwrap();
bindings.write(output)
.expect("Unable to write output");
bindings.write_dummy_uses()