Skip to content

Commit a6088ee

Browse files
author
bors-servo
authored
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.
2 parents 72f435e + 362eac2 commit a6088ee

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/clang.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl fmt::Debug for TranslationUnit {
924924
impl TranslationUnit {
925925
/// Parse a source file into a translation unit.
926926
pub fn parse(ix: &Index, file: &str, cmd_args: &[String],
927-
unsaved: &[UnsavedFile], opts: ::libc::c_uint) -> TranslationUnit {
927+
unsaved: &[UnsavedFile], opts: ::libc::c_uint) -> Option<TranslationUnit> {
928928
let fname = CString::new(file).unwrap();
929929
let _c_args: Vec<CString> = cmd_args.iter().map(|s| CString::new(s.clone()).unwrap()).collect();
930930
let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect();
@@ -937,7 +937,11 @@ impl TranslationUnit {
937937
c_unsaved.len() as c_uint,
938938
opts)
939939
};
940-
TranslationUnit { x: tu }
940+
if tu.is_null() {
941+
None
942+
} else {
943+
Some(TranslationUnit { x: tu })
944+
}
941945
}
942946

943947
/// Reparse this translation unit, maybe because the file changed on disk or

src/ir/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl<'ctx> BindgenContext<'ctx> {
104104

105105
let translation_unit =
106106
clang::TranslationUnit::parse(&index, "", &options.clang_args, &[],
107-
clangll::CXTranslationUnit_DetailedPreprocessingRecord);
107+
clangll::CXTranslationUnit_DetailedPreprocessingRecord)
108+
.expect("null TranslationUnit received from `clang::TranslationUnit::parse`");
108109

109110
let root_module = Self::build_root_module();
110111
let mut me = BindgenContext {

0 commit comments

Comments
 (0)