tustvold commented on code in PR #3685:
URL: https://github.com/apache/arrow-rs/pull/3685#discussion_r1101814606
##########
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:
You either do something like in this doc -
https://github.com/apache/arrow-rs/pull/3685/files#diff-c6cab492853dc6dec63fbf818294b78b87bdef628515910d91873084ff32d6d7R61
Or you use `std::ptr::replace`.
We could add something like `try_from_raw` that accepts `*mut` pointers, but
I figured it was better to push people towards using Rust ownership instead of
passing pointers around with unclear ownership
--
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]