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

unsafe improvements #6551

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions arrow-buffer/src/builder/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ impl<O: ArrowNativeType> OffsetBufferBuilder<O> {
///
/// Panics if offsets overflow `O`
ssbr marked this conversation as resolved.
Show resolved Hide resolved
pub fn finish_cloned(&self) -> OffsetBuffer<O> {
O::from_usize(self.last_offset).expect("overflow");
unsafe { OffsetBuffer::new_unchecked(self.offsets.clone().into()) }
let cloned = Self {
offsets: self.offsets.clone(),
last_offset: self.last_offset,
};
cloned.finish()
}
}

Expand Down
8 changes: 4 additions & 4 deletions arrow-buffer/src/util/bit_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ unsafe fn set_upto_64bits(
}

/// # Safety
/// The caller must ensure all arguments are within the valid range.
/// The caller must ensure `data` has `offset..(offset + 8)` range
#[inline]
unsafe fn read_bytes_to_u64(data: &[u8], offset: usize, count: usize) -> u64 {
debug_assert!(count <= 8);
let mut tmp = std::mem::MaybeUninit::<u64>::new(0);
let mut tmp : u64 = 0;
let src = data.as_ptr().add(offset);
unsafe {
std::ptr::copy_nonoverlapping(src, tmp.as_mut_ptr() as *mut u8, count);
tmp.assume_init()
std::ptr::copy_nonoverlapping(src, &mut tmp as *mut _ as *mut u8, count);
ssbr marked this conversation as resolved.
Show resolved Hide resolved
}
tmp
}

/// # Safety
Expand Down
Loading