Skip to content

Commit 1f097dd

Browse files
author
bors-servo
authored
Auto merge of #1321 - stouset:check-if-num-template-args-is-loaded, r=emilio
Check if `clang_Type_getNumTemplateArguments` is loaded before use Fixes #1304, which reapplies #916 which was regressed by #915.
2 parents ede6054 + c63a095 commit 1f097dd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/clang.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,13 @@ impl Type {
911911
/// Get the number of template arguments this type has, or `None` if it is
912912
/// not some kind of template.
913913
pub fn num_template_args(&self) -> Option<u32> {
914+
// If an old libclang is loaded, we have no hope of answering this
915+
// question correctly. However, that's no reason to panic when
916+
// generating bindings for simple C headers with an old libclang.
917+
if !clang_Type_getNumTemplateArguments::is_loaded() {
918+
return None
919+
}
920+
914921
let n = unsafe { clang_Type_getNumTemplateArguments(self.x) };
915922
if n >= 0 {
916923
Some(n as u32)
@@ -1639,8 +1646,11 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
16391646
depth,
16401647
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
16411648
);
1642-
let num_template_args =
1643-
unsafe { clang_Type_getNumTemplateArguments(ty.x) };
1649+
let num_template_args = if clang_Type_getNumTemplateArguments::is_loaded() {
1650+
unsafe { clang_Type_getNumTemplateArguments(ty.x) }
1651+
} else {
1652+
-1
1653+
};
16441654
if num_template_args >= 0 {
16451655
print_indent(
16461656
depth,

0 commit comments

Comments
 (0)