Skip to content
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: 1 addition & 1 deletion vortex-buffer/src/bit/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a, const NB: usize> BitView<'a, NB> {
/// If the length of the slice is not equal to `NB`.
pub fn from_slice(bits: &'a [u8]) -> Self {
assert_eq!(bits.len(), NB);
let bits_array = unsafe { &*(bits.as_ptr() as *const [u8; NB]) };
let bits_array = unsafe { &*(bits.as_ptr().cast::<[u8; NB]>()) };
BitView::new(bits_array)
}

Expand Down
6 changes: 3 additions & 3 deletions vortex-compute/src/take/slice/portable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn take_portable<T: NativePType, I: UnsignedPType>(buffer: &[T], indices: &[
// SAFETY: We know that f16 has the same bit pattern as u16, so this transmute is fine to
// make.
let u16_slice: &[u16] =
unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const u16, buffer.len()) };
unsafe { std::slice::from_raw_parts(buffer.as_ptr().cast(), buffer.len()) };
return unsafe { take_with_indices(u16_slice, indices).transmute::<T>() };
}

Expand All @@ -49,7 +49,7 @@ pub fn take_portable<T: NativePType, I: UnsignedPType>(buffer: &[T], indices: &[
// SAFETY: This is essentially a no-op that tricks the compiler into adding the
// `simd::SimdElement` bound we need to call `take_with_indices`.
let buffer: &[TC] =
unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const TC, buffer.len()) };
unsafe { std::slice::from_raw_parts(buffer.as_ptr().cast::<TC>(), buffer.len()) };
unsafe { take_with_indices(buffer, indices).transmute::<T>() }
})
}
Expand All @@ -64,7 +64,7 @@ fn take_with_indices<T: NativePType + simd::SimdElement, I: UnsignedPType>(
) -> Buffer<T> {
match_each_unsigned_integer_ptype!(I::PTYPE, |IC| {
let indices: &[IC] =
unsafe { std::slice::from_raw_parts(indices.as_ptr() as *const IC, indices.len()) };
unsafe { std::slice::from_raw_parts(indices.as_ptr().cast::<IC>(), indices.len()) };
take_portable_simd::<T, IC, SIMD_WIDTH>(buffer, indices)
})
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-dtype/src/ptype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ macro_rules! try_from_bytes {
fn to_le_bytes(&self) -> &[u8] {
// NOTE(ngates): this assumes the platform is little-endian. Currently enforced
// with a flag cfg(target_endian = "little")
let raw_ptr = self as *const $T as *const u8;
let raw_ptr = (self as *const $T).cast::<u8>();
unsafe { std::slice::from_raw_parts(raw_ptr, std::mem::size_of::<$T>()) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-duckdb/src/convert/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> DuckString<'a> {
unsafe {
let len = duckdb_string_t_length(*self.ptr);
let c_ptr = duckdb_string_t_data(self.ptr);
std::slice::from_raw_parts(c_ptr as *const u8, len as usize)
std::slice::from_raw_parts(c_ptr.cast::<u8>(), len as usize)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vortex-duckdb/src/duckdb/object_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl ObjectCacheRef<'_> {
cpp::duckdb_vx_object_cache_put(
self.as_ptr(),
key_cstr.as_ptr(),
opaque_ptr as *mut c_void,
opaque_ptr.cast(),
Some(rust_box_deleter::<T>),
);
}
Expand All @@ -55,7 +55,7 @@ impl ObjectCacheRef<'_> {
unsafe {
let opaque_ptr = cpp::duckdb_vx_object_cache_get(self.as_ptr(), key_cstr.as_ptr());
(!opaque_ptr.is_null())
.then_some((opaque_ptr as *const T).as_ref())
.then_some(opaque_ptr.cast::<T>().as_ref())
.flatten()
}
}
Expand Down
2 changes: 1 addition & 1 deletion vortex-duckdb/src/duckdb/table_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl TableFilter {

let name = unsafe {
str::from_utf8_unchecked(std::slice::from_raw_parts(
out.child_name as *const u8,
out.child_name.cast::<u8>(),
out.child_name_len,
))
};
Expand Down
2 changes: 1 addition & 1 deletion vortex-duckdb/src/duckdb/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Vector {
// Direct bit manipulation for better performance
let entry_idx = row / 64;
let idx_in_entry = row % 64;
let validity_u64_ptr = validity as *const u64;
let validity_u64_ptr = validity.cast_const();
let validity_entry = unsafe { *validity_u64_ptr.add(entry_idx as usize) };
let is_valid = (validity_entry & (1u64 << idx_in_entry)) != 0;

Expand Down
8 changes: 4 additions & 4 deletions vortex-ffi/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod tests {
fn test_string_new() {
unsafe {
let test_str = "hello world";
let ptr = test_str.as_ptr() as *const c_char;
let ptr = test_str.as_ptr().cast();
let len = test_str.len();

let vx_str = vx_binary_new(ptr, len);
Expand All @@ -66,7 +66,7 @@ mod tests {
let ptr = vx_binary_ptr(vx_str);
let len = vx_binary_len(vx_str);

let slice = slice::from_raw_parts(ptr as *const u8, len);
let slice = slice::from_raw_parts(ptr.cast::<u8>(), len);
assert_eq!(slice, "testing".as_bytes());

vx_binary_free(vx_str);
Expand All @@ -77,7 +77,7 @@ mod tests {
fn test_empty_string() {
unsafe {
let empty = "";
let ptr = empty.as_ptr() as *const c_char;
let ptr = empty.as_ptr().cast();
let vx_str = vx_binary_new(ptr, 0);

assert_eq!(vx_binary_len(vx_str), 0);
Expand All @@ -91,7 +91,7 @@ mod tests {
fn test_unicode_string() {
unsafe {
let unicode_str = "Hello 世界 🌍";
let ptr = unicode_str.as_ptr() as *const c_char;
let ptr = unicode_str.as_ptr().cast();
let len = unicode_str.len();

let vx_str = vx_binary_new(ptr, len);
Expand Down
4 changes: 2 additions & 2 deletions vortex-ffi/src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ mod tests {

let name_len = unsafe { vx_string_len(field_name_ptr) };
let name_ptr = unsafe { vx_string_ptr(field_name_ptr) };
let name_slice = unsafe { slice::from_raw_parts(name_ptr as *const u8, name_len) };
let name_slice = unsafe { slice::from_raw_parts(name_ptr.cast::<u8>(), name_len) };
let name_str = str::from_utf8(name_slice).unwrap();
assert_eq!(name_str, "nums");

Expand Down Expand Up @@ -689,7 +689,7 @@ mod tests {

let name_len = unsafe { vx_string_len(field_name_ptr) };
let name_ptr = unsafe { vx_string_ptr(field_name_ptr) };
let name_slice = unsafe { slice::from_raw_parts(name_ptr as *const u8, name_len) };
let name_slice = unsafe { slice::from_raw_parts(name_ptr.cast::<u8>(), name_len) };
let name_str = str::from_utf8(name_slice).unwrap();

let expected_name = if i == 0 { "nums" } else { "floats" };
Expand Down
2 changes: 1 addition & 1 deletion vortex-ffi/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn extract_expression(
) -> VortexResult<Option<Expression>> {
Ok((!expression.is_null() && expression_len > 0).then_some({
let bytes =
unsafe { slice::from_raw_parts(expression as *const u8, expression_len as usize) };
unsafe { slice::from_raw_parts(expression.cast::<u8>(), expression_len as usize) };

// Decode the protobuf message.
deserialize_expr_proto(&Expr::decode(bytes)?, registry)
Expand Down
8 changes: 4 additions & 4 deletions vortex-ffi/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod tests {
fn test_string_new() {
unsafe {
let test_str = "hello world";
let ptr = test_str.as_ptr() as *const c_char;
let ptr = test_str.as_ptr().cast();
let len = test_str.len();

let vx_str = vx_string_new(ptr, len);
Expand Down Expand Up @@ -103,7 +103,7 @@ mod tests {
let ptr = vx_string_ptr(vx_str);
let len = vx_string_len(vx_str);

let slice = slice::from_raw_parts(ptr as *const u8, len);
let slice = slice::from_raw_parts(ptr.cast::<u8>(), len);
let recovered = str::from_utf8_unchecked(slice);
assert_eq!(recovered, "testing");

Expand All @@ -115,7 +115,7 @@ mod tests {
fn test_empty_string() {
unsafe {
let empty = "";
let ptr = empty.as_ptr() as *const c_char;
let ptr = empty.as_ptr().cast();
let vx_str = vx_string_new(ptr, 0);

assert_eq!(vx_string_len(vx_str), 0);
Expand All @@ -129,7 +129,7 @@ mod tests {
fn test_unicode_string() {
unsafe {
let unicode_str = "Hello 世界 🌍";
let ptr = unicode_str.as_ptr() as *const c_char;
let ptr = unicode_str.as_ptr().cast();
let len = unicode_str.len();

let vx_str = vx_string_new(ptr, len);
Expand Down
4 changes: 2 additions & 2 deletions vortex-scalar/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Scalar {
.ok()
.flatten()
.map_or(0, |s| s.len()),
DType::Struct(_dtype, _) => self
DType::Struct(..) => self
.as_struct()
.fields()
.map(|fields| fields.into_iter().map(|f| f.nbytes()).sum::<usize>())
Expand All @@ -196,7 +196,7 @@ impl Scalar {
.elements()
.map(|fields| fields.into_iter().map(|f| f.nbytes()).sum::<usize>())
.unwrap_or_default(),
DType::Extension(_ext_dtype) => self.as_extension().storage().nbytes(),
DType::Extension(_) => self.as_extension().storage().nbytes(),
}
}

Expand Down
6 changes: 3 additions & 3 deletions vortex/benches/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,23 +680,23 @@ fn alp_decompress(encoded: &[i32], exponents: Exponents, output: &mut [f32]) {
/// This is safe because i32 and u32 have the same size and alignment.
fn cast_i32_as_u32(slice: &[i32]) -> &[u32] {
// SAFETY: i32 and u32 have the same size and alignment, so this transmute is safe.
unsafe { std::slice::from_raw_parts(slice.as_ptr() as *const u32, slice.len()) }
unsafe { std::slice::from_raw_parts(slice.as_ptr().cast(), slice.len()) }
}

/// Cast u32 slice to i32 slice.
///
/// This is safe because u32 and i32 have the same size and alignment.
fn cast_u32_as_i32(slice: &[u32]) -> &[i32] {
// SAFETY: i32 and u32 have the same size and alignment, so this transmute is safe.
unsafe { std::slice::from_raw_parts(slice.as_ptr() as *const i32, slice.len()) }
unsafe { std::slice::from_raw_parts(slice.as_ptr().cast(), slice.len()) }
}

/// Cast mutable u32 slice to mutable i32 slice.
///
/// This is safe because u32 and i32 have the same size and alignment.
fn cast_u32_as_i32_mut(slice: &mut [u32]) -> &mut [i32] {
// SAFETY: i32 and u32 have the same size and alignment, so this transmute is safe.
unsafe { std::slice::from_raw_parts_mut(slice.as_mut_ptr() as *mut i32, slice.len()) }
unsafe { std::slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), slice.len()) }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading