You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/16 03:26:54 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2883: Skip memory alignment check when constructing PrimitiveArray from an array data reference

tustvold commented on code in PR #2883:
URL: https://github.com/apache/arrow-rs/pull/2883#discussion_r996382149


##########
arrow-array/src/array/list_array.rs:
##########
@@ -861,16 +861,40 @@ mod tests {
     }
 
     #[test]
-    #[should_panic(expected = "memory is not aligned")]
+    #[should_panic(expected = "Need at least 8 bytes in buffers[0]")]
     fn test_primitive_array_alignment() {
-        let ptr = arrow_buffer::alloc::allocate_aligned(8);
+        let ptr = arrow_buffer::alloc::allocate_aligned_zeroed(8);
         let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
+        let buf1 = buf.slice(1);
         let buf2 = buf.slice(1);
+
+        // Aligned
+        let array_data = ArrayData::builder(DataType::Int32)
+            .add_buffer(buf)
+            .len(2)
+            .build()
+            .unwrap();
+        let array = Int32Array::from(array_data);
+        assert_eq!(array.len(), 2);
+        assert_eq!(array.value(0), 0);
+        assert_eq!(array.value(1), 0);
+
+        // Not aligned.
+        // `ArrayData::build` checks buffer length.
         let array_data = ArrayData::builder(DataType::Int32)
+            .add_buffer(buf1)
+            .len(1)
+            .build()
+            .unwrap();
+        let array = Int32Array::from(array_data);
+        assert_eq!(array.len(), 1);
+        assert_eq!(array.value(0), 0);

Review Comment:
   This is now unsound, as this violates the safety requirement in PrimitiveArray::values



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org