diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml index ffdd2196b07..350171da3a7 100644 --- a/arrow/Cargo.toml +++ b/arrow/Cargo.toml @@ -53,7 +53,7 @@ chrono-tz = {version = "0.6", optional = true} flatbuffers = { version = "=2.1.1", optional = true } hex = "0.4" comfy-table = { version = "5.0", optional = true, default-features = false } -pyo3 = { version = "0.16", optional = true } +pyo3 = { version = "0.18", optional = true } lexical-core = "^0.8" multiversion = "0.6.1" bitflags = "1.2.1" diff --git a/arrow/src/array/array.rs b/arrow/src/array/array.rs index 795439ec80a..3018967f5a5 100644 --- a/arrow/src/array/array.rs +++ b/arrow/src/array/array.rs @@ -620,6 +620,19 @@ fn new_null_sized_array( }) } +/// Creates a new array from two FFI pointers. Used to import arrays from the C Data Interface +/// # Safety +/// Assumes that these pointers represent valid C Data Interfaces, both in memory +/// representation and lifetime via the `release` mechanism. +pub unsafe fn make_array_from_box( + array: *const ffi::FFI_ArrowArray, + schema: *const ffi::FFI_ArrowSchema, +) -> Result { + let array = Arc::into_raw(Arc::from(Box::from_raw(array as *mut _))); + let schema = Arc::into_raw(Arc::from(Box::from_raw(schema as *mut _))); + make_array_from_raw(array, schema) +} + /// Creates a new array from two FFI pointers. Used to import arrays from the C Data Interface /// # Safety /// Assumes that these pointers represent valid C Data Interfaces, both in memory diff --git a/arrow/src/ffi.rs b/arrow/src/ffi.rs index 461995bdbaf..e0633081e95 100644 --- a/arrow/src/ffi.rs +++ b/arrow/src/ffi.rs @@ -107,7 +107,7 @@ bitflags! { /// See /// This was created by bindgen #[repr(C)] -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct FFI_ArrowSchema { format: *const c_char, name: *const c_char, @@ -336,7 +336,7 @@ fn bit_width(data_type: &DataType, i: usize) -> Result { /// See /// This was created by bindgen #[repr(C)] -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct FFI_ArrowArray { pub(crate) length: i64, pub(crate) null_count: i64, @@ -781,11 +781,9 @@ impl ArrowArray { .to_string(), )); }; - let ffi_array = (*array).clone(); - let ffi_schema = (*schema).clone(); Ok(Self { - array: Arc::new(ffi_array), - schema: Arc::new(ffi_schema), + array: Arc::from_raw(array as *mut FFI_ArrowArray), + schema: Arc::from_raw(schema as *mut FFI_ArrowSchema), }) }