File tree 2 files changed +5
-16
lines changed
2 files changed +5
-16
lines changed Original file line number Diff line number Diff line change @@ -74,14 +74,9 @@ impl Buffer {
74
74
/// Returns the offset, in bytes, of `Self::ptr` to `Self::data`
75
75
///
76
76
/// 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 }
85
80
}
86
81
87
82
/// Returns the pointer to the start of the buffer without the offset.
Original file line number Diff line number Diff line change @@ -139,21 +139,15 @@ impl FFI_ArrowArray {
139
139
// the consumer to calculate incorrect length of data buffer (buffer 1).
140
140
// We need to get the offset of the offset buffer and fill it in
141
141
// 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 > ( ) )
146
143
}
147
144
DataType :: LargeUtf8 | DataType :: LargeBinary => {
148
145
// Offset buffer is possible a slice of the buffer.
149
146
// If we use slice pointer as exported buffer pointer, it will cause
150
147
// the consumer to calculate incorrect length of data buffer (buffer 1).
151
148
// We need to get the offset of the offset buffer and fill it in
152
149
// 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 > ( ) )
157
151
}
158
152
_ => None ,
159
153
} ;
You can’t perform that action at this time.
0 commit comments