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

Fix FFI and add support for Struct type #287

Merged
merged 3 commits into from
May 17, 2021
Merged

Conversation

roee88
Copy link
Contributor

@roee88 roee88 commented May 12, 2021

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?

  • Support struct type in FFI
  • No fake "item" in list types
  • No undefined behavior on release of nested types

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.

Ported from https://github.com/jorgecarleitao/arrow2

Fix apache#20
Fix apache#251

Signed-off-by: roee88 <roee88@gmail.com>
@nevi-me
Copy link
Contributor

nevi-me commented May 13, 2021

ping @ritchie46

Copy link
Member

@jorgecarleitao jorgecarleitao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <roee88@gmail.com>
Signed-off-by: roee88 <roee88@gmail.com>
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'

@ritchie46
Copy link
Contributor

Nice work on this one! 👍

@roee88
Copy link
Contributor Author

roee88 commented May 15, 2021

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'

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.

@jorgecarleitao
Copy link
Member

@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-commenter
Copy link

Codecov Report

Merging #287 (5da458b) into master (8226219) will decrease coverage by 0.03%.
The diff coverage is 88.26%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
arrow/src/ffi.rs 82.61% <87.15%> (+1.66%) ⬆️
arrow/src/array/ffi.rs 100.00% <100.00%> (+14.86%) ⬆️
parquet/src/errors.rs 18.51% <0.00%> (-3.71%) ⬇️
arrow/src/error.rs 8.88% <0.00%> (-2.23%) ⬇️
arrow/src/compute/kernels/regexp.rs 96.34% <0.00%> (-1.22%) ⬇️
arrow/src/array/equal_json.rs 91.21% <0.00%> (-1.22%) ⬇️
arrow/src/ipc/convert.rs 92.98% <0.00%> (-1.14%) ⬇️
arrow/src/compute/util.rs 97.84% <0.00%> (-1.08%) ⬇️
arrow/src/datatypes/schema.rs 66.39% <0.00%> (-0.82%) ⬇️
arrow/src/array/data.rs 71.47% <0.00%> (-0.61%) ⬇️
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8226219...5da458b. Read the comment docs.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review this carefully but I trust @jorgecarleitao's analysis -- I think this is good to merge from my perspective

@alamb alamb merged commit c863a2c into apache:master May 17, 2021
@roee88 roee88 deleted the ffi-nested branch May 17, 2021 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement FFI / CDataInterface for Struct Arrays FFI listarray lead to undefined behavior.
6 participants