Skip to content

Commit

Permalink
update zerocopy to 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiwa4 committed Nov 3, 2024
1 parent 2cc1e8c commit ee472e2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ required-features = ["alloc"]
ascii = { version = "1.1.0", default-features = false }
deforest_derive = { path = "deforest_derive", version = "=0.3.0", optional = true }
fallible-iterator = { version = "0.3.0", default-features = false }
zerocopy = { version = "0.7.31", default-features = false, features = ["derive"] }
zerocopy = { version = "0.8.7", features = ["derive"] }

[features]
alloc = ["fallible-iterator/alloc"]
Expand Down
8 changes: 4 additions & 4 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use core::{
#[cfg(feature = "alloc")]
use std_alloc::{borrow::ToOwned, boxed::Box, vec::Vec};

use zerocopy::{AsBytes, FromBytes, FromZeroes, Ref};
use zerocopy::{FromBytes, IntoBytes, Ref};

use crate::{
BlobError, DeserializeNode, DeserializeProperty, MemReserveEntries, NodeContext, Path,
Expand All @@ -37,7 +37,7 @@ pub const DTB_MAGIC: [u8; 4] = 0xd00d_feed_u32.to_be_bytes();
pub(crate) const LAST_COMPATIBLE_VERSION: u32 = 0x10;
const STRUCT_BLOCK_OPTIMAL_ALIGN: usize = 4;

#[derive(AsBytes)]
#[derive(IntoBytes)]
#[repr(C)]
pub(crate) struct Header {
pub magic: [u8; 4],
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Devicetree {
/// The blob data as a `u32` slice.
#[inline]
pub fn blob_u32(&self) -> &[u32] {
Ref::new_slice(self.blob_u8()).unwrap().into_slice()
Ref::into_ref(Ref::from_bytes(self.blob_u8()).unwrap())
}

/// The blob data as a `u64` slice.
Expand Down Expand Up @@ -575,7 +575,7 @@ impl<'dtb> Item<'dtb> {
}
}

#[derive(AsBytes, FromBytes, FromZeroes)]
#[derive(FromBytes, IntoBytes)]
#[repr(C)]
pub(crate) struct RawReserveEntry {
pub address: u64,
Expand Down
8 changes: 4 additions & 4 deletions src/blob/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
mem::size_of,
};

use zerocopy::{FromBytes, FromZeroes};
use zerocopy::FromBytes;

use super::{BlobError, Devicetree, DtUint, Item, Node, Property, Result};
use crate::util;
Expand Down Expand Up @@ -119,7 +119,7 @@ impl Devicetree {

/// Returns the token pointed to by the cursor and advance the cursor.
pub fn next_token(&self, cursor: &mut Cursor) -> Result<Option<Token<'_>>> {
#[derive(FromBytes, FromZeroes)]
#[derive(FromBytes)]
#[repr(C)]
struct PropHeader {
len: u32,
Expand Down Expand Up @@ -152,8 +152,8 @@ impl Devicetree {
Token::EndNode
}
RawToken::Prop => {
let header = PropHeader::read_from_prefix(&blob[offset..])
.ok_or(BlobError::UnexpectedEnd)?;
let (header, _) = PropHeader::read_from_prefix(&blob[offset..])
.map_err(|_| BlobError::UnexpectedEnd)?;

let name_blob = usize::try_from(u32::from_be(header.nameoff))
.ok()
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use ascii::AsciiStr;
pub use deforest_derive::*;
pub use fallible_iterator;
use fallible_iterator::FallibleIterator;
use zerocopy::{AsBytes, FromBytes, Ref};
use zerocopy::{FromBytes, IntoBytes, Ref};

use blob::{Cursor, Item, Node, Property};

Expand Down Expand Up @@ -207,8 +207,8 @@ impl<'dtb> FallibleIterator for MemReserveEntries<'dtb> {
type Error = Error;

fn next(&mut self) -> Result<Option<Self::Item>, Self::Error> {
let raw = blob::RawReserveEntry::read_from_prefix(self.blob.as_bytes())
.ok_or(BlobError::UnexpectedEnd)?;
let (raw, _) = blob::RawReserveEntry::read_from_prefix(self.blob.as_bytes())
.map_err(|_| BlobError::UnexpectedEnd)?;
self.blob = &self.blob[blob::RawReserveEntry::FIELD_COUNT..];

let entry = (raw.address != 0 || raw.size != 0).then(|| MemReserveEntry {
Expand Down Expand Up @@ -345,9 +345,9 @@ impl<'dtb> DeserializeProperty<'dtb> for &'dtb [u8] {
impl<'dtb> DeserializeProperty<'dtb> for &'dtb [u32] {
/// Gives a devicetree property value as a big-endian u32 slice.
fn deserialize(blob_prop: Property<'dtb>, _cx: NodeContext<'_>) -> Result<Self> {
match Ref::new_slice(blob_prop.value()) {
Some(val) => Ok(val.into_slice()),
None => Err(Error::UnsuitableProperty),
match Ref::from_bytes(blob_prop.value()) {
Ok(val) => Ok(Ref::into_ref(val)),
Err(_) => Err(Error::UnsuitableProperty),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use deforest::{
prop_value::{self, RegBlock},
BlobError, DeserializeProperty, Error, NodeContext,
};
use zerocopy::{AsBytes, FromBytes, FromZeroes};
use zerocopy::{FromBytes, IntoBytes, KnownLayout};

const UNALIGNED_BLOB: &[u8] = include_bytes!("tree.dtb");
const FORMATTED: &str = include_str!("formatted.txt");
Expand All @@ -34,7 +34,7 @@ right: {right}"
);
}

#[derive(AsBytes, FromBytes, FromZeroes)]
#[derive(FromBytes, IntoBytes, KnownLayout)]
#[repr(C)]
struct Header {
magic: u32,
Expand Down Expand Up @@ -255,7 +255,7 @@ macro_rules! blob {
header: { $($field:ident: $val:expr),* $(,)? } $(,)?
} => {{
let mut buf = $buf_init;
let header = Header::mut_from_prefix(buf.as_bytes_mut()).unwrap();
let (header, _) = Header::mut_from_prefix(buf.as_mut_bytes()).unwrap();
*header = Header { $($field: { let v: u32 = $val; v.to_be() },)* ..Header::EMPTY };
buf
}};
Expand Down

0 comments on commit ee472e2

Please sign in to comment.