summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Barnard <eabarnard@gmail.com>2015-01-03 14:15:20 +0000
committerEdward Barnard <eabarnard@gmail.com>2015-01-03 14:32:35 +0000
commitd120a06a07bf13a255899d5cfff334e4b0467ad0 (patch)
tree5b9ca9cac97cb2e495b2e2d967a1339b8db8668b
parentb016bc541ad172479f83615eddf49c129b2ddb74 (diff)
Don't try to generate assessors for bitfields in anonymous structs. Closes #151.
-rw-r--r--src/gen.rs9
-rw-r--r--tests/headers/union_with_anon_struct_bitfield.h7
-rw-r--r--tests/test_union.rs25
3 files changed, 38 insertions, 3 deletions
diff --git a/src/gen.rs b/src/gen.rs
index 598a5494..b528cacb 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -679,6 +679,9 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: uint,
let data_ident = ctx.ext_cx.ident_of(data_field);
let mk_field_method = |ctx: &mut GenCtx, f: &FieldInfo, offset: uint| {
+ // TODO: Implement bitfield accessors
+ if f.bitfields.is_some() { return None; }
+
let (f_name, _) = rust_id(ctx, f.name.clone());
let f_name_ident = ctx.ext_cx.ident_of(f_name.as_slice());
let ret_ty = P(cty_to_rs(ctx, &TPtr(box f.ty.clone(), false, Layout::zero())));
@@ -699,7 +702,7 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: uint,
}
)
};
- ast::MethodImplItem(method)
+ Some(ast::MethodImplItem(method))
};
let mut offset = data_offset;
@@ -707,7 +710,7 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: uint,
for m in members.iter() {
let advance_by = match m {
&CompMember::Field(ref f) => {
- methods.push(mk_field_method(ctx, f, offset));
+ methods.extend(mk_field_method(ctx, f, offset).into_iter());
f.ty.size()
}
&CompMember::Comp(ref rc_c) => {
@@ -717,7 +720,7 @@ fn gen_comp_methods(ctx: &mut GenCtx, data_field: &str, data_offset: uint,
c.layout.size
}
&CompMember::CompField(ref rc_c, ref f) => {
- methods.push(mk_field_method(ctx, f, offset));
+ methods.extend(mk_field_method(ctx, f, offset).into_iter());
let c = rc_c.borrow();
extra.extend(comp_to_rs(ctx, c.kind, comp_name(c.kind, &c.name),
diff --git a/tests/headers/union_with_anon_struct_bitfield.h b/tests/headers/union_with_anon_struct_bitfield.h
new file mode 100644
index 00000000..d39b92d1
--- /dev/null
+++ b/tests/headers/union_with_anon_struct_bitfield.h
@@ -0,0 +1,7 @@
+union foo {
+ int a;
+ struct {
+ int b : 7;
+ int c : 25;
+ };
+}; \ No newline at end of file
diff --git a/tests/test_union.rs b/tests/test_union.rs
index 15759e7f..61cb7a04 100644
--- a/tests/test_union.rs
+++ b/tests/test_union.rs
@@ -17,6 +17,31 @@ fn with_anon_struct() {
}
#[test]
+fn with_anon_struct_bitfield() {
+ assert_bind_eq!("headers/union_with_anon_struct_bitfield.h", cx,
+ quote_item!(cx,
+ #[repr(C)]
+ #[deriving(Copy)]
+ pub struct Union_foo {
+ pub _bindgen_data_: [u32; 1u],
+ }
+ ),
+ quote_item!(cx,
+ impl Union_foo {
+ pub unsafe fn a(&self) -> *mut ::libc::c_int {
+ ::std::mem::transmute(&self._bindgen_data_)
+ }
+ }
+ ),
+ quote_item!(cx,
+ impl ::std::default::Default for Union_foo {
+ fn default() -> Union_foo { unsafe { ::std::mem::zeroed() } }
+ }
+ )
+ );
+}
+
+#[test]
fn with_anon_union() {
mod ffi { bindgen!("headers/union_with_anon_union.h"); }
let mut x: ffi::Union_foo = Default::default();