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

[GitHub] [arrow-rs] Virgiel commented on a diff in pull request #4447: Simplify ffi import/export

Virgiel commented on code in PR #4447:
URL: https://github.com/apache/arrow-rs/pull/4447#discussion_r1242560260


##########
arrow/src/ffi.rs:
##########
@@ -222,41 +221,69 @@ unsafe fn create_buffer(
         .map(|ptr| Buffer::from_custom_allocation(ptr, len, owner))
 }
 
-pub trait ArrowArrayRef {
-    fn to_data(&self) -> Result<ArrayData> {
-        let data_type = self.data_type()?;
-        let len = self.array().len();
-        let offset = self.array().offset();
-        let null_count = self.array().null_count();
+/// Export to the C Data Interface
+pub fn to_ffi(data: &ArrayData) -> Result<(FFI_ArrowArray, FFI_ArrowSchema)> {
+    let array = FFI_ArrowArray::new(data);
+    let schema = FFI_ArrowSchema::try_from(data.data_type())?;
+    Ok((array, schema))
+}
+
+/// Import [ArrayData] from the C Data Interface
+///
+/// # Safety
+///
+/// This struct assumes that the incoming data agrees with the C data interface.
+pub fn from_ffi(array: FFI_ArrowArray, schema: &FFI_ArrowSchema) -> Result<ArrayData> {

Review Comment:
   The ownership is transferred to ArrayData in the same way as before. As I understand it, this happens when the arc is cloned in the buffer logic.



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