You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2023/06/22 20:42:16 UTC

[GitHub] [arrow-rs] viirya commented on a diff in pull request #4446: Revise error message in From for ScalaBuffer

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: github-unsubscribe@arrow.apache.org

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