Added compile time struct size checks

rust_native
ko1N 5 years ago
parent be09dc2d6e
commit 522414f956

@ -12,8 +12,10 @@ readme = "README.md"
crate-type = ["lib", "cdylib"] crate-type = ["lib", "cdylib"]
[dependencies] [dependencies]
memflow-core = { path = "../memflow/memflow-core", features = ["plugins"] } memflow-core = { git = "ssh://git@github.com/memflow/memflow.git", branch = "dev", features = ["plugins"] }
memflow-derive = { path = "../memflow/memflow-derive" } memflow-derive = { git = "ssh://git@github.com/memflow/memflow.git", branch = "dev" }
#memflow-core = { path = "../memflow/memflow-core", features = ["plugins"] }
#memflow-derive = { path = "../memflow/memflow-derive" }
log = { version = "0.4.8", default-features = false } log = { version = "0.4.8", default-features = false }
rusb = "0.6.0" rusb = "0.6.0"
dataview = "0.1" dataview = "0.1"

@ -1,7 +1,7 @@
use crate::ft60x::*; use crate::ft60x::*;
use std::mem::MaybeUninit; use core::mem::MaybeUninit;
use std::time::Duration; use core::time::Duration;
use log::{info, trace, warn}; use log::{info, trace, warn};
@ -40,6 +40,7 @@ bitfield! {
pl_downstream_deemph_source, _: 8; pl_downstream_deemph_source, _: 8;
//_, _: 16, 9; //_, _: 16, 9;
} }
const _: [(); core::mem::size_of::<PhyConfigWr>()] = [(); 2];
bitfield! { bitfield! {
pub struct PhyConfigRd(u32); pub struct PhyConfigRd(u32);
@ -59,6 +60,7 @@ bitfield! {
pl_received_hot_rst, _: 24; pl_received_hot_rst, _: 24;
//_, _: 31, 25; //_, _: 31, 25;
} }
const _: [(); core::mem::size_of::<PhyConfigRd>()] = [(); 4];
pub struct Device { pub struct Device {
ft60: FT60x, ft60: FT60x,
@ -320,7 +322,7 @@ impl Device {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::mem::size_of; use core::mem::size_of;
#[test] #[test]
fn test_struct_sizes() { fn test_struct_sizes() {

@ -7,8 +7,8 @@ use rusb::{
request_type, DeviceHandle, DeviceList, Direction, GlobalContext, Recipient, RequestType, request_type, DeviceHandle, DeviceList, Direction, GlobalContext, Recipient, RequestType,
}; };
use std::mem::size_of; use core::mem::size_of;
use std::time::Duration; use core::time::Duration;
use log::{info, trace}; use log::{info, trace};

@ -68,6 +68,7 @@ pub struct Config {
pub msio_control: u32, pub msio_control: u32,
pub gpio_control: u32, pub gpio_control: u32,
} }
const _: [(); core::mem::size_of::<Config>()] = [(); 0x98];
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone, Pod)] #[derive(Copy, Clone, Pod)]
@ -81,6 +82,7 @@ pub struct ControlRequest {
unknown3: u32, unknown3: u32,
unknown4: u32, unknown4: u32,
} }
const _: [(); core::mem::size_of::<ControlRequest>()] = [(); 0x14];
impl ControlRequest { impl ControlRequest {
pub fn new(idx: u32, pipe: u8, cmd: u8, len: u32) -> Self { pub fn new(idx: u32, pipe: u8, cmd: u8, len: u32) -> Self {
@ -100,7 +102,7 @@ impl ControlRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::mem::size_of; use core::mem::size_of;
#[test] #[test]
fn test_struct_sizes() { fn test_struct_sizes() {

Loading…
Cancel
Save