From a7cc916829cfeef042c532a2cc89104a76b4853a Mon Sep 17 00:00:00 2001 From: ritchie Date: Tue, 22 Oct 2024 10:32:09 +0200 Subject: [PATCH] manually drop --- crates/polars-arrow/src/compute/take/fixed_size_list.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/polars-arrow/src/compute/take/fixed_size_list.rs b/crates/polars-arrow/src/compute/take/fixed_size_list.rs index 997ad004387b..bf5bc64606d4 100644 --- a/crates/polars-arrow/src/compute/take/fixed_size_list.rs +++ b/crates/polars-arrow/src/compute/take/fixed_size_list.rs @@ -15,6 +15,8 @@ // specific language governing permissions and limitations // under the License. +use std::mem::ManuallyDrop; + use polars_utils::itertools::Itertools; use super::Index; @@ -100,16 +102,13 @@ fn get_buffer_and_size(array: &dyn Array) -> (&[u8], usize) { } } -unsafe fn from_buffer(mut buf: Vec, dtype: &ArrowDataType) -> ArrayRef { +unsafe fn from_buffer(mut buf: ManuallyDrop>, dtype: &ArrowDataType) -> ArrayRef { match dtype.to_physical_type() { PhysicalType::Primitive(primitive) => with_match_primitive_type!(primitive, |$T| { - let ptr = buf.as_mut_ptr(); let len_units = buf.len(); let cap_units = buf.capacity(); - std::mem::forget(buf); - let buf = Vec::from_raw_parts( ptr as *mut $T, len_units / size_of::<$T>(), @@ -175,7 +174,7 @@ pub(super) unsafe fn take_unchecked( let n_idx = indices.len(); let total_bytes = bytes_per_element * n_idx; - let mut buf = aligned_vec(leaves.dtype(), total_bytes); + let mut buf = ManuallyDrop::new(aligned_vec(leaves.dtype(), total_bytes)); let dst = buf.spare_capacity_mut(); let mut count = 0;