Repository navigation
Replies: 2 comments
|
Mailing list thread: https://lists.apache.org/thread/or56pq7dofv13w8do4ndwdfcx9px8wq7 |
0 replies
|
+1 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I propose changing the C ABI so that structs are passed through pointers rather than returned by value. This would let the Go binding call the C binding directly through purego and remove its libffi dependency while keeping CGO_ENABLED=0.
The Go binding currently requires users to install libffi. Its call layer prepares libffi signatures for C entry points, including struct results for operator creation, reads, metadata, and other operations. We already depend on purego, but the pinned v0.10.1 only supports passing and returning structs by value on Linux and macOS amd64/arm64. Windows is excluded, so replacing libffi calls without changing the ABI would not cover our platforms.
The proposed convention is:
opendal_error *from fallible operations, withNULLindicating success.For example:
The caller would provide valid, aligned, writable storage for
out. The function would initialize it on both success and failure, with an empty value on failure, and would not retain its address. Returned data would remain owned by the caller and released withopendal_bytes_free(). Reusing output storage would require releasing its previous owned contents first. The error pointer would retain the existingopendal_error_free()ownership convention.This does not inherently require another heap allocation or a copy of the payload: the caller provides storage for the result descriptor, and OpenDAL writes the buffer pointer and sizes into it. Struct layout and pointer lifetime still need to match across languages; using pointers only removes the struct calling-convention problem.
I would prefer changing the existing C entry points in a coordinated breaking release over maintaining parallel versions indefinitely. Go, C++, Zig, and other consumers of the affected C entry points would need corresponding updates, but their higher-level APIs could keep the same behavior. The Go package and its companion native libraries would need matching releases. This would also allow us to remove result wrapper types whose only purpose is to pair a value with an error.
The main trade-off beyond compatibility is that C callers must explicitly provide output storage. Performance also needs measurement: small structs can currently return in registers, while some larger structs already use hidden return pointers. Removing libffi does not by itself establish a speedup.
Before shipping, we should validate the affected bindings on their supported platforms, including Windows, and exercise successful calls, errors, empty results, and resource cleanup. The Go tests should run with CGO_ENABLED=0 and without libffi installed. Frequent small calls, such as metadata getters and streaming reads, would be useful cases for a before/after benchmark.
Would this be a reasonable direction for the next breaking C binding release? Are there consumers or calling patterns that make the output-parameter convention problematic?
AI assistance: Codex (gpt-6-astra, high reasoning effort) assisted with source inspection and drafting. This proposal follows a human-led design discussion; no implementation, cross-platform runtime validation, or performance measurements have been completed.
All reactions