Skip to content

#144 Changed clang::TranslationUnit::parse to return an Option #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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();
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down