summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-21 17:25:42 -0600
committerGitHub <noreply@github.com>2016-11-21 17:25:42 -0600
commitd4a66485a1438b5c3502fc1dd633ce42d9e04405 (patch)
tree175bf5e1d145af5380d8026f2c20bba3604792e4
parentec9852a3a8e0ee6e2b4082c1de13432bb4662f1c (diff)
parentbd29a7a86ec9b7a2666fe290da940e319e71b008 (diff)
Auto merge of #293 - fitzgen:type-referenced-by-whitelisted-function, r=emilio
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 r? @emilio
-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 *);