From 362eac2b12568428637b7cdf091db3fbc9d46c00 Mon Sep 17 00:00:00 2001 From: Ian Gilham Date: Thu, 27 Oct 2016 18:00:26 +0100 Subject: [PATCH] Changed `clang::TranslationUnit::parse` to return an Option --- src/clang.rs | 8 ++++++-- src/ir/context.rs | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index fa4eb01b72..90da618aca 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -919,7 +919,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 { let fname = CString::new(file).unwrap(); let _c_args: Vec = 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(); @@ -932,7 +932,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 da5f334f05..8031f5c08c 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 {