summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-11-21 14:28:35 -0800
committerNick Fitzgerald <fitzgen@gmail.com>2016-11-21 14:37:28 -0800
commitbd29a7a86ec9b7a2666fe290da940e319e71b008 (patch)
treecedf884b6cdce3dab6d87a4f5db21678e70c2a65
parent77868f4379dc40b91dfd3674c8091c14dcf69ecd (diff)
Trace function signature types
This extends the `TypeCollector` trait implementation for `Item` to consider items of kind `Function` and to collect the types found in the function's signature. Fixes #291
-rw-r--r--libbindgen/src/ir/item.rs5
-rw-r--r--libbindgen/tests/expectations/tests/type-referenced-by-whitelisted-function.rs22
-rw-r--r--libbindgen/tests/headers/type-referenced-by-whitelisted-function.h7
3 files changed, 34 insertions, 0 deletions
diff --git a/libbindgen/src/ir/item.rs b/libbindgen/src/ir/item.rs
index d96936ad..b857acf9 100644
--- a/libbindgen/src/ir/item.rs
+++ b/libbindgen/src/ir/item.rs
@@ -142,6 +142,11 @@ impl TypeCollector for Item {
ty.collect_types(ctx, types, self);
}
}
+ ItemKind::Function(ref fun) => {
+ if !self.is_opaque(ctx) {
+ types.insert(fun.signature());
+ }
+ }
_ => {} // FIXME.
}
}
diff --git a/libbindgen/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/libbindgen/tests/expectations/tests/type-referenced-by-whitelisted-function.rs
new file mode 100644
index 00000000..c9686501
--- /dev/null
+++ b/libbindgen/tests/expectations/tests/type-referenced-by-whitelisted-function.rs
@@ -0,0 +1,22 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct dl_phdr_info {
+ pub x: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_dl_phdr_info() {
+ assert_eq!(::std::mem::size_of::<dl_phdr_info>() , 4usize);
+ assert_eq!(::std::mem::align_of::<dl_phdr_info>() , 4usize);
+}
+impl Clone for dl_phdr_info {
+ fn clone(&self) -> Self { *self }
+}
+extern "C" {
+ pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int;
+}
diff --git a/libbindgen/tests/headers/type-referenced-by-whitelisted-function.h b/libbindgen/tests/headers/type-referenced-by-whitelisted-function.h
new file mode 100644
index 00000000..86b00303
--- /dev/null
+++ b/libbindgen/tests/headers/type-referenced-by-whitelisted-function.h
@@ -0,0 +1,7 @@
+// bindgen-flags: --whitelist-function dl_iterate_phdr
+
+struct dl_phdr_info {
+ int x;
+};
+
+int dl_iterate_phdr(struct dl_phdr_info *);