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. I'm not sure why MIRI isn't catching this... Edit: It is `array.values()` that is unsound now, not `array.value`. If you add a call to `array.values()` in this test, MIRI will fail -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org