Skip to content

Commit ea528d2

Browse files
committed
chore: Small stylistic fixes to pointer casting
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent bc83712 commit ea528d2

File tree

13 files changed

+26
-26
lines changed

13 files changed

+26
-26
lines changed

vortex-buffer/src/bit/view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, const NB: usize> BitView<'a, NB> {
107107
/// If the length of the slice is not equal to `NB`.
108108
pub fn from_slice(bits: &'a [u8]) -> Self {
109109
assert_eq!(bits.len(), NB);
110-
let bits_array = unsafe { &*(bits.as_ptr() as *const [u8; NB]) };
110+
let bits_array = unsafe { &*(bits.as_ptr().cast::<[u8; NB]>()) };
111111
BitView::new(bits_array)
112112
}
113113

vortex-compute/src/take/slice/portable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn take_portable<T: NativePType, I: UnsignedPType>(buffer: &[T], indices: &[
3939
// SAFETY: We know that f16 has the same bit pattern as u16, so this transmute is fine to
4040
// make.
4141
let u16_slice: &[u16] =
42-
unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const u16, buffer.len()) };
42+
unsafe { std::slice::from_raw_parts(buffer.as_ptr().cast(), buffer.len()) };
4343
return unsafe { take_with_indices(u16_slice, indices).transmute::<T>() };
4444
}
4545

@@ -49,7 +49,7 @@ pub fn take_portable<T: NativePType, I: UnsignedPType>(buffer: &[T], indices: &[
4949
// SAFETY: This is essentially a no-op that tricks the compiler into adding the
5050
// `simd::SimdElement` bound we need to call `take_with_indices`.
5151
let buffer: &[TC] =
52-
unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const TC, buffer.len()) };
52+
unsafe { std::slice::from_raw_parts(buffer.as_ptr().cast::<TC>(), buffer.len()) };
5353
unsafe { take_with_indices(buffer, indices).transmute::<T>() }
5454
})
5555
}
@@ -64,7 +64,7 @@ fn take_with_indices<T: NativePType + simd::SimdElement, I: UnsignedPType>(
6464
) -> Buffer<T> {
6565
match_each_unsigned_integer_ptype!(I::PTYPE, |IC| {
6666
let indices: &[IC] =
67-
unsafe { std::slice::from_raw_parts(indices.as_ptr() as *const IC, indices.len()) };
67+
unsafe { std::slice::from_raw_parts(indices.as_ptr().cast::<IC>(), indices.len()) };
6868
take_portable_simd::<T, IC, SIMD_WIDTH>(buffer, indices)
6969
})
7070
}

vortex-dtype/src/ptype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ macro_rules! try_from_bytes {
895895
fn to_le_bytes(&self) -> &[u8] {
896896
// NOTE(ngates): this assumes the platform is little-endian. Currently enforced
897897
// with a flag cfg(target_endian = "little")
898-
let raw_ptr = self as *const $T as *const u8;
898+
let raw_ptr = (self as *const $T).cast::<u8>();
899899
unsafe { std::slice::from_raw_parts(raw_ptr, std::mem::size_of::<$T>()) }
900900
}
901901
}

vortex-duckdb/src/convert/vector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a> DuckString<'a> {
6262
unsafe {
6363
let len = duckdb_string_t_length(*self.ptr);
6464
let c_ptr = duckdb_string_t_data(self.ptr);
65-
std::slice::from_raw_parts(c_ptr as *const u8, len as usize)
65+
std::slice::from_raw_parts(c_ptr.cast::<u8>(), len as usize)
6666
}
6767
}
6868
}

vortex-duckdb/src/duckdb/object_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ObjectCacheRef<'_> {
3838
cpp::duckdb_vx_object_cache_put(
3939
self.as_ptr(),
4040
key_cstr.as_ptr(),
41-
opaque_ptr as *mut c_void,
41+
opaque_ptr.cast(),
4242
Some(rust_box_deleter::<T>),
4343
);
4444
}
@@ -55,7 +55,7 @@ impl ObjectCacheRef<'_> {
5555
unsafe {
5656
let opaque_ptr = cpp::duckdb_vx_object_cache_get(self.as_ptr(), key_cstr.as_ptr());
5757
(!opaque_ptr.is_null())
58-
.then_some((opaque_ptr as *const T).as_ref())
58+
.then_some(opaque_ptr.cast::<T>().as_ref())
5959
.flatten()
6060
}
6161
}

vortex-duckdb/src/duckdb/table_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl TableFilter {
127127

128128
let name = unsafe {
129129
str::from_utf8_unchecked(std::slice::from_raw_parts(
130-
out.child_name as *const u8,
130+
out.child_name.cast::<u8>(),
131131
out.child_name_len,
132132
))
133133
};

vortex-duckdb/src/duckdb/vector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Vector {
144144
// Direct bit manipulation for better performance
145145
let entry_idx = row / 64;
146146
let idx_in_entry = row % 64;
147-
let validity_u64_ptr = validity as *const u64;
147+
let validity_u64_ptr = validity.cast_const();
148148
let validity_entry = unsafe { *validity_u64_ptr.add(entry_idx as usize) };
149149
let is_valid = (validity_entry & (1u64 << idx_in_entry)) != 0;
150150

vortex-ffi/src/binary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mod tests {
4646
fn test_string_new() {
4747
unsafe {
4848
let test_str = "hello world";
49-
let ptr = test_str.as_ptr() as *const c_char;
49+
let ptr = test_str.as_ptr().cast();
5050
let len = test_str.len();
5151

5252
let vx_str = vx_binary_new(ptr, len);
@@ -66,7 +66,7 @@ mod tests {
6666
let ptr = vx_binary_ptr(vx_str);
6767
let len = vx_binary_len(vx_str);
6868

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

7272
vx_binary_free(vx_str);
@@ -77,7 +77,7 @@ mod tests {
7777
fn test_empty_string() {
7878
unsafe {
7979
let empty = "";
80-
let ptr = empty.as_ptr() as *const c_char;
80+
let ptr = empty.as_ptr().cast();
8181
let vx_str = vx_binary_new(ptr, 0);
8282

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

9797
let vx_str = vx_binary_new(ptr, len);

vortex-ffi/src/dtype.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ mod tests {
660660

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

@@ -689,7 +689,7 @@ mod tests {
689689

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

695695
let expected_name = if i == 0 { "nums" } else { "floats" };

vortex-ffi/src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn extract_expression(
114114
) -> VortexResult<Option<Expression>> {
115115
Ok((!expression.is_null() && expression_len > 0).then_some({
116116
let bytes =
117-
unsafe { slice::from_raw_parts(expression as *const u8, expression_len as usize) };
117+
unsafe { slice::from_raw_parts(expression.cast::<u8>(), expression_len as usize) };
118118

119119
// Decode the protobuf message.
120120
deserialize_expr_proto(&Expr::decode(bytes)?, registry)

0 commit comments

Comments
 (0)