1
0
Fork 0
forked from wry/wry

all: remove unnecessary mem:: prefix

This commit is contained in:
Julian Orth 2024-10-12 14:49:37 +02:00
parent c00ef63afe
commit 1e45a243de
22 changed files with 61 additions and 76 deletions

View file

@ -1,8 +1,6 @@
#![allow(dead_code)]
use std::mem;
const SEG_SIZE: usize = 8 * mem::size_of::<usize>();
const SEG_SIZE: usize = usize::BITS as usize;
#[derive(Default)]
pub struct Bitfield {

View file

@ -313,7 +313,7 @@ pub struct TypedBuf<T: Pod> {
impl<T: Pod> TypedBuf<T> {
pub fn new() -> Self {
Self {
buf: Buf::new(mem::size_of::<T>()),
buf: Buf::new(size_of::<T>()),
_phantom: Default::default(),
}
}

View file

@ -101,7 +101,7 @@ impl<'a> MsgFormatter<'a> {
}
pub fn binary<T: ?Sized + Packed>(&mut self, t: &T) -> &mut Self {
self.uint(mem::size_of_val(t) as u32);
self.uint(size_of_val(t) as u32);
self.write(uapi::as_bytes(t));
let none = [0; 4];
self.write(&none[..self.meta.write_pos.wrapping_neg() & 3]);

View file

@ -1,7 +1,7 @@
use {
crate::{fixed::Fixed, globals::GlobalName, object::ObjectId, utils::buffd::BufFdIn},
bstr::{BStr, ByteSlice},
std::{mem, ptr, rc::Rc},
std::{ptr, rc::Rc},
thiserror::Error,
uapi::{OwnedFd, Pod},
};
@ -122,30 +122,30 @@ impl<'a, 'b> MsgParser<'a, 'b> {
pub fn binary<T: Pod>(&mut self) -> Result<T, MsgParserError> {
let array = self.array()?;
if array.len() < mem::size_of::<T>() {
if array.len() < size_of::<T>() {
return Err(MsgParserError::UnexpectedEof);
}
if array.len() > mem::size_of::<T>() {
if array.len() > size_of::<T>() {
return Err(MsgParserError::BinaryArrayTooLarge);
}
unsafe { Ok(ptr::read_unaligned(array.as_ptr() as _)) }
}
pub fn binary_array<T: Pod>(&mut self) -> Result<&'b [T], MsgParserError> {
if std::mem::align_of::<T>() > 4 {
if align_of::<T>() > 4 {
panic!("Alignment of binary array element is too large");
};
if std::mem::size_of::<T>() == 0 {
if size_of::<T>() == 0 {
panic!("Size of binary array element is 0");
};
let array = self.array()?;
if array.len() % mem::size_of::<T>() != 0 {
if array.len() % size_of::<T>() != 0 {
return Err(MsgParserError::BinaryArraySize);
}
unsafe {
Ok(std::slice::from_raw_parts(
array.as_ptr() as _,
array.len() / mem::size_of::<T>(),
array.len() / size_of::<T>(),
))
}
}

View file

@ -1,6 +1,5 @@
use {
crate::forker::ForkerError,
std::mem,
uapi::{c, OwnedFd},
};
@ -41,7 +40,7 @@ pub fn fork_with_pidfd(pidfd_for_child: bool) -> Result<Forked, ForkerError> {
let pid = c::syscall(
c::SYS_clone3,
&mut args as *const _ as usize,
mem::size_of::<clone_args>(),
size_of::<clone_args>(),
);
if let Err(e) = uapi::map_err!(pid) {
return Err(ForkerError::Fork(e.into()));