alamb commented on a change in pull request #8997:
URL: https://github.com/apache/arrow/pull/8997#discussion_r549110171
##########
File path: rust/arrow/src/array/raw_pointer.rs
##########
@@ -16,28 +16,37 @@
// under the License.
use crate::memory;
+use std::ptr::NonNull;
+/// This struct is highly `unsafe` and offers the possibility to
self-reference a [arrow::Buffer] from [arrow::array::ArrayData].
+/// as a pointer to the beginning of its contents.
pub(super) struct RawPtrBox<T> {
- inner: *const T,
+ ptr: NonNull<T>,
}
impl<T> RawPtrBox<T> {
- pub(super) fn new(inner: *const T) -> Self {
- Self { inner }
+ /// # Safety
+ /// The user must guarantee that:
+ /// * the contents where `ptr` points to are never `moved`. This is
guaranteed when they are Pinned.
+ /// * the lifetime of this struct does not outlive the lifetime of `ptr`.
+ /// Failure to fulfill any the above conditions results in undefined
behavior.
+ /// # Panic
+ /// This function panics if:
+ /// * `ptr` is null
+ /// * `ptr` is not aligned to a slice of type `T`. This is guaranteed if
it was built from a slice of type `T`.
+ pub(super) unsafe fn new(ptr: *const u8) -> Self {
Review comment:
This is a nice change -- to move the alignment assertion into the
`RawPtrBox::new` as that now makes the callsites clearer as well as they can't
forget to ensure alignment. 👍
##########
File path: rust/arrow/src/buffer.rs
##########
@@ -183,7 +192,7 @@ impl Buffer {
/// in larger chunks and starting at arbitrary bit offsets.
/// Note that both `offset` and `length` are measured in bits.
pub fn bit_chunks(&self, offset: usize, len: usize) -> BitChunks {
- BitChunks::new(&self.data.as_slice()[self.offset..], offset, len)
Review comment:
👍
##########
File path: rust/arrow/src/buffer.rs
##########
@@ -919,24 +962,18 @@ mod tests {
#[test]
fn test_from_raw_parts() {
- let buf = unsafe { Buffer::from_raw_parts(null_mut(), 0, 0) };
Review comment:
why was this test removed? Because it is no longer possible to create a
buffer from a null pointer?
----------------------------------------------------------------
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]