viirya commented on code in PR #4446:
URL: https://github.com/apache/arrow-rs/pull/4446#discussion_r1239011698
##########
arrow-buffer/src/buffer/scalar.rs:
##########
@@ -118,11 +119,16 @@ impl<T: ArrowNativeType> From<MutableBuffer> for
ScalarBuffer<T> {
impl<T: ArrowNativeType> From<Buffer> for ScalarBuffer<T> {
fn from(buffer: Buffer) -> Self {
let align = std::mem::align_of::<T>();
- assert_eq!(
- buffer.as_ptr().align_offset(align),
- 0,
- "memory is not aligned"
- );
+ let is_aligned = buffer.as_ptr().align_offset(align) == 0;
+
+ match buffer.deallocation() {
+ Deallocation::Standard(_) => assert!(
+ is_aligned,
+ "Memory pointer is not aligned with the specified scalar type."
+ ),
+ Deallocation::Custom(_) =>
+ assert!(is_aligned, "Memory pointer from external source (e.g,
FFI) is not aligned with the specified scalar type. Before importing buffer
through FFI, please make sure the allocation is aligned."),
Review Comment:
This is to clarify the error message for users who don't know too much
details about the implementation.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]