chitralverma opened a new pull request, #9315:
URL: https://github.com/apache/opendal/pull/9315

   # Which issue does this PR close?
   
   Closes #9264.
   
   # Rationale for this change
   
   Since #9126, `dev/src/generate/c.rs` renders the C `opendal_capability` 
struct and the Go `opendalCapability` mirror in core field order. Inserting a 
core field mid-struct therefore moves every later field. That breaks C 
positional initializers and the layout that Go reads through `libopendal_c`, 
including the copy embedded in `opendal-go-services` companion modules. On 
`main`, 54 of the 57 fields released in C binding 0.47.8 (OpenDAL v0.59.5) 
already sit at different offsets than in that release.
   
   This PR implements the append-only order agreed in #9264.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/c.rs`: `FROZEN_CAPABILITY_ORDER` lists all 98 core 
fields: the 57 released fields in their v0.59.5 order, followed by the 41 
fields added since, in core order. `frozen_order` applies this order to both 
`bindings/c/src/capability.rs` and `bindings/go/capability.go`. Generation 
fails with an error that names the field and the list when a core field is not 
listed (``new core capability `x` must be appended to FROZEN_CAPABILITY_ORDER 
in dev/src/generate/c.rs``) or when a listed field is missing from core. This 
logic is local to `c.rs`; `cpp::public_order` has the same checks, but its 
error message names `cpp.rs`.
   - Regenerated `bindings/c/src/capability.rs`, `bindings/go/capability.go`, 
and `bindings/c/include/opendal.h` (cbindgen). Only the `opendal_capability` 
field block of the header changes.
   - Tests:
     - `dev`: `test_rendered_capability_keeps_released_prefix` compares the 
rendered C struct and Go mirror field declarations (name and type) with 
literals copied from `bindings/c/src/operator_info.rs` and 
`bindings/go/types.go` at `v0.59.5`, and checks that both render every core 
field. `test_frozen_order_rejects_unlisted_core_field` and 
`test_frozen_order_rejects_missing_frozen_field` cover the two generation 
errors.
     - `bindings/c/tests/capability.cpp` (gtest, added to `GTEST_SRCS`): 
initializes `opendal_capability` by position in the released order and reads 
the fields back by name, including the size limits. A sweep then sets each of 
the 98 positions in turn and checks it against a by-name list. The first 57 
names come from the v0.59.5 header and the rest from the header order on `main`.
   - `bindings/c/upgrade.md` and `bindings/go/upgrade.md`: the existing 
*Unreleased* entries now describe the append-only layout instead of "field 
offsets changed". The C guide adds a before/after snippet for the 
`opendal_operator_info_get_capability` output pointer and recommends designated 
initializers. Both guides keep the binary-compatibility warning and the 
companion-module migration.
   
   The C/Go layout probe and the drift checks in `ci_bindings_c.yml`, 
`ci_bindings_go.yml`, and `ci_odev.yml` are unchanged.
   
   # Are there any user-facing changes?
   
   Yes, for C, Zig, and Go users upgrading from v0.59.5 (C binding 0.47.8):
   
   - The 57 released `opendal_capability` fields come first and keep their 
v0.59.5 order and offsets (checked with `offsetof` on Linux x86-64 with GCC 
13.3 and on macOS arm64). The 41 new fields follow them. Code that initializes 
the struct by position keeps its meaning when rebuilt.
   - The binary ABI still differs from v0.59.5. `sizeof(opendal_capability)` is 
152 bytes, up from 104, on both platforms, and 
`opendal_operator_info_get_capability` takes an output pointer (since #8513). C 
and Zig consumers must use a matching `opendal.h` and `libopendal_c`, and Go 
users must upgrade the binding together with their `opendal-go-services` 
companions.
   
   Compared with current (unreleased) `main`, the field order changes. A 
`libopendal_c` built from `main` before this PR does not match the Go mirror 
after it.
   
   This PR does not need its own breaking-change declaration. It adds no break 
relative to the last release; it narrows the unreleased layout change from 
#9126. The remaining ABI break is already declared for `bindings/c` by #8513 
and #9126, and their migration instructions still apply.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - Harness: Claude Code (in T3 Code) | Model: Claude Opus 5.5 
(`claude-opus-5-5`) | Effort: xhigh | Role: analyzed the released and current 
layouts, implemented the generator change, wrote the tests and upgrade notes, 
and drafted this description. The author reviews the change. Each new test was 
shown to fail under at least one deliberate code mutation:
     - swapping two released fields in the frozen list 
(`read`/`stat_with_version`, `write_multi_max_size`/`write_multi_min_size`);
     - swapping two appended fields;
     - rendering `main`'s pre-PR layout, under which the limits gtest no longer 
compiles and the other two fail;
     - removing either `frozen_order` check;
     - changing the Go template's field type.
   
     Assumption: C++ aggregate initialization in the gtest suite stands in for 
C positional initialization, because both follow declaration order. Not run: Go 
behavior tests against `opendal-go-services` companions.
   


-- 
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