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


##########
arrow/src/ffi.rs:
##########
@@ -1424,31 +1443,28 @@ mod tests {
         let array = make_array(Int32Array::from(vec![1, 2, 3]).into_data());
 
         // Assume two raw pointers provided by the consumer
-        let out_array = Box::new(FFI_ArrowArray::empty());
-        let out_schema = Box::new(FFI_ArrowSchema::empty());
-        let out_array_ptr = Box::into_raw(out_array);
-        let out_schema_ptr = Box::into_raw(out_schema);
-
-        unsafe {
-            export_array_into_raw(array, out_array_ptr, out_schema_ptr)?;
+        let mut out_array = FFI_ArrowArray::empty();
+        let mut out_schema = FFI_ArrowSchema::empty();
+
+        {
+            let out_array_ptr = addr_of_mut!(out_array);
+            let out_schema_ptr = addr_of_mut!(out_schema);
+            unsafe {
+                export_array_into_raw(array, out_array_ptr, out_schema_ptr)?;
+            }
         }
 
         // (simulate consumer) import it
-        unsafe {
-            let array = ArrowArray::try_from_raw(out_array_ptr, 
out_schema_ptr).unwrap();

Review Comment:
   > Isn't it jut like try_from_raw did now
   
   Yes, this does not change what can be achieved. Instead it clarifies both 
the ownership and mutation by making the user be explicit about what they want. 
If they want to zero out the data, mutating it, they can use 
`std::ptr::replace` on a `*mut T`, if they just want to read the data, they can 
use `std::ptr::read`, if the pointer isn't aligned they can use 
`std::ptr::read_unaligned`, etc... The intention is to put the responsibility 
onto the caller as to what the pointer is and how to "correctly" read it



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

Reply via email to