summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-09-19 02:48:16 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-09-19 02:48:16 +0200
commit9087c2f065c8ae868ad418afee0c4bc5921337e6 (patch)
treec3fedef5f5a0598a4204a0e2b17bea1654c7dda6
parentcf7bb3c180da0dcf2360967698e6b19fd4e21d4e (diff)
codegen: Generate u128 / i128 when available.
-rw-r--r--src/codegen/mod.rs20
-rw-r--r--tests/expectations/tests/i128.rs48
-rw-r--r--tests/headers/i128.h6
3 files changed, 69 insertions, 5 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 8aa8d348..86a29c50 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3059,11 +3059,21 @@ impl TryToRustTy for Type {
#ident
})
}
- // FIXME: This doesn't generate the proper alignment, but we
- // can't do better right now. We should be able to use
- // i128/u128 when they're available.
- IntKind::U128 | IntKind::I128 => {
- Ok(quote! { [u64; 2] })
+ IntKind::U128 => {
+ Ok(if ctx.options().rust_features.i128_and_u128 {
+ quote! { u128 }
+ } else {
+ // Best effort thing, but wrong alignment
+ // unfortunately.
+ quote! { [u64; 2] }
+ })
+ }
+ IntKind::I128 => {
+ Ok(if ctx.options().rust_features.i128_and_u128 {
+ quote! { i128 }
+ } else {
+ quote! { [u64; 2] }
+ })
}
}
}
diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs
new file mode 100644
index 00000000..cd91f141
--- /dev/null
+++ b/tests/expectations/tests/i128.rs
@@ -0,0 +1,48 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct foo {
+ pub my_signed: i128,
+ pub my_unsigned: u128,
+}
+#[test]
+fn bindgen_test_layout_foo() {
+ assert_eq!(
+ ::std::mem::size_of::<foo>(),
+ 32usize,
+ concat!("Size of: ", stringify!(foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<foo>(),
+ 16usize,
+ concat!("Alignment of ", stringify!(foo))
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<foo>())).my_signed as *const _ as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(my_signed)
+ )
+ );
+ assert_eq!(
+ unsafe { &(*(::std::ptr::null::<foo>())).my_unsigned as *const _ as usize },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(foo),
+ "::",
+ stringify!(my_unsigned)
+ )
+ );
+}
diff --git a/tests/headers/i128.h b/tests/headers/i128.h
new file mode 100644
index 00000000..6ec399c7
--- /dev/null
+++ b/tests/headers/i128.h
@@ -0,0 +1,6 @@
+// bindgen-flags: --rust-target 1.26
+
+struct foo {
+ __int128 my_signed;
+ unsigned __int128 my_unsigned;
+};