File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 3
3
pub use ir:: int:: IntKind ;
4
4
pub use ir:: enum_ty:: { EnumVariantValue , EnumVariantCustomBehavior } ;
5
5
use std:: fmt;
6
+ use std:: panic:: UnwindSafe ;
6
7
7
8
/// A trait to allow configuring different kinds of types in different
8
9
/// situations.
9
- pub trait TypeChooser : fmt:: Debug {
10
+ pub trait TypeChooser : fmt:: Debug + UnwindSafe {
10
11
/// The integer kind an integer macro should have, given a name and the
11
12
/// value of that macro, or `None` if you want the default to be chosen.
12
13
fn int_macro ( & self , _name : & str , _value : i64 ) -> Option < IntKind > {
Original file line number Diff line number Diff line change @@ -555,6 +555,11 @@ pub struct BindgenOptions {
555
555
pub objc_extern_crate : bool ,
556
556
}
557
557
558
+ /// TODO(emilio): This is sort of a lie (see the error message that results from
559
+ /// removing this), but since we don't share references across panic boundaries
560
+ /// it's ok.
561
+ impl :: std:: panic:: UnwindSafe for BindgenOptions { }
562
+
558
563
impl BindgenOptions {
559
564
fn build ( & mut self ) {
560
565
self . whitelisted_vars . build ( ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ extern crate rustc_serialize;
8
8
9
9
use bindgen:: clang_version;
10
10
use std:: env;
11
+ use std:: panic;
11
12
12
13
mod options;
13
14
use options:: builder_from_flags;
@@ -44,8 +45,24 @@ pub fn main() {
44
45
45
46
match builder_from_flags ( bind_args. into_iter ( ) ) {
46
47
Ok ( ( builder, output) ) => {
47
- let mut bindings = builder. generate ( )
48
- . expect ( "Unable to generate bindings" ) ;
48
+
49
+ let builder_result =
50
+ panic:: catch_unwind ( ||
51
+ builder. generate ( ) . expect ( "Unable to generate bindings" )
52
+ ) ;
53
+
54
+ if builder_result. is_err ( ) {
55
+ println ! ( "Bindgen unexpectedly panicked" ) ;
56
+ println ! ( "This may be caused by one of the known-unsupported \
57
+ things (https://github.com/servo/rust-bindgen#c), \
58
+ please modify the bindgen flags to work around it as \
59
+ described in https://github.com/servo/rust-bindgen#c") ;
60
+ println ! ( "Otherwise, please file an issue at \
61
+ https://github.com/servo/rust-bindgen/issues/new") ;
62
+ std:: process:: exit ( 1 ) ;
63
+ }
64
+
65
+ let mut bindings = builder_result. unwrap ( ) ;
49
66
bindings. write ( output)
50
67
. expect ( "Unable to write output" ) ;
51
68
bindings. write_dummy_uses ( )
You can’t perform that action at this time.
0 commit comments