sunchao commented on a change in pull request #1432:
URL: https://github.com/apache/arrow-rs/pull/1432#discussion_r827449744



##########
File path: arrow/src/array/array.rs
##########
@@ -629,7 +629,9 @@ pub unsafe fn make_array_from_raw(
     schema: *const ffi::FFI_ArrowSchema,
 ) -> Result<ArrayRef> {
     let array = ffi::ArrowArray::try_from_raw(array, schema)?;
-    let data = ArrayData::try_from(array)?;
+    let data = ArrayData::try_from(&array)?;
+    // Avoid dropping the `Box` pointers and trigger the `release` mechanism.
+    let _ = ffi::ArrowArray::into_raw(array);

Review comment:
       I see, thanks for the explanation.
   
   I'm wondering if we can still use `Arc` but drop the "envelop memory" 
allocated for the struct holding the actual pointers, for the input array and 
schema. For example:
   ```rust
       pub unsafe fn try_from_raw(
           array: *const FFI_ArrowArray,
           schema: *const FFI_ArrowSchema,
       ) -> Result<Self> {
           if array.is_null() || schema.is_null() {
               return Err(ArrowError::MemoryError(
                   "At least one of the pointers passed to `try_from_raw` is 
null"
                       .to_string(),
               ));
           };
   
           let array_mut = array as *mut FFI_ArrowArray;
           let schema_mut = schema as *mut FFI_ArrowSchema;
   
           let array_data = std::ptr::replace(array_mut, 
FFI_ArrowArray::empty());
           let schema_data = std::ptr::replace(schema_mut, 
FFI_ArrowSchema::empty());
   
           std::ptr::drop_in_place(array_mut);
           std::ptr::drop_in_place(schema_mut);
   
           Ok(Self {
               array: Arc::new(array_data),
               schema: Arc::new(schema_data),
           })
       }
   ```




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