diff options
-rwxr-xr-x | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/context.rs | 3 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/clang.rs b/src/clang.rs index e3e0f313..c0934055 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -924,7 +924,7 @@ impl fmt::Debug for TranslationUnit { impl TranslationUnit { /// Parse a source file into a translation unit. pub fn parse(ix: &Index, file: &str, cmd_args: &[String], - unsaved: &[UnsavedFile], opts: ::libc::c_uint) -> TranslationUnit { + unsaved: &[UnsavedFile], opts: ::libc::c_uint) -> Option<TranslationUnit> { let fname = CString::new(file).unwrap(); let _c_args: Vec<CString> = cmd_args.iter().map(|s| CString::new(s.clone()).unwrap()).collect(); let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect(); @@ -937,7 +937,11 @@ impl TranslationUnit { c_unsaved.len() as c_uint, opts) }; - TranslationUnit { x: tu } + if tu.is_null() { + None + } else { + Some(TranslationUnit { x: tu }) + } } /// Reparse this translation unit, maybe because the file changed on disk or diff --git a/src/ir/context.rs b/src/ir/context.rs index da5f334f..8031f5c0 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -104,7 +104,8 @@ impl<'ctx> BindgenContext<'ctx> { let translation_unit = clang::TranslationUnit::parse(&index, "", &options.clang_args, &[], - clangll::CXTranslationUnit_DetailedPreprocessingRecord); + clangll::CXTranslationUnit_DetailedPreprocessingRecord) + .expect("null TranslationUnit received from `clang::TranslationUnit::parse`"); let root_module = Self::build_root_module(); let mut me = BindgenContext { |