Skip to content

Commit

Permalink
Not derive Copy for C flexible array member
Browse files Browse the repository at this point in the history
  • Loading branch information
WiSaGaN committed Aug 1, 2017
1 parent cc938cb commit 06b3893
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ impl<'a> CanDeriveCopy<'a> for Type {

fn can_derive_copy(&self, ctx: &BindgenContext, item: &Item) -> bool {
match self.kind {
TypeKind::Array(t, _) => {
TypeKind::Array(t, len) => {
len > 0 &&
t.can_derive_copy_in_array(ctx, ())
}
TypeKind::ResolvedTypeRef(t) |
Expand Down
16 changes: 0 additions & 16 deletions tests/expectations/tests/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ 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],
Expand Down Expand Up @@ -123,14 +122,10 @@ 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],
Expand All @@ -145,14 +140,10 @@ 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],
Expand All @@ -170,9 +161,6 @@ 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() } }
}
Expand All @@ -194,7 +182,6 @@ 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>,
Expand All @@ -209,9 +196,6 @@ 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() } }
}
Expand Down
5 changes: 1 addition & 4 deletions tests/expectations/tests/issue-643-inner-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
}
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
#[repr(C)]
#[derive(Debug, Copy)]
#[derive(Debug)]
pub struct rte_ring {
pub memzone: *mut rte_memzone,
pub prod: rte_ring_prod,
Expand Down Expand Up @@ -92,9 +92,6 @@ fn bindgen_test_layout_rte_ring() {
assert_eq! (::std::mem::align_of::<rte_ring>() , 8usize , concat ! (
"Alignment of " , stringify ! ( rte_ring ) ));
}
impl Clone for rte_ring {
fn clone(&self) -> Self { *self }
}
impl Default for rte_ring {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
Expand Down
5 changes: 1 addition & 4 deletions tests/expectations/tests/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
}
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
#[repr(C, packed)]
#[derive(Debug, Default, Copy)]
#[derive(Debug, Default)]
pub struct header {
pub proto: ::std::os::raw::c_char,
pub size: ::std::os::raw::c_uint,
Expand All @@ -50,6 +50,3 @@ fn bindgen_test_layout_header() {
assert_eq!(::std::mem::size_of::<header>() , 16usize , concat ! (
"Size of: " , stringify ! ( header ) ));
}
impl Clone for header {
fn clone(&self) -> Self { *self }
}
5 changes: 1 addition & 4 deletions tests/expectations/tests/layout_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
}
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
#[repr(C)]
#[derive(Debug, Copy)]
#[derive(Debug)]
pub struct rte_kni_fifo {
/// < Next position to be written
pub write: ::std::os::raw::c_uint,
Expand All @@ -59,9 +59,6 @@ fn bindgen_test_layout_rte_kni_fifo() {
assert_eq! (::std::mem::align_of::<rte_kni_fifo>() , 8usize , concat ! (
"Alignment of " , stringify ! ( rte_kni_fifo ) ));
}
impl Clone for rte_kni_fifo {
fn clone(&self) -> Self { *self }
}
impl Default for rte_kni_fifo {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/layout_large_align_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ impl Default for ip_frag_tbl_stat {
}
/// fragmentation table
#[repr(C)]
#[derive(Copy)]
pub struct rte_ip_frag_tbl {
/// < ttl for table entries.
pub max_cycles: u64,
Expand Down Expand Up @@ -403,9 +402,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() {
"Alignment of field: " , stringify ! ( rte_ip_frag_tbl ) ,
"::" , stringify ! ( pkt ) ));
}
impl Clone for rte_ip_frag_tbl {
fn clone(&self) -> Self { *self }
}
impl Default for rte_ip_frag_tbl {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
Expand Down
4 changes: 0 additions & 4 deletions tests/expectations/tests/layout_mbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ impl Clone for rte_atomic16_t {
}
/// The generic rte_mbuf, containing a packet mbuf.
#[repr(C)]
#[derive(Copy)]
pub struct rte_mbuf {
pub cacheline0: MARKER,
/// < Virtual address of segment buffer.
Expand Down Expand Up @@ -1078,9 +1077,6 @@ fn bindgen_test_layout_rte_mbuf() {
"Alignment of field: " , stringify ! ( rte_mbuf ) , "::" ,
stringify ! ( timesync ) ));
}
impl Clone for rte_mbuf {
fn clone(&self) -> Self { *self }
}
impl Default for rte_mbuf {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
Expand Down

0 comments on commit 06b3893

Please sign in to comment.