Skip to content

Commit

Permalink
Fix panic in BufferContents derive expansion and wrong safety docs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Oct 22, 2024
1 parent 82acabc commit ba278ac
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
2 changes: 0 additions & 2 deletions vulkano-macros/src/derive_buffer_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ pub fn derive_buffer_contents(crate_ident: &Ident, mut ast: DeriveInput) -> Resu
};

ptr_from_slice = quote! {
debug_assert_eq!(slice.len(), ::std::mem::size_of::<Self>());

<*mut [u8]>::cast::<Self>(slice.as_ptr())
};
}
Expand Down
6 changes: 1 addition & 5 deletions vulkano/src/buffer/subbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,7 @@ pub unsafe trait BufferContents: Send + Sync + 'static {
///
/// # Safety
///
/// - If `Self` is sized, then `slice.len()` must match the size exactly.
/// - If `Self` is unsized, then `slice.len()` minus the size of the head (sized part) of the
/// DST must be evenly divisible by the size of the element type.
/// - `slice` must be a pointer that's valid for reads and writes of the entire slice.
#[doc(hidden)]
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self;
}
Expand All @@ -854,8 +852,6 @@ where

#[inline(always)]
unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self {
debug_assert_eq!(slice.len(), size_of::<T>());

<*mut [u8]>::cast::<T>(slice.as_ptr())
}
}
Expand Down
4 changes: 1 addition & 3 deletions vulkano/src/padded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
cmp::Ordering,
fmt::{Debug, Display, Formatter, Result as FmtResult},
hash::{Hash, Hasher},
mem::{size_of, MaybeUninit},
mem::MaybeUninit,
ops::{Deref, DerefMut},
ptr::NonNull,
};
Expand Down Expand Up @@ -290,8 +290,6 @@ where
const LAYOUT: BufferContentsLayout = BufferContentsLayout::from_sized(Layout::new::<Self>());

unsafe fn ptr_from_slice(slice: NonNull<[u8]>) -> *mut Self {
debug_assert_eq!(slice.len(), size_of::<Padded<T, N>>());

<*mut [u8]>::cast::<Padded<T, N>>(slice.as_ptr())
}
}
Expand Down

0 comments on commit ba278ac

Please sign in to comment.