Skip to content

Commit 826e77f

Browse files
committed
For review
1 parent fe54f67 commit 826e77f

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

arrow-buffer/src/buffer/immutable.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ impl Buffer {
7474
/// Returns the offset, in bytes, of `Self::ptr` to `Self::data`
7575
///
7676
/// self.ptr and self.data can be different after slicing or advancing the buffer.
77-
///
78-
/// # Safety
79-
///
80-
/// This function is unsafe as it uses unsafe function `offset_from`. Under certain
81-
/// conditions, this function can cause undefined behavior. See the documentation of
82-
/// `offset_from` for more information.
83-
pub unsafe fn ptr_offset(&self) -> usize {
84-
self.ptr.offset_from(self.data.ptr().as_ptr()) as usize
77+
pub fn ptr_offset(&self) -> usize {
78+
// Safety: `ptr` is always in bounds of `data`.
79+
unsafe { self.ptr.offset_from(self.data.ptr().as_ptr()) as usize }
8580
}
8681

8782
/// Returns the pointer to the start of the buffer without the offset.

arrow-data/src/ffi.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,15 @@ impl FFI_ArrowArray {
139139
// the consumer to calculate incorrect length of data buffer (buffer 1).
140140
// We need to get the offset of the offset buffer and fill it in
141141
// the `FFI_ArrowArray` offset field.
142-
Some(unsafe {
143-
let b = &data.buffers()[0];
144-
b.ptr_offset() / std::mem::size_of::<i32>()
145-
})
142+
Some(data.buffers()[0].ptr_offset() / std::mem::size_of::<i32>())
146143
}
147144
DataType::LargeUtf8 | DataType::LargeBinary => {
148145
// Offset buffer is possible a slice of the buffer.
149146
// If we use slice pointer as exported buffer pointer, it will cause
150147
// the consumer to calculate incorrect length of data buffer (buffer 1).
151148
// We need to get the offset of the offset buffer and fill it in
152149
// the `FFI_ArrowArray` offset field.
153-
Some(unsafe {
154-
let b = &data.buffers()[0];
155-
b.ptr_offset() / std::mem::size_of::<i64>()
156-
})
150+
Some(data.buffers()[0].ptr_offset() / std::mem::size_of::<i64>())
157151
}
158152
_ => None,
159153
};

0 commit comments

Comments
 (0)