Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup FFI interface (#3684) (#3683) #3685

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use ManuallyDrop to model external memory
tustvold committed Feb 9, 2023
commit 34871371154195dd77fae9593792bc065f4034f5
28 changes: 14 additions & 14 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
@@ -966,7 +966,8 @@ mod tests {
use arrow_array::types::{Float64Type, Int32Type};
use arrow_array::{Float64Array, UnionArray};
use std::convert::TryFrom;
use std::ptr::{addr_of, addr_of_mut};
use std::mem::ManuallyDrop;
use std::ptr::addr_of_mut;

#[test]
fn test_round_trip() {
@@ -987,19 +988,18 @@ mod tests {
#[test]
fn test_import() {
// Model receiving const pointers from an external system
let (schema_ptr, array_ptr) = {
// create an array natively
let data = Int32Array::from(vec![1, 2, 3]).into_data();
let schema = FFI_ArrowSchema::try_from(data.data_type()).unwrap();
let array = FFI_ArrowArray::new(&data);

// Models receiving pointers from some external system
let schema_ptr = addr_of!(schema);
let array_ptr = addr_of!(array);
std::mem::forget(schema);
std::mem::forget(array);
(schema_ptr, array_ptr)
};

// Create an array natively
let data = Int32Array::from(vec![1, 2, 3]).into_data();
let schema = FFI_ArrowSchema::try_from(data.data_type()).unwrap();
let array = FFI_ArrowArray::new(&data);

// Use ManuallyDrop to avoid Box:Drop recursing
let schema = Box::new(ManuallyDrop::new(schema));
let array = Box::new(ManuallyDrop::new(array));

let schema_ptr = &**schema as *const _;
let array_ptr = &**array as *const _;

// We can read them back to memory
// SAFETY: