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

Replace as *... raw pointer-type changes with more explicit .cast() #685

Merged
merged 1 commit into from Nov 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions ash-window/src/lib.rs
Expand Up @@ -51,7 +51,7 @@ pub unsafe fn create_surface(

(RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => {
let surface_desc = vk::XlibSurfaceCreateInfoKHR::default()
.dpy(display.display as *mut _)
.dpy(display.display.cast())
.window(window.window);
let surface_fn = khr::XlibSurface::new(entry, instance);
surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks)
Expand All @@ -77,7 +77,7 @@ pub unsafe fn create_surface(
use raw_window_metal::{appkit, Layer};

let layer = match appkit::metal_layer_from_handle(window) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(),
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};

Expand All @@ -91,7 +91,7 @@ pub unsafe fn create_surface(
use raw_window_metal::{uikit, Layer};

let layer = match uikit::metal_layer_from_handle(window) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(),
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};

Expand Down
2 changes: 1 addition & 1 deletion ash/src/device.rs
Expand Up @@ -2026,7 +2026,7 @@ impl Device {
first_query,
data.len() as u32,
data_size,
data.as_mut_ptr() as *mut _,
data.as_mut_ptr().cast(),
mem::size_of::<T>() as _,
flags,
)
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/khr/acceleration_structure.rs
Expand Up @@ -200,7 +200,7 @@ impl AccelerationStructure {
acceleration_structures.as_ptr(),
query_type,
data.len(),
data.as_mut_ptr() as *mut std::ffi::c_void,
data.as_mut_ptr().cast(),
stride,
)
.result()
Expand Down
4 changes: 2 additions & 2 deletions ash/src/extensions/nv/ray_tracing.rs
Expand Up @@ -206,7 +206,7 @@ impl RayTracing {
first_group,
group_count,
data.len(),
data.as_mut_ptr() as *mut std::ffi::c_void,
data.as_mut_ptr().cast(),
)
.result()
}
Expand All @@ -223,7 +223,7 @@ impl RayTracing {
self.handle,
accel_struct,
std::mem::size_of::<u64>(),
handle_ptr as *mut std::ffi::c_void,
handle_ptr.cast(),
)
.result_with_success(handle)
}
Expand Down
10 changes: 7 additions & 3 deletions ash/src/util.rs
Expand Up @@ -31,7 +31,7 @@ impl<T: Copy> Align<T> {
use std::slice::from_raw_parts_mut;
if self.elem_size == size_of::<T>() as u64 {
unsafe {
let mapped_slice = from_raw_parts_mut(self.ptr as *mut T, slice.len());
let mapped_slice = from_raw_parts_mut(self.ptr.cast(), slice.len());
mapped_slice.copy_from_slice(slice);
}
} else {
Expand Down Expand Up @@ -75,7 +75,9 @@ impl<'a, T: Copy + 'a> Iterator for AlignIter<'a, T> {
}
unsafe {
// Need to cast to *mut u8 because () has size 0
let ptr = (self.align.ptr as *mut u8).offset(self.current as isize) as *mut T;
let ptr = (self.align.ptr.cast::<u8>())
.offset(self.current as isize)
.cast();
self.current += self.align.elem_size;
Some(&mut *ptr)
}
Expand Down Expand Up @@ -118,7 +120,9 @@ pub fn read_spv<R: io::Read + io::Seek>(x: &mut R) -> io::Result<Vec<u32>> {
// reading uninitialized memory.
let mut result = vec![0u32; words];
x.seek(io::SeekFrom::Start(0))?;
x.read_exact(unsafe { slice::from_raw_parts_mut(result.as_mut_ptr() as *mut u8, words * 4) })?;
x.read_exact(unsafe {
slice::from_raw_parts_mut(result.as_mut_ptr().cast::<u8>(), words * 4)
})?;
const MAGIC_NUMBER: u32 = 0x0723_0203;
if !result.is_empty() && result[0] == MAGIC_NUMBER.swap_bytes() {
for word in &mut result {
Expand Down
18 changes: 9 additions & 9 deletions ash/src/vk/definitions.rs
Expand Up @@ -3440,7 +3440,7 @@ impl<'a> SpecializationInfo<'a> {
#[inline]
pub fn data(mut self, data: &'a [u8]) -> Self {
self.data_size = data.len();
self.p_data = data.as_ptr() as *const c_void;
self.p_data = data.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -4657,7 +4657,7 @@ impl<'a> PipelineCacheCreateInfo<'a> {
#[inline]
pub fn initial_data(mut self, initial_data: &'a [u8]) -> Self {
self.initial_data_size = initial_data.len();
self.p_initial_data = initial_data.as_ptr() as *const c_void;
self.p_initial_data = initial_data.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -8796,7 +8796,7 @@ impl<'a> DebugMarkerObjectTagInfoEXT<'a> {
#[inline]
pub fn tag(mut self, tag: &'a [u8]) -> Self {
self.tag_size = tag.len();
self.p_tag = tag.as_ptr() as *const c_void;
self.p_tag = tag.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -16659,7 +16659,7 @@ impl<'a> WriteDescriptorSetInlineUniformBlock<'a> {
#[inline]
pub fn data(mut self, data: &'a [u8]) -> Self {
self.data_size = data.len() as _;
self.p_data = data.as_ptr() as *const c_void;
self.p_data = data.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -16839,7 +16839,7 @@ impl<'a> ValidationCacheCreateInfoEXT<'a> {
#[inline]
pub fn initial_data(mut self, initial_data: &'a [u8]) -> Self {
self.initial_data_size = initial_data.len();
self.p_initial_data = initial_data.as_ptr() as *const c_void;
self.p_initial_data = initial_data.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -17775,7 +17775,7 @@ impl<'a> DebugUtilsObjectTagInfoEXT<'a> {
#[inline]
pub fn tag(mut self, tag: &'a [u8]) -> Self {
self.tag_size = tag.len();
self.p_tag = tag.as_ptr() as *const c_void;
self.p_tag = tag.as_ptr().cast();
self
}
}
Expand Down Expand Up @@ -27527,7 +27527,7 @@ impl<'a> PipelineExecutableInternalRepresentationKHR<'a> {
#[inline]
pub fn data(mut self, data: &'a mut [u8]) -> Self {
self.data_size = data.len();
self.p_data = data.as_mut_ptr() as *mut c_void;
self.p_data = data.as_mut_ptr().cast();
self
}
}
Expand Down Expand Up @@ -30960,7 +30960,7 @@ impl<'a> AccelerationStructureBuildGeometryInfoKHR<'a> {
geometries_ptrs: &'a [&'a AccelerationStructureGeometryKHR],
) -> Self {
self.geometry_count = geometries_ptrs.len() as _;
self.pp_geometries = geometries_ptrs.as_ptr() as *const *const _;
self.pp_geometries = geometries_ptrs.as_ptr().cast();
self
}
#[inline]
Expand Down Expand Up @@ -38723,7 +38723,7 @@ impl<'a> CuModuleCreateInfoNVX<'a> {
#[inline]
pub fn data(mut self, data: &'a [u8]) -> Self {
self.data_size = data.len();
self.p_data = data.as_ptr() as *const c_void;
self.p_data = data.as_ptr().cast();
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lib.rs
Expand Up @@ -34,7 +34,7 @@ macro_rules! offset_of {
#[allow(unused_unsafe)]
unsafe {
let b: $base = mem::zeroed();
(&b.$field as *const _ as isize) - (&b as *const _ as isize)
std::ptr::addr_of!(b.$field) as isize - std::ptr::addr_of!(b) as isize
}
}};
}
Expand Down
6 changes: 2 additions & 4 deletions generator/src/lib.rs
Expand Up @@ -1720,10 +1720,8 @@ pub fn derive_setters(

// Interpret void array as byte array
if field.basetype == "void" && matches!(field.reference, Some(vkxml::ReferenceType::Pointer)) {
let mutable = if field.is_const { quote!(const) } else { quote!(mut) };

slice_param_ty_tokens = quote!([u8]);
ptr = quote!(#ptr as *#mutable c_void);
ptr = quote!(#ptr.cast());
};

let set_size_stmt = if field.is_pointer_to_static_sized_array() {
Expand All @@ -1741,7 +1739,7 @@ pub fn derive_setters(
let array_size = if let Some(array_size) = array_size.strip_suffix(",1") {
param_ident_short = format_ident!("{}_ptrs", param_ident_short);
slice_param_ty_tokens = field.safe_type_tokens(quote!('a), Some(1));
ptr = quote!(#ptr as *const *const _);
ptr = quote!(#ptr.cast());
array_size
} else {
array_size
Expand Down