sunchao commented on a change in pull request #1449:
URL: https://github.com/apache/arrow-rs/pull/1449#discussion_r830366722
##########
File path: arrow/src/array/array.rs
##########
@@ -632,6 +632,40 @@ pub unsafe fn make_array_from_raw(
let data = ArrayData::try_from(array)?;
Ok(make_array(data))
}
+
+/// Exports an array to raw pointers of the C Data Interface provided by the
consumer.
+/// # Safety
+/// Assumes that these pointers represent valid C Data Interfaces, both in
memory
+/// representation and lifetime via the `release` mechanism.
+///
+/// This function copies the content of two FFI structs [ffi::FFI_ArrowArray]
and
+/// [ffi::FFI_ArrowSchema] in the array to the location pointed by the raw
pointers.
+/// Usually the raw pointers are provided by the array data consumer.
+pub unsafe fn export_array_into_raw(
+ src: ArrayRef,
+ out_array: *mut ffi::FFI_ArrowArray,
+ out_schema: *mut ffi::FFI_ArrowSchema,
+) -> Result<()> {
+ let (array, schema) = src.to_raw()?;
Review comment:
hmm can we just construct array and schema explicitly?
```rust
let data = src.data().clone();
let array = FFI_ArrowArray::new(&data);
let schema = FFI_ArrowSchema::try_from(data.data_type())?;
std::ptr::write_unaligned(out_array, array);
std::ptr::write_unaligned(out_schema, schema);
Ok(())
```
--
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]