Skip to content

Commit 570f7ed

Browse files
authored
Remove borrowed types from FFI; fixed_size_list constructor accepts u32 (#8658)
FFI currently has two types of returned objects: ones are owned (inside of which there's an Arc), others are borrowed (because there's no Arc inside). One example of the latter is a struct field name which returns a borrowed vx_string. We initially had a comment caller shouldn't call the corresponding _free() function on these. This is not enough as caller can call a _clone() function on a borrowed vx_string which is UB because we try to increment a strong reference count on a pointer which isn't an Arc. From a callee's perspective, we can't distinguish owned and borrowed types, and this creates weird APIs like struct field dtype being owned but name being borrowed. This PR removes all borrowed/owned distinction from FFI layer. Each object now returned from an FFI function is owned. It can be freely cloned, and each must be freed explicitly with _free() functions. On another change, fixed size list constructor previously accepted a size_t (64-bit unsigned integer on most systems) but validated it against u32 because that's our file format limitation for fixed size lists. This PR changes the signature so that now it accepts uint32_t as length parameter. As the changes are significant enough to trigger bugs in our own tests, this PR also re-enables FFI sanitizer tests in CI. Signed-off-by: Mikhail Kot <mikhail@spiraldb.com>
1 parent 86c250a commit 570f7ed

20 files changed

Lines changed: 224 additions & 305 deletions

.github/workflows/rust-instrumented.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ jobs:
194194
- sanitizer: tsan
195195
sanitizer_flags: "-Zsanitizer=thread"
196196
name: "Rust/C++ FFI tests (${{ matrix.sanitizer }})"
197-
timeout-minutes: 30
197+
timeout-minutes: 5
198198
env:
199199
ASAN_OPTIONS: "symbolize=1:check_initialization_order=1:detect_leaks=1:leak_check_at_exit=1"
200200
LSAN_OPTIONS: "report_objects=1"
@@ -217,9 +217,6 @@ jobs:
217217
sccache: s3
218218
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
219219
- uses: ./.github/actions/setup-prebuild
220-
- name: Install rustfilt
221-
run: |
222-
cargo install rustfilt
223220
- name: Install Rust nightly toolchain
224221
run: |
225222
rustup toolchain install $NIGHTLY_TOOLCHAIN
@@ -241,8 +238,7 @@ jobs:
241238
- name: Run tests
242239
run: |
243240
set -o pipefail
244-
# re-enable once we can fix this hang
245-
# ./vortex-ffi/build/test/vortex_ffi_test 2>&1 | rustfilt
241+
./vortex-ffi/build/test/vortex_ffi_test
246242
- name: Run examples
247243
run: |
248244
set -o pipefail
@@ -251,11 +247,11 @@ jobs:
251247
# error: Unable to walk dir: File system loop found
252248
rm -fr vortex-ffi/build/_deps/nanoarrow-src/python
253249
254-
./vortex-ffi/build/examples/write_sample file.vortex 2>&1 | rustfilt
255-
./vortex-ffi/build/examples/write_sample file2.vortex 2>&1 | rustfilt
256-
./vortex-ffi/build/examples/dtype '*.vortex' 2>&1 | rustfilt
257-
./vortex-ffi/build/examples/scan '*.vortex' 2>&1 | rustfilt
258-
./vortex-ffi/build/examples/scan_to_arrow '*.vortex' 2>&1 | rustfilt
250+
./vortex-ffi/build/examples/write_sample file.vortex
251+
./vortex-ffi/build/examples/write_sample file2.vortex
252+
./vortex-ffi/build/examples/dtype '*.vortex'
253+
./vortex-ffi/build/examples/scan '*.vortex'
254+
./vortex-ffi/build/examples/scan_to_arrow '*.vortex'
259255
260256
miri:
261257
name: "Rust tests (miri)"

vortex-ffi/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Vortex C interface
1+
# Vortex C bindings
22

33
## Updating Headers
44

@@ -20,7 +20,7 @@ target_link_libraries(my_target, vortex_ffi_shared)
2020
# or target_link_libraries(my_target, vortex_ffi)
2121
```
2222

23-
## Running C examples:
23+
## Running C examples
2424

2525
```sh
2626
cmake -Bbuild -DBUILD_EXAMPLES=1
@@ -99,7 +99,7 @@ cargo +nightly build -Zbuild-std --target=<target triple> \
9999
2. Build tests with target triple:
100100

101101
```sh
102-
cmake -Bbuild -DWITH_ASAN=1 -DTARGET_TRIPLE=<target triple>
102+
cmake -Bbuild -DSANITIZER=asan -DTARGET_TRIPLE=<target triple>
103103
```
104104

105105
3. Run the tests (ctest doesn't output failures in detail):

vortex-ffi/cbindgen.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ header = """
1111
#pragma once
1212
#include <stdint.h>
1313
14-
//
1514
// THIS FILE IS AUTO-GENERATED, DO NOT MAKE EDITS DIRECTLY
16-
//
15+
16+
// All operations return owned types which need to be freed by calling a
17+
// matching _free() function. This includes all arrays, data sources, scans,
18+
// errors, error messages, and other allocated objects.
1719
1820
// https://arrow.apache.org/docs/format/CDataInterface.html#structure-definitions
1921
// If you want to use your own Arrow library like nanoarrow, define this macro

0 commit comments

Comments
 (0)