Fix FFI and add support for Struct type#287
Conversation
Ported from https://github.com/jorgecarleitao/arrow2 Fix apache#20 Fix apache#251 Signed-off-by: roee88 <[email protected]>
|
ping @ritchie46 |
jorgecarleitao
left a comment
There was a problem hiding this comment.
I went through this PR and the changes look good (I am a bit biased, though ^_^).
The only think I would change: remove the Clone from #derive[Debug, Clone]. In general is not a good practice to allow people to clone a struct containing pointers, as there is limited control over their lifetimes.
Arrow2 has it by mistake; I added it during some experiments and then abandoned it and forgot to remove the Clone from there.
Signed-off-by: roee88 <[email protected]>
Signed-off-by: roee88 <[email protected]>
alamb
left a comment
There was a problem hiding this comment.
I also wondered if this would fix #227 (aka miri reported issues):
RUST_BACKTRACE=1 MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test -p arrow -- ffi
Sadly, it still fails on both this branch and master. On master it fails with:
running 12 tests
test array::ffi::tests::test_i64 ... error: Undefined Behavior: trying to reborrow for SharedReadOnly at alloc875771, but parent tag <2225913> does not have an appropriate item in the borrow stack
--> /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/unique.rs:118:18
|
118 | unsafe { &*self.as_ptr() }
| ^^^^^^^^^^^^^^^ trying to reborrow for SharedReadOnly at alloc875771, but parent tag <2225913> does not have an appropriate item in the borrow stack
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
= note: inside `std::ptr::Unique::<[*const std::ffi::c_void]>::as_ref` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/unique.rs:118:18
= note: inside `alloc::alloc::box_free::<[*const std::ffi::c_void], std::alloc::Global>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/alloc.rs:331:32
= note: inside `std::ptr::drop_in_place::<std::boxed::Box<[*const std::ffi::c_void]>> - shim(Some(std::boxed::Box<[*const std::ffi::c_void]>))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<ffi::PrivateData> - shim(Some(ffi::PrivateData))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<std::boxed::Box<ffi::PrivateData>> - shim(Some(std::boxed::Box<ffi::PrivateData>))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
note: inside `ffi::release_array` at arrow/src/ffi.rs:396:58
--> arrow/src/ffi.rs:396:58
|
396 | Box::from_raw(array.private_data as *mut PrivateData);
| ^
note: inside `<ffi::FFI_ArrowArray as std::ops::Drop>::drop` at arrow/src/ffi.rs:517:39
--> arrow/src/ffi.rs:517:39
|
517 | Some(release) => unsafe { release(self) },
| ^^^^^^^^^^^^^
= note: inside `std::ptr::drop_in_place::<ffi::FFI_ArrowArray> - shim(Some(ffi::FFI_ArrowArray))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::sync::Arc::<ffi::FFI_ArrowArray>::drop_slow` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:1039:18
= note: inside `<std::sync::Arc<ffi::FFI_ArrowArray> as std::ops::Drop>::drop` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:1571:13
= note: inside `std::ptr::drop_in_place::<std::sync::Arc<ffi::FFI_ArrowArray>> - shim(Some(std::sync::Arc<ffi::FFI_ArrowArray>))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<bytes::Deallocation> - shim(Some(bytes::Deallocation))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<bytes::Bytes> - shim(Some(bytes::Bytes))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::sync::Arc::<bytes::Bytes>::drop_slow` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:1039:18
= note: inside `<std::sync::Arc<bytes::Bytes> as std::ops::Drop>::drop` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:1571:13
= note: inside `std::ptr::drop_in_place::<std::sync::Arc<bytes::Bytes>> - shim(Some(std::sync::Arc<bytes::Bytes>))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<buffer::immutable::Buffer> - shim(Some(buffer::immutable::Buffer))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<bitmap::Bitmap> - shim(Some(bitmap::Bitmap))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<std::option::Option<bitmap::Bitmap>> - shim(Some(std::option::Option<bitmap::Bitmap>))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
= note: inside `std::ptr::drop_in_place::<array::data::ArrayData> - shim(Some(array::data::ArrayData))` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:192:1
note: inside `array::ffi::tests::test_round_trip` at arrow/src/array/ffi.rs:146:5
--> arrow/src/array/ffi.rs:146:5
|
146 | }
| ^
note: inside `array::ffi::tests::test_i64` at arrow/src/array/ffi.rs:166:9
--> arrow/src/array/ffi.rs:166:9
|
166 | test_round_trip(data)
| ^^^^^^^^^^^^^^^^^^^^^
note: inside closure at arrow/src/array/ffi.rs:163:5
--> arrow/src/array/ffi.rs:163:5
|
163 | / fn test_i64() -> Result<()> {
164 | | let array = Int64Array::from(vec![Some(2), None, Some(1), None]);
165 | | let data = array.data();
166 | | test_round_trip(data)
167 | | }
| |_____^
= note: inside `<[closure@arrow/src/array/ffi.rs:163:5: 167:6] as std::ops::FnOnce<()>>::call_once - shim` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
= note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
= note: inside `test::__rust_begin_short_backtrace::<fn()>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:577:5
= note: inside closure at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:568:30
= note: inside `<[closure@test::run_test::{closure#2}] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
= note: inside `<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send> as std::ops::FnOnce<()>>::call_once` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1546:9
= note: inside `<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>> as std::ops::FnOnce<()>>::call_once` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:344:9
= note: inside `std::panicking::r#try::do_call::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:379:40
= note: inside `std::panicking::r#try::<(), std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:343:19
= note: inside `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:431:14
= note: inside `test::run_test_in_process` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:600:18
= note: inside closure at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:492:39
= note: inside `test::run_test::run_test_inner` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:530:13
= note: inside `test::run_test` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:564:28
= note: inside `test::run_tests::<[closure@test::run_tests_console::{closure#2}]>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:305:17
= note: inside `test::run_tests_console` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/console.rs:289:5
= note: inside `test::test_main` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:122:15
= note: inside `test::test_main_static` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/test/src/lib.rs:141:5
= note: inside `main`
= note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
= note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:125:18
= note: inside closure at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:49:18
= note: inside `std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:259:13
= note: inside `std::panicking::r#try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:379:40
= note: inside `std::panicking::r#try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:343:19
= note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:431:14
= note: inside `std::rt::lang_start_internal` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:34:21
= note: inside `std::rt::lang_start::<()>` at /Users/alamb/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:48:5
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
error: test failed, to rerun pass '-p arrow --lib'
|
Nice work on this one! 👍 |
I have written on slack about this. I spent several hours on this but couldn't understand why dereferencing the raw pointer (to get the inner raw pointer) pops the borrow. I did test with miri but had to disable stacked borrows as suggested by @jorgecarleitao. |
|
@alamb , we are unable to distinguish if that is a false positive or a problem on our side. It is on my todo list to write to MIRI team to help us here. |
Codecov Report
@@ Coverage Diff @@
## master #287 +/- ##
==========================================
- Coverage 82.56% 82.52% -0.04%
==========================================
Files 162 162
Lines 43896 44005 +109
==========================================
+ Hits 36241 36316 +75
- Misses 7655 7689 +34
Continue to review full report at Codecov.
|
alamb
left a comment
There was a problem hiding this comment.
I didn't review this carefully but I trust @jorgecarleitao's analysis -- I think this is good to merge from my perspective
Which issue does this PR close?
Closes #20
Closes #251
Rationale for this change
This PR ports fixes from jorgecarleitao/arrow2#67 to this repository (thanks @jorgecarleitao).
The original API is unchanged and it's not a 1-1 port. Please review carefully.
What changes are included in this PR?
Are there any user-facing changes?
No changes to the API.
Exporting/Importing StructArray should work now, but the previous lack of support is not documented anyway.