Skip to content

refactor(bindings/c)!: make operation options opaque and owned - #9593

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/implement-c-option-handles
Dec 3, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/implement-c-option-handles

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Dec 3, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #9566.

Rationale for this change

C callers currently allocate option structs and must know their layout. Allocating these structs in the library lets OpenDAL add fields without changing caller allocations. Copying setter inputs also gives callers a clear point at which they can release their buffers.

What changes are included in this PR?

The C header now declares seven incomplete struct types for list, stat, delete, read, reader, write, and copy options. All 56 setter signatures are unchanged. Each operation takes a snapshot of its options. Once the call returns, callers can reuse or free the options handle, including when the returned reader, writer, lister, or copier is still in use.

Are there any user-facing changes?

String and write-metadata setters copy their inputs before returning. Callers can then release or reuse the input buffers. To change an option, call its setter again. Passing NULL to a string setter clears that option, while "" supplies an explicit empty value. Passing NULL for an operation's options continues to select the defaults.

Breaking changes

Affected packages: bindings/c, bindings/go, bindings/zig

Migration:

  • In C and Zig C imports, pass NULL for default options. For custom options, replace stack allocation and struct literals with opendal_<operation>_options_new(), configure the handle with setters, and release it with opendal_<operation>_options_free(). The structs are incomplete, so direct field reads, field assignments, and sizeof on the struct no longer compile. Call a setter again if you previously relied on changing its input buffer after the call.
  • Rebuild native consumers with opendal.h and libopendal_c from the same OpenDAL source version. The new library and earlier development builds both return 1 from opendal_c_abi_version(), even though their option layouts differ.
  • If you set OPENDAL_C_LIB_PATH in Go, rebuild libopendal_c from the sources matching the Go binding. The Go wrapper keeps string and metadata buffers alive through each operation for older development libraries that borrow them.

AI Usage Statement

  • Harness: Pi via T3 Code. Model: magpie/codex/gpt-6.2-astra. Effort: thinking=high. Role: Traced C option ownership, checked binding migration requirements, and identified the ABI 1 development-library compatibility constraint.
  • Harness: Pi via T3 Code. Model: magpie/codex/gpt-6.2-sol. Effort: thinking=max. Role: Implemented the option handles and caller migration, verified the ABI and binding behavior, and drafted the migration notes.
  • Harness: Antigravity via T3 Code. Model: gemini-4-neon. Effort: high. Role: Copy-edited the PR description and migration notes.

@Xuanwo
Xuanwo merged commit 222c5a8 into main Dec 3, 2026
34 of 36 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/implement-c-option-handles branch December 3, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(bindings/c)!: convert opendal_*_options structs to opaque handles with owned string setters for C ABI v1

2 participants