summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWangshan Lu <wisagan@gmail.com>2017-08-01 15:08:15 +0800
committerWangshan Lu <wisagan@gmail.com>2017-08-01 15:08:15 +0800
commitcc938cb9bf656b49aecf1d569084b12ad56048d4 (patch)
tree867642860b5f07e3ab7d03bdedd7d81628bf4db3
parent09abb26c14ec5ea749d0a8b3538af95770946b15 (diff)
Support deriving copy for large array
-rw-r--r--src/ir/ty.rs3
-rw-r--r--tests/expectations/tests/class.rs20
-rw-r--r--tests/expectations/tests/layout_eth_conf.rs16
-rw-r--r--tests/expectations/tests/struct_with_derive_debug.rs8
-rw-r--r--tests/expectations/tests/struct_with_large_array.rs37
-rw-r--r--tests/headers/struct_with_large_array.hpp7
6 files changed, 89 insertions, 2 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index b3de1f03..b53e27bf 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -531,8 +531,7 @@ impl<'a> CanDeriveCopy<'a> for Type {
fn can_derive_copy(&self, ctx: &BindgenContext, item: &Item) -> bool {
match self.kind {
- TypeKind::Array(t, len) => {
- len <= RUST_DERIVE_IN_ARRAY_LIMIT &&
+ TypeKind::Array(t, _) => {
t.can_derive_copy_in_array(ctx, ())
}
TypeKind::ResolvedTypeRef(t) |
diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs
index 43e67153..413c033a 100644
--- a/tests/expectations/tests/class.rs
+++ b/tests/expectations/tests/class.rs
@@ -62,6 +62,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
}
}
#[repr(C)]
+#[derive(Copy)]
pub struct C {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -82,10 +83,14 @@ fn bindgen_test_layout_C() {
"Alignment of field: " , stringify ! ( C ) , "::" , stringify
! ( big_array ) ));
}
+impl Clone for C {
+ fn clone(&self) -> Self { *self }
+}
impl Default for C {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
+#[derive(Copy)]
pub struct C_with_zero_length_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -118,10 +123,14 @@ fn bindgen_test_layout_C_with_zero_length_array() {
C_with_zero_length_array ) , "::" , stringify ! (
zero_length_array ) ));
}
+impl Clone for C_with_zero_length_array {
+ fn clone(&self) -> Self { *self }
+}
impl Default for C_with_zero_length_array {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
+#[derive(Copy)]
pub struct C_with_incomplete_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -136,10 +145,14 @@ fn bindgen_test_layout_C_with_incomplete_array() {
concat ! (
"Alignment of " , stringify ! ( C_with_incomplete_array ) ));
}
+impl Clone for C_with_incomplete_array {
+ fn clone(&self) -> Self { *self }
+}
impl Default for C_with_incomplete_array {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
+#[derive(Copy)]
pub struct C_with_zero_length_array_and_incomplete_array {
pub a: ::std::os::raw::c_int,
pub big_array: [::std::os::raw::c_char; 33usize],
@@ -157,6 +170,9 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() {
"Alignment of " , stringify ! (
C_with_zero_length_array_and_incomplete_array ) ));
}
+impl Clone for C_with_zero_length_array_and_incomplete_array {
+ fn clone(&self) -> Self { *self }
+}
impl Default for C_with_zero_length_array_and_incomplete_array {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
@@ -178,6 +194,7 @@ fn bindgen_test_layout_WithDtor() {
stringify ! ( b ) ));
}
#[repr(C)]
+#[derive(Copy)]
pub struct IncompleteArrayNonCopiable {
pub whatever: *mut ::std::os::raw::c_void,
pub incomplete_array: __IncompleteArrayField<C>,
@@ -192,6 +209,9 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() {
"Alignment of " , stringify ! ( IncompleteArrayNonCopiable )
));
}
+impl Clone for IncompleteArrayNonCopiable {
+ fn clone(&self) -> Self { *self }
+}
impl Default for IncompleteArrayNonCopiable {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs
index cc32c3cc..a51e40bc 100644
--- a/tests/expectations/tests/layout_eth_conf.rs
+++ b/tests/expectations/tests/layout_eth_conf.rs
@@ -727,6 +727,7 @@ pub enum rte_eth_nb_pools {
/// A default pool may be used, if desired, to route all traffic which
/// does not match the vlan filter rules.
#[repr(C)]
+#[derive(Copy)]
pub struct rte_eth_vmdq_dcb_conf {
/// < With DCB, 16 or 32 pools
pub nb_queue_pools: rte_eth_nb_pools,
@@ -814,6 +815,9 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() {
"Alignment of field: " , stringify ! ( rte_eth_vmdq_dcb_conf )
, "::" , stringify ! ( dcb_tc ) ));
}
+impl Clone for rte_eth_vmdq_dcb_conf {
+ fn clone(&self) -> Self { *self }
+}
impl Default for rte_eth_vmdq_dcb_conf {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
@@ -941,6 +945,7 @@ impl Default for rte_eth_vmdq_tx_conf {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
+#[derive(Copy)]
pub struct rte_eth_vmdq_rx_conf {
/// < VMDq only mode, 8 or 64 pools
pub nb_queue_pools: rte_eth_nb_pools,
@@ -1036,6 +1041,9 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() {
"Alignment of field: " , stringify ! ( rte_eth_vmdq_rx_conf )
, "::" , stringify ! ( pool_map ) ));
}
+impl Clone for rte_eth_vmdq_rx_conf {
+ fn clone(&self) -> Self { *self }
+}
impl Default for rte_eth_vmdq_rx_conf {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
@@ -1458,6 +1466,7 @@ impl Clone for rte_intr_conf {
/// Depending upon the RX multi-queue mode, extra advanced
/// configuration settings may be needed.
#[repr(C)]
+#[derive(Copy)]
pub struct rte_eth_conf {
/// < bitmap of ETH_LINK_SPEED_XXX of speeds to be
/// used. ETH_LINK_SPEED_FIXED disables link
@@ -1490,6 +1499,7 @@ pub struct rte_eth_conf {
pub intr_conf: rte_intr_conf,
}
#[repr(C)]
+#[derive(Copy)]
pub struct rte_eth_conf__bindgen_ty_1 {
/// < Port RSS configuration
pub rss_conf: rte_eth_rss_conf,
@@ -1531,6 +1541,9 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() {
rte_eth_conf__bindgen_ty_1 ) , "::" , stringify ! (
vmdq_rx_conf ) ));
}
+impl Clone for rte_eth_conf__bindgen_ty_1 {
+ fn clone(&self) -> Self { *self }
+}
impl Default for rte_eth_conf__bindgen_ty_1 {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
@@ -1625,6 +1638,9 @@ fn bindgen_test_layout_rte_eth_conf() {
"Alignment of field: " , stringify ! ( rte_eth_conf ) , "::" ,
stringify ! ( intr_conf ) ));
}
+impl Clone for rte_eth_conf {
+ fn clone(&self) -> Self { *self }
+}
impl Default for rte_eth_conf {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs
index bbe78898..b2a77b27 100644
--- a/tests/expectations/tests/struct_with_derive_debug.rs
+++ b/tests/expectations/tests/struct_with_derive_debug.rs
@@ -25,6 +25,7 @@ impl Clone for LittleArray {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
+#[derive(Copy)]
pub struct BigArray {
pub a: [::std::os::raw::c_int; 33usize],
}
@@ -40,6 +41,9 @@ fn bindgen_test_layout_BigArray() {
"Alignment of field: " , stringify ! ( BigArray ) , "::" ,
stringify ! ( a ) ));
}
+impl Clone for BigArray {
+ fn clone(&self) -> Self { *self }
+}
impl Default for BigArray {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
@@ -64,6 +68,7 @@ impl Clone for WithLittleArray {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
+#[derive(Copy)]
pub struct WithBigArray {
pub a: BigArray,
}
@@ -79,6 +84,9 @@ fn bindgen_test_layout_WithBigArray() {
"Alignment of field: " , stringify ! ( WithBigArray ) , "::" ,
stringify ! ( a ) ));
}
+impl Clone for WithBigArray {
+ fn clone(&self) -> Self { *self }
+}
impl Default for WithBigArray {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs
new file mode 100644
index 00000000..0f2accba
--- /dev/null
+++ b/tests/expectations/tests/struct_with_large_array.rs
@@ -0,0 +1,37 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy)]
+pub struct S {
+ pub large_array: [::std::os::raw::c_char; 33usize],
+}
+#[test]
+fn bindgen_test_layout_S() {
+ assert_eq!(::std::mem::size_of::<S>() , 33usize , concat ! (
+ "Size of: " , stringify ! ( S ) ));
+ assert_eq! (::std::mem::align_of::<S>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( S ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const S ) ) . large_array as * const _ as usize
+ } , 0usize , concat ! (
+ "Alignment of field: " , stringify ! ( S ) , "::" , stringify
+ ! ( large_array ) ));
+}
+impl Clone for S {
+ fn clone(&self) -> Self { *self }
+}
+impl Default for S {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+#[repr(C)]
+pub struct ST<T> {
+ pub large_array: [T; 33usize],
+ pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
+}
+impl <T> Default for ST<T> {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
diff --git a/tests/headers/struct_with_large_array.hpp b/tests/headers/struct_with_large_array.hpp
new file mode 100644
index 00000000..fc67b333
--- /dev/null
+++ b/tests/headers/struct_with_large_array.hpp
@@ -0,0 +1,7 @@
+struct S {
+ char large_array[33];
+};
+
+template<typename T> struct ST {
+ T large_array[33];
+};