Skip to content

Check if clang_Type_getNumTemplateArguments is loaded before use #1321

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
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
14 changes: 12 additions & 2 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,13 @@ impl Type {
/// Get the number of template arguments this type has, or `None` if it is
/// not some kind of template.
pub fn num_template_args(&self) -> Option<u32> {
// If an old libclang is loaded, we have no hope of answering this
// question correctly. However, that's no reason to panic when
// generating bindings for simple C headers with an old libclang.
if !clang_Type_getNumTemplateArguments::is_loaded() {
return None
}

let n = unsafe { clang_Type_getNumTemplateArguments(self.x) };
if n >= 0 {
Some(n as u32)
Expand Down Expand Up @@ -1639,8 +1646,11 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
depth,
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
);
let num_template_args =
unsafe { clang_Type_getNumTemplateArguments(ty.x) };
let num_template_args = if clang_Type_getNumTemplateArguments::is_loaded() {
unsafe { clang_Type_getNumTemplateArguments(ty.x) }
} else {
-1
};
if num_template_args >= 0 {
print_indent(
depth,
Expand Down