summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/mod.rs2
-rw-r--r--src/lib.rs8
-rw-r--r--src/options.rs3
-rw-r--r--tests/expectations/tests/gen-destructors.rs33
-rw-r--r--tests/headers/gen-destructors.hpp7
5 files changed, 47 insertions, 6 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 78b2e02a..6d9af09b 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -1598,7 +1598,7 @@ impl CodeGenerator for CompInfo {
}
}
- if ctx.options().codegen_config.destructor {
+ if ctx.options().codegen_config.destructors {
if let Some((is_virtual, destructor)) = self.destructor() {
let kind = if is_virtual {
MethodKind::VirtualDestructor
diff --git a/src/lib.rs b/src/lib.rs
index 8ee16534..e6a66dfc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -109,8 +109,8 @@ pub struct CodegenConfig {
pub methods: bool,
/// Whether to generate constructors.
pub constructors: bool,
- /// Whether to generate a destructor.
- pub destructor: bool,
+ /// Whether to generate destructors.
+ pub destructors: bool,
}
impl CodegenConfig {
@@ -122,7 +122,7 @@ impl CodegenConfig {
vars: true,
methods: true,
constructors: true,
- destructor: true,
+ destructors: true,
}
}
@@ -134,7 +134,7 @@ impl CodegenConfig {
vars: false,
methods: false,
constructors: false,
- destructor: false,
+ destructors: false,
}
}
}
diff --git a/src/options.rs b/src/options.rs
index 9f229f66..6d06ad3b 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -112,7 +112,7 @@ pub fn builder_from_flags<I>
.long("generate")
.help("Generate a given kind of items, split by commas. \
Valid values are \"functions\",\"types\", \"vars\", \
- \"methods\" and \"constructors\".")
+ \"methods\", \"constructors\" and \"destructors\".")
.takes_value(true),
Arg::with_name("ignore-methods")
.long("ignore-methods")
@@ -272,6 +272,7 @@ pub fn builder_from_flags<I>
"vars" => config.vars = true,
"methods" => config.methods = true,
"constructors" => config.constructors = true,
+ "destructors" => config.destructors = true,
_ => {
return Err(Error::new(ErrorKind::Other,
"Unknown generate item"));
diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs
new file mode 100644
index 00000000..14a51d14
--- /dev/null
+++ b/tests/expectations/tests/gen-destructors.rs
@@ -0,0 +1,33 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Default)]
+pub struct Foo {
+ pub bar: ::std::os::raw::c_int,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
+ 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( Foo ) , "::" ,
+ stringify ! ( bar ) ));
+}
+extern "C" {
+ #[link_name = "_ZN3FooD1Ev"]
+ pub fn Foo_Foo_destructor(this: *mut Foo);
+}
+impl Foo {
+ #[inline]
+ pub unsafe fn __bindgen_destructor__(&mut self) {
+ Foo_Foo_destructor(&mut *self)
+ }
+}
diff --git a/tests/headers/gen-destructors.hpp b/tests/headers/gen-destructors.hpp
new file mode 100644
index 00000000..719eb248
--- /dev/null
+++ b/tests/headers/gen-destructors.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: --generate types,destructors,functions
+
+class Foo {
+ int bar;
+ public:
+ ~Foo();
+};