summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Barnard <eabarnard@gmail.com>2014-12-28 23:02:26 +0100
committerEdward Barnard <eabarnard@gmail.com>2014-12-28 23:25:52 +0100
commitdd96a0c5f416c6d0e0689079e228de536a643153 (patch)
treef589bba1b9717f9741501263bf02f34c3f0048da
parent02d34166ff3b1ab192f949e9eb880dd54a476b50 (diff)
Create names for unnamed bitfield members so rustc can parse the (incorrect) definitions.
-rw-r--r--src/gen.rs11
-rw-r--r--tests/forward_declared_struct.rs2
-rw-r--r--tests/headers/unnamed_bitfields.h10
-rw-r--r--tests/unnamed_bitfields.rs12
4 files changed, 33 insertions, 2 deletions
diff --git a/src/gen.rs b/src/gen.rs
index a08d8aeb..68629250 100644
--- a/src/gen.rs
+++ b/src/gen.rs
@@ -473,6 +473,7 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: String, members: Vec<CompMember>) -> Ve
// they are encountered. The declarations end up in 'extra' and are emitted
// after the current struct.
let mut extra = vec!();
+ let mut unnamed: u32 = 0;
for m in members.iter() {
let (opt_rc_c, opt_f) = match m {
@@ -482,7 +483,15 @@ fn cstruct_to_rs(ctx: &mut GenCtx, name: String, members: Vec<CompMember>) -> Ve
};
if let Some(f) = opt_f {
- let f_name = rust_type_id(ctx, f.name.clone());
+ // Needed so bitfields with unnamed members still parse
+ // They're still wrong though
+ let f_name = if f.name.is_empty() || "_" == f.name.as_slice() {
+ unnamed += 1;
+ format!("unnamed_field{}", unnamed)
+ } else {
+ rust_type_id(ctx, f.name.clone())
+ };
+
let f_ty = P(cty_to_rs(ctx, &f.ty));
fields.push(respan(ctx.span, ast::StructField_ {
diff --git a/tests/forward_declared_struct.rs b/tests/forward_declared_struct.rs
index 7e9bfc8b..a5d95743 100644
--- a/tests/forward_declared_struct.rs
+++ b/tests/forward_declared_struct.rs
@@ -8,5 +8,5 @@ extern crate libc;
#[test]
fn test_struct_containing_forward_declared_struct() {
mod ffi { bindgen!("headers/struct_containing_forward_declared_struct.h"); }
- // Checking that struct b is not duplicated
+ // Check that struct b is not duplicated
} \ No newline at end of file
diff --git a/tests/headers/unnamed_bitfields.h b/tests/headers/unnamed_bitfields.h
new file mode 100644
index 00000000..6ca9ec76
--- /dev/null
+++ b/tests/headers/unnamed_bitfields.h
@@ -0,0 +1,10 @@
+struct bitfield
+{
+ unsigned short
+ a :1,
+ b :1,
+ c :1,
+ :1,
+ :2,
+ d :2
+}; \ No newline at end of file
diff --git a/tests/unnamed_bitfields.rs b/tests/unnamed_bitfields.rs
new file mode 100644
index 00000000..a5bb1332
--- /dev/null
+++ b/tests/unnamed_bitfields.rs
@@ -0,0 +1,12 @@
+#![feature(phase)]
+
+#[phase(plugin)]
+extern crate bindgen;
+
+extern crate libc;
+
+#[test]
+fn test_unnamed_bitfields() {
+ mod ffi { bindgen!("headers/unnamed_bitfields.h"); }
+ // Check that there are no unnamed struct fields
+} \ No newline at end of file