Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in BufferContents derive expansion and wrong safety docs #2587

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
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