summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-04-14 14:34:16 +0200
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-04-14 14:34:16 +0200
commitb914db16661a389093a78189612710912206f9a6 (patch)
treeffd794ee0f6c49d3ddd3b53a97b3521e65978819
parent2511e9ec1ad21e66ee8727700f02b8f38c770ffc (diff)
bindgen: Add flag to customise flags added to types with destructor
-rw-r--r--src/bin/bindgen.rs7
-rw-r--r--src/gen.rs5
-rw-r--r--src/lib.rs20
3 files changed, 25 insertions, 7 deletions
diff --git a/src/bin/bindgen.rs b/src/bin/bindgen.rs
index 42c0cb40..6cd0059b 100644
--- a/src/bin/bindgen.rs
+++ b/src/bin/bindgen.rs
@@ -120,6 +120,13 @@ fn parse_args(args: &[String]) -> ParseResult {
options.gen_bitfield_methods = false;
ix += 1;
}
+ "-dtor-attr" => {
+ if ix + 1 >= args_len {
+ return ParseResult::ParseErr("Missing dtor attr".to_string());
+ }
+ options.dtor_attrs.push(args[ix + 1].clone());
+ ix += 2;
+ }
"-allow-unknown-types" => {
options.fail_on_unknown_type = false;
ix += 1;
diff --git a/src/gen.rs b/src/gen.rs
index 4244c926..13c62dbe 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -844,7 +844,10 @@ fn comp_attrs(ctx: &GenCtx, ci: &CompInfo, name: &str, has_destructor: bool, ext
if has_destructor {
- attrs.push(quote_attr!(&ctx.ext_cx, #[unsafe_no_drop_flag]));
+ for attr in ctx.options.dtor_attrs.iter() {
+ let attr = ctx.ext_cx.ident_of(attr);
+ attrs.push(quote_attr!(&ctx.ext_cx, #[$attr]));
+ }
} else {
// TODO: make can_derive_debug more reliable in presence of opaque types and all that stuff
let can_derive_debug = ci.members.iter()
diff --git a/src/lib.rs b/src/lib.rs
index c5737035..3bcc4ca0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -86,6 +86,11 @@ impl<'a> Builder<'a> {
self
}
+ pub fn dtor_attr<T: Into<String>>(&mut self, attr: T) -> &mut Self {
+ self.options.dtor_attrs.push(attr.into());
+ self
+ }
+
pub fn forbid_unknown_types(&mut self) -> &mut Self {
self.options.fail_on_unknown_type = true;
self
@@ -148,18 +153,20 @@ pub struct BindgenOptions {
pub derive_debug: bool,
pub override_enum_ty: String,
pub raw_lines: Vec<String>,
+ /// Attributes for a type with destructor
+ pub dtor_attrs: Vec<String>,
pub clang_args: Vec<String>,
}
impl Default for BindgenOptions {
fn default() -> BindgenOptions {
BindgenOptions {
- match_pat: Vec::new(),
- blacklist_type: Vec::new(),
- opaque_types: Vec::new(),
+ match_pat: vec![],
+ blacklist_type: vec![],
+ opaque_types: vec![],
builtins: false,
rust_enums: true,
- links: Vec::new(),
+ links: vec![],
emit_ast: false,
ignore_functions: false,
gen_bitfield_methods: true,
@@ -169,7 +176,8 @@ impl Default for BindgenOptions {
enable_cxx_namespaces: false,
override_enum_ty: "".to_string(),
raw_lines: vec![],
- clang_args: Vec::new()
+ dtor_attrs: vec![],
+ clang_args: vec![],
}
}
}
@@ -221,7 +229,7 @@ impl Bindings {
}
pub fn to_string(&self) -> String {
- let mut mod_str = Vec::new();
+ let mut mod_str = vec![];
{
let ref_writer = Box::new(mod_str.by_ref()) as Box<Write>;
self.write(ref_writer).expect("Could not write bindings to string");