Skip to content

Commit

Permalink
Apply suggestions from code review: some safety annotations
Browse files Browse the repository at this point in the history
Co-authored-by: QP Hou <dave2008713@gmail.com>
  • Loading branch information
alamb and houqp authored Oct 12, 2021
1 parent 92e4789 commit d54bd7d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions arrow/src/array/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
new_null_sized_array::<IntervalDayTimeType>(data_type, length)
}
},
// Safety: `value_len` from `DataType::FixedSizeBinary` is used as data unit length value buffer length calculation
DataType::FixedSizeBinary(value_len) => make_array(unsafe {
ArrayData::new_unchecked(
data_type.clone(),
Expand Down
1 change: 1 addition & 0 deletions arrow/src/array/array_boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl<Ptr: Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray {
}
});

// Safety: value buffer size is derived directly from iterator size hint above
let data = unsafe {
ArrayData::new_unchecked(
DataType::Boolean,
Expand Down
1 change: 1 addition & 0 deletions arrow/src/array/array_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
/// Creates a PrimitiveArray based on an iterator of values without nulls
pub fn from_iter_values<I: IntoIterator<Item = T::Native>>(iter: I) -> Self {
let val_buf: Buffer = iter.into_iter().collect();
// Safety: Buffer from iterator trait is sound, generic guarantees array data type matches iterator item type
let data = unsafe {
ArrayData::new_unchecked(
T::DATA_TYPE,
Expand Down
1 change: 1 addition & 0 deletions arrow/src/compute/kernels/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ where
// `values` is an iterator with a known size.
let buffer = unsafe { Buffer::from_trusted_len_iter(values) };

// Safety: generic guarantees array data type matches with buffer value iterator datatype
let data = unsafe {
ArrayData::new_unchecked(
T::DATA_TYPE,
Expand Down

0 comments on commit d54bd7d

Please sign in to comment.