chitralverma opened a new issue, #9352:
URL: https://github.com/apache/opendal/issues/9352

   *AI-generated issue (Claude Code), filed with @chitralverma's approval.*
   
   ### Feature Description
   
   Replace the C binding's `opendal_capability` struct and 
`opendal_operator_info_get_capability` with one generated function per core 
capability:
   
   ```c
   bool opendal_operator_info_capability_read(const struct 
opendal_operator_info *self);
   uintptr_t opendal_operator_info_capability_write_multi_max_size(const struct 
opendal_operator_info *self);
   ```
   
   `dev/src/generate/c.rs` would render these functions in core order and keep 
no field list. The Go binding keeps its `Capability` methods and reads each 
value through its function, as `Metadata` already does. Zig's 
`OperatorInfo.capability()` builds its struct at compile time from the same 
functions.
   
   ### Problem and Solution
   
   #9315 froze the order of the 98 `opendal_capability` fields 
(`FROZEN_CAPABILITY_ORDER` in `dev/src/generate/c.rs`), so C positional 
initializers keep their meaning after a rebuild. Two problems remain:
   
   - Every new core capability needs a manual append to that list, which is the 
kind of hand-maintained copy the generator was meant to remove.
   - Binaries still break. `opendal_operator_info_get_capability` writes the 
whole struct into caller-provided storage, so an appended field can grow 
`sizeof(opendal_capability)`; on Linux x86-64, one more `bool` takes it from 
152 to 160 bytes. A caller built with an older header then allocates too little 
space. The upgrade notes now say so, at Xuanwo's request.
   
   With one function per capability, a new capability adds a symbol and leaves 
the existing ones unchanged. No field order or struct size is part of the ABI, 
and the generator needs no hardcoded list.
   
   **One break instead of two.** The next release already breaks this API for 
every C caller that reads capabilities:
   
   - `opendal_operator_info_get_capability` changed from returning the struct 
by value to writing it through an output pointer (#8513), so the v0.59.5 call 
`opendal_capability cap = opendal_operator_info_get_capability(info);` no 
longer compiles.
   - `sizeof(opendal_capability)` grew from 104 to 152 bytes on Linux x86-64.
   
   Callers must edit their capability code and rebuild for that release anyway. 
Switching to functions in the same release costs them one migration. Switching 
after the new struct ships costs a second source migration and a second binary 
break.
   
   Costs of switching:
   
   - **C:** each field read such as `cap.read` becomes 
`opendal_operator_info_capability_read(info)`. That touches more lines than the 
output-pointer change alone.
   - **Go:** no public API change; `Capability` keeps every method name and 
signature. `opendal-go-services` companions must match the binding, as they 
already must.
   - **Zig:** `cap.read` keeps working; `cap.delete_` becomes `cap.delete`.
   - **C++:** unaffected, because it uses its own cxx bridge. Its 
`FROZEN_PUBLIC_ORDER` in `dev/src/generate/cpp.rs` protects a released C++ 
aggregate whose next release is not otherwise breaking, so it is out of scope 
here.
   
   ### Additional Context
   
   - On #9315, Xuanwo kept the struct for that PR and wrote: "That API decision 
can be made separately." 
(https://github.com/apache/opendal/pull/9315#issuecomment-7234603733)
   - Alternatives considered:
     - Keep the struct and its frozen order (current `main`). Each capability 
is a manual append and a possible binary break.
     - Add a size argument to `opendal_operator_info_get_capability` so the 
library writes only what the caller allocated. That keeps old binaries working 
as the struct grows, but keeps the frozen list and is still a second API change.
   - A draft PR implements this proposal for review.
   - Related: #9264, #9315, #9126, #8513.
   
   cc @Xuanwo


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to