|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
18 | | -use std::alloc::{handle_alloc_error, Layout}; |
| 18 | +use std::alloc::{Layout, handle_alloc_error}; |
19 | 19 | use std::mem; |
20 | 20 | use std::ptr::NonNull; |
21 | 21 |
|
22 | | -use crate::alloc::{Deallocation, ALIGNMENT}; |
| 22 | +use crate::alloc::{ALIGNMENT, Deallocation}; |
23 | 23 | use crate::{ |
24 | 24 | bytes::Bytes, |
25 | 25 | native::{ArrowNativeType, ToByteSlice}, |
@@ -460,8 +460,8 @@ impl MutableBuffer { |
460 | 460 | pub unsafe fn push_unchecked<T: ToByteSlice>(&mut self, item: T) { |
461 | 461 | let additional = std::mem::size_of::<T>(); |
462 | 462 | let src = item.to_byte_slice().as_ptr(); |
463 | | - let dst = self.data.as_ptr().add(self.len); |
464 | | - std::ptr::copy_nonoverlapping(src, dst, additional); |
| 463 | + let dst = unsafe { self.data.as_ptr().add(self.len) }; |
| 464 | + unsafe { std::ptr::copy_nonoverlapping(src, dst, additional) }; |
465 | 465 | self.len += additional; |
466 | 466 | } |
467 | 467 |
|
@@ -640,11 +640,11 @@ impl MutableBuffer { |
640 | 640 | for item in iterator { |
641 | 641 | // note how there is no reserve here (compared with `extend_from_iter`) |
642 | 642 | let src = item.to_byte_slice().as_ptr(); |
643 | | - std::ptr::copy_nonoverlapping(src, dst, item_size); |
644 | | - dst = dst.add(item_size); |
| 643 | + unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) }; |
| 644 | + dst = unsafe { dst.add(item_size) }; |
645 | 645 | } |
646 | 646 | assert_eq!( |
647 | | - dst.offset_from(buffer.data.as_ptr()) as usize, |
| 647 | + unsafe { dst.offset_from(buffer.data.as_ptr()) } as usize, |
648 | 648 | len, |
649 | 649 | "Trusted iterator length was not accurately reported" |
650 | 650 | ); |
@@ -703,20 +703,22 @@ impl MutableBuffer { |
703 | 703 | let item = item?; |
704 | 704 | // note how there is no reserve here (compared with `extend_from_iter`) |
705 | 705 | let src = item.to_byte_slice().as_ptr(); |
706 | | - std::ptr::copy_nonoverlapping(src, dst, item_size); |
707 | | - dst = dst.add(item_size); |
| 706 | + unsafe { std::ptr::copy_nonoverlapping(src, dst, item_size) }; |
| 707 | + dst = unsafe { dst.add(item_size) }; |
708 | 708 | } |
709 | 709 | // try_from_trusted_len_iter is instantiated a lot, so we extract part of it into a less |
710 | 710 | // generic method to reduce compile time |
711 | 711 | unsafe fn finalize_buffer(dst: *mut u8, buffer: &mut MutableBuffer, len: usize) { |
712 | | - assert_eq!( |
713 | | - dst.offset_from(buffer.data.as_ptr()) as usize, |
714 | | - len, |
715 | | - "Trusted iterator length was not accurately reported" |
716 | | - ); |
717 | | - buffer.len = len; |
| 712 | + unsafe { |
| 713 | + assert_eq!( |
| 714 | + dst.offset_from(buffer.data.as_ptr()) as usize, |
| 715 | + len, |
| 716 | + "Trusted iterator length was not accurately reported" |
| 717 | + ); |
| 718 | + buffer.len = len; |
| 719 | + } |
718 | 720 | } |
719 | | - finalize_buffer(dst, &mut buffer, len); |
| 721 | + unsafe { finalize_buffer(dst, &mut buffer, len) }; |
720 | 722 | Ok(buffer) |
721 | 723 | } |
722 | 724 | } |
|
0 commit comments