diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-27 15:36:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-27 15:36:58 -0500 |
commit | a6088ee904a249890e98ab3e74875af71ed6672b (patch) | |
tree | e2f2fdff1b107404bcf753358c54a42a4bf6bfd0 | |
parent | 72f435e5d0dd818f01173242839b2e89ed104b83 (diff) | |
parent | 362eac2b12568428637b7cdf091db3fbc9d46c00 (diff) |
Auto merge of #153 - igilham:master, r=emilio
Changed the potentially null pointer to an Optional.
The caller previously assumed the pointer was always valid and not null, so I called `expect` to make it fail early if it isn't.
Fixes #144.
-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 { |