Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions zerocopy-derive/tests/struct_no_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,31 @@ where
T: 'a + 'b + imp::Immutable;

util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::Immutable);

// Regression test for #2445: Fuchsia has `repr(C)` packet types with a large
// computed array field, and they should still be `Immutable`.
const FX_LOG_MAX_DATAGRAM_LEN: usize = 2032;

#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct FxLogMetadata {
pid: u64,
tid: u64,
time: i64,
severity: i32,
dropped_logs: u32,
}

const FX_LOG_METADATA_SIZE: usize = imp::core::mem::size_of::<FxLogMetadata>();

#[derive(imp::Immutable)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct FxLogPacket {
metadata: FxLogMetadata,
data: [u8; FX_LOG_MAX_DATAGRAM_LEN - FX_LOG_METADATA_SIZE],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make FX_LOG_METADATA_SIZE size_of::<FxLogMetadata>() instead of hard-coding its size?

}

util_assert_impl_all!(FxLogMetadata: imp::Immutable);
util_assert_impl_all!(FxLogPacket: imp::Immutable);
28 changes: 28 additions & 0 deletions zerocopy-derive/tests/struct_to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,31 @@ pub struct IndexEntry<const SIZE_BLOCK_ID: usize> {

util_assert_impl_all!(IndexEntry<0>: imp::IntoBytes);
util_assert_impl_all!(IndexEntry<1>: imp::IntoBytes);

// Regression test for #2445: Fuchsia has `repr(C)` packet types with a large
// computed array field, and they should still be serializable with zerocopy.
const FX_LOG_MAX_DATAGRAM_LEN: usize = 2032;

#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct FxLogMetadata {
pid: u64,
tid: u64,
time: i64,
severity: i32,
dropped_logs: u32,
}

const FX_LOG_METADATA_SIZE: usize = imp::core::mem::size_of::<FxLogMetadata>();

#[derive(imp::IntoBytes)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct FxLogPacket {
metadata: FxLogMetadata,
data: [u8; FX_LOG_MAX_DATAGRAM_LEN - FX_LOG_METADATA_SIZE],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re: size_of.

}

util_assert_impl_all!(FxLogMetadata: imp::IntoBytes);
util_assert_impl_all!(FxLogPacket: imp::IntoBytes);
Loading