Skip to content

Commit

Permalink
For review
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jun 18, 2024
1 parent fe54f67 commit 826e77f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
11 changes: 3 additions & 8 deletions arrow-buffer/src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ impl Buffer {
/// Returns the offset, in bytes, of `Self::ptr` to `Self::data`
///
/// self.ptr and self.data can be different after slicing or advancing the buffer.
///
/// # Safety
///
/// This function is unsafe as it uses unsafe function `offset_from`. Under certain
/// conditions, this function can cause undefined behavior. See the documentation of
/// `offset_from` for more information.
pub unsafe fn ptr_offset(&self) -> usize {
self.ptr.offset_from(self.data.ptr().as_ptr()) as usize
pub fn ptr_offset(&self) -> usize {
// Safety: `ptr` is always in bounds of `data`.
unsafe { self.ptr.offset_from(self.data.ptr().as_ptr()) as usize }
}

/// Returns the pointer to the start of the buffer without the offset.
Expand Down
10 changes: 2 additions & 8 deletions arrow-data/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,15 @@ impl FFI_ArrowArray {
// the consumer to calculate incorrect length of data buffer (buffer 1).
// We need to get the offset of the offset buffer and fill it in
// the `FFI_ArrowArray` offset field.
Some(unsafe {
let b = &data.buffers()[0];
b.ptr_offset() / std::mem::size_of::<i32>()
})
Some(data.buffers()[0].ptr_offset() / std::mem::size_of::<i32>())
}
DataType::LargeUtf8 | DataType::LargeBinary => {
// Offset buffer is possible a slice of the buffer.
// If we use slice pointer as exported buffer pointer, it will cause
// the consumer to calculate incorrect length of data buffer (buffer 1).
// We need to get the offset of the offset buffer and fill it in
// the `FFI_ArrowArray` offset field.
Some(unsafe {
let b = &data.buffers()[0];
b.ptr_offset() / std::mem::size_of::<i64>()
})
Some(data.buffers()[0].ptr_offset() / std::mem::size_of::<i64>())
}
_ => None,
};
Expand Down

0 comments on commit 826e77f

Please sign in to comment.