jorgecarleitao opened a new pull request #8997:
URL: https://github.com/apache/arrow/pull/8997


   Currently, our allocation code is not guaranteeing that the 
`std::mem::alloc` was successful, by checking for whether the returned pointer 
was not null. Passing null pointers to buffers is dangerous, specially given 
that Buffers currently expose them without any checks.
   
   This PR is a series of modifications that removes the possibility of having 
null pointers:
   
   * Made most of our pointers `NonNull` and panic whenever a null pointer 
tries to sneak to a buffer (either via FFI or a failed allocation)
   * Guard against overflow of a pointer address during allocations (relevant 
for 32 bit systems)
   * remove the possibility of a null pointer to be on `RawPtrBox`, flags 
`RawPtrBox::new` as `unsafe` and documents the invariants necessary to a sound 
usage of `RawPtrBox`.
   * Made all methods in `memory` expect and output a `NonNull`
   
   All these changes were highly motivated by the code in Rust's `std::alloc`, 
and how it deals with these edge cases.
   
   The main consequence of these changes is that our buffers no longer hold 
null pointers, which allow us to implement `Deref<[u8]>` (done in this PR), and 
treat `Buffer` as very similar to an immutable `Vec<u8>` (and `MutableBuffer` 
closer to `Vec<u8>`). In this direction, this PR renames a bunch of methods:
   
   * `MutableBuffer::data_mut -> MutableBuffer::as_slice_mut`
   * `MutableBuffer::data -> MutableBuffer::as_slice`
   * `Buffer::data -> Buffer::as_slice`
   * `Buffer::raw_data -> Buffer::as_ptr`
   * `RawPtrBox::get -> RawPtrBox::as_ptr`
   
   The rational for these names come from `Vec::as_slice_mut`, `Vec::as_slice`, 
`Vec::as_ptr` and `NonNull::as_ptr` respectively.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to