Skip to content

Commit 4044876

Browse files
committed
options: Allow configuring destructors via CLI.
1 parent 11ffbd1 commit 4044876

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

src/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ impl CodeGenerator for CompInfo {
15981598
}
15991599
}
16001600

1601-
if ctx.options().codegen_config.destructor {
1601+
if ctx.options().codegen_config.destructors {
16021602
if let Some((is_virtual, destructor)) = self.destructor() {
16031603
let kind = if is_virtual {
16041604
MethodKind::VirtualDestructor

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub struct CodegenConfig {
109109
pub methods: bool,
110110
/// Whether to generate constructors.
111111
pub constructors: bool,
112-
/// Whether to generate a destructor.
113-
pub destructor: bool,
112+
/// Whether to generate destructors.
113+
pub destructors: bool,
114114
}
115115

116116
impl CodegenConfig {
@@ -122,7 +122,7 @@ impl CodegenConfig {
122122
vars: true,
123123
methods: true,
124124
constructors: true,
125-
destructor: true,
125+
destructors: true,
126126
}
127127
}
128128

@@ -134,7 +134,7 @@ impl CodegenConfig {
134134
vars: false,
135135
methods: false,
136136
constructors: false,
137-
destructor: false,
137+
destructors: false,
138138
}
139139
}
140140
}

src/options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn builder_from_flags<I>
112112
.long("generate")
113113
.help("Generate a given kind of items, split by commas. \
114114
Valid values are \"functions\",\"types\", \"vars\", \
115-
\"methods\" and \"constructors\".")
115+
\"methods\", \"constructors\" and \"destructors\".")
116116
.takes_value(true),
117117
Arg::with_name("ignore-methods")
118118
.long("ignore-methods")
@@ -272,6 +272,7 @@ pub fn builder_from_flags<I>
272272
"vars" => config.vars = true,
273273
"methods" => config.methods = true,
274274
"constructors" => config.constructors = true,
275+
"destructors" => config.destructors = true,
275276
_ => {
276277
return Err(Error::new(ErrorKind::Other,
277278
"Unknown generate item"));
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default)]
9+
pub struct Foo {
10+
pub bar: ::std::os::raw::c_int,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Foo() {
14+
assert_eq!(::std::mem::size_of::<Foo>() , 4usize , concat ! (
15+
"Size of: " , stringify ! ( Foo ) ));
16+
assert_eq! (::std::mem::align_of::<Foo>() , 4usize , concat ! (
17+
"Alignment of " , stringify ! ( Foo ) ));
18+
assert_eq! (unsafe {
19+
& ( * ( 0 as * const Foo ) ) . bar as * const _ as usize } ,
20+
0usize , concat ! (
21+
"Alignment of field: " , stringify ! ( Foo ) , "::" ,
22+
stringify ! ( bar ) ));
23+
}
24+
extern "C" {
25+
#[link_name = "_ZN3FooD1Ev"]
26+
pub fn Foo_Foo_destructor(this: *mut Foo);
27+
}
28+
impl Foo {
29+
#[inline]
30+
pub unsafe fn __bindgen_destructor__(&mut self) {
31+
Foo_Foo_destructor(&mut *self)
32+
}
33+
}

tests/headers/gen-destructors.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// bindgen-flags: --generate types,destructors,functions
2+
3+
class Foo {
4+
int bar;
5+
public:
6+
~Foo();
7+
};

0 commit comments

Comments
 (0)