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

   # Which issue does this PR close?
   
   Part of #9323 (tracker #9320).
   
   # Rationale for this change
   
   #9335 generated the C and Go `ListOptions` from core. This PR generates 
`StatOptions` the same way, with the same table, templates, and tests. It 
exposes no new option: core's `if_version_match`, `if_version_not_match`, and 
`checksum` keep their defaults in the conversion, and the other C and Go option 
structs stay hand-written.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/c/options.rs`: the released-options table gains 
`StatOptions` in its C member order. Two new representations record today's 
encodings:
     - `BorrowedString` for all six stat strings: a `const char *` that the 
setter stores without copying and `_free` does not free. Go skips an empty 
string and keeps the bytes it passed alive until the C call returns. List 
`start_after` stays `OwnedString`: the setter copies it, and `_free` frees it.
     - `FlaggedMillis` for the two timestamps: a `has_<name>` `bool` followed 
by an `int64_t` of Unix milliseconds. The setter sets both. The conversion 
fails with `OPENDAL_CONFIG_INVALID` when the value is out of range. Go passes 
`UnixMilli()`.
     - The table also records each released Go parameter name, such as `t` for 
the two times, so `go doc` output stays the same. As for list, generation fails 
when a released field leaves core or changes its kind.
   - Docs come from core. Each member, setter, and Go option carries the 
field's full core doc comment, and the struct and `WithStatFn` carry the 
struct's.
     - The C/Go generator renders a `crate::ErrorKind::X` code span as the C 
`opendal_code` value, such as `OPENDAL_NOT_FOUND`. In Go it renders the span as 
the way callers check it, such as "an `*Error` whose `Code()` is 
`CodeNotFound`", the wording #9349 uses for `WithListFn`. The generator reads 
the C names from `bindings/c/src/error.rs` and the Go names from the order of 
the Go `ErrorCode` constants, so Go keeps the released `CodePermissioDenied` 
spelling. The mapping covers the whole generator, so the one such span in the 
`ListOptions` struct doc changes too; its Go line matches #9349's output.
     - `dev/src/generate/rustdoc.rs`: a reference link such as `[conditional 
operation specification][crate::docs::specs::conditional_operations]` keeps 
only its label. No other generator's output changes.
     - The generator adds what core cannot state: unset values, who owns each 
string (including list `start_after`), the `has_*` flags, and the out-of-range 
error. Generation fails if a C doc line would open or close a C comment.
   - C: the generated file holds `opendal_stat_options`, `_new`, the eight 
`_set_*` functions, `_free`, and a crate-private `unsafe fn to_core(&self) -> 
opendal::Result<options::StatOptions>`. That function replaces the safe 
`TryFrom` impl, which read the raw string pointers. Its `# Safety` section 
requires each non-null string to be a readable, nul-terminated C string for the 
duration of the copy. `opendal_operator_stat_with_cancel` and 
`opendal_operator_presign_stat_with_cancel` call it under that caller contract. 
`optional_timestamp` stays in `types.rs`, which still uses it for read options, 
and becomes `pub(crate)`. The Go generated-code check skips `cargo fmt`, so the 
generator lays out the conversion as rustfmt does.
   - Go: `WithStatFn`, the eight `StatWith*` options, `statOptions`, 
`parseStatOptions`, `newOpendalStatOptions`, and the stat option FFI 
declarations move from `stat.go` to the generated `options.go`. They keep the 
same signatures, private field names, empty-string and nil handling, and 
returned keep-alive slices.
   - Tests pin the API and behavior, not doc text:
     - `bindings/c/tests/stat.cpp` (new): `static_assert`s pin the ten member 
types, the 64-bit `sizeof` (80) and offsets, and the ten prototypes, all copied 
from `opendal.h` on `main`. A brace-initialization check pins exactly ten 
members. At runtime, the string setters must store the caller's pointer. The 
test passes stack strings, so a `free` of one fails under ASan. The timestamp 
setters must set `has_*`. On a memory operator, stat succeeds with no options 
and with the three overrides, and the version and each condition fail with 
`OPENDAL_UNSUPPORTED`.
     - `bindings/c/src/types.rs`: `test_stat_options_to_core` checks the 
defaults, every setter through the conversion (including the three defaulted 
core fields), and that `_free` leaves the borrowed strings alone. The existing 
out-of-range timestamp test calls `to_core` in place of `try_from` and keeps 
its assertions.
     - `bindings/go/options_test.go`: compile-time assignments pin `WithStatFn` 
and the eight `StatWith*` signatures from `main`, and a test requires exactly 
these eight exported `StatWith*` functions. A memory operator stats through the 
live C library. No options, the overrides, and empty strings succeed. The 
version and each condition fail with `CodeUnsupported`, and an out-of-range 
time fails with `CodeConfigInvalid`. A stub test checks that each option 
reaches its C setter with its value, that times arrive in Unix milliseconds, 
and that empty strings reach no setter.
     - `dev`: generator tests cover core docs on every stat member and Go 
option, error-kind, capability, and field names (every name must exist in 
`opendal.h`, `capability.go`, or `error.go`), the ownership notes, the 
defaulted stat fields, removed or retyped stat fields, the comment guard, the 
error-code position mapping, reference links, and the conversion layout. The 
layout expectations are rustfmt 1.9 output, including the 60-column 
call-argument limit.
   
   Each new test fails under a mutation:
   
   - `tests/stat.cpp` fails when `if_match` and `if_none_match` swap in the 
table (offsets), when `version` becomes a copied string (member type), when the 
table gains `checksum` (member count and `sizeof`), when the timestamp setters 
stop setting `has_*`, and when `opendal_stat_options_set_version` copies while 
keeping its `const char *` type (stored pointer).
   - `test_stat_options_to_core` fails in the last two cases.
   - `options_test.go` fails when `StatWithIfModifiedSince` takes `*time.Time` 
while the package still builds (signatures), when the table gains `checksum` 
(exported set), when empty strings reach C (memory stat), when the 
`override_content_type` setter call is dropped (stub), and when times pass 
`Unix()` instead of `UnixMilli()` (stub and out-of-range memory stat).
   - `dev` tests fail when the kind check is skipped, when Go codes are spelled 
from the kind name instead of the C order, when C or Go leaves error kinds as 
Rust paths, when reference links keep their target, when the comment guard is 
off, when the call-width limit is 61, when `unsafe { … }` stays on one line, 
when a borrowed member's note says the setter copies, and when borrowed members 
lose their core doc.
   
   # Are there any user-facing changes?
   
   Doc comments only. No API or ABI change, and no behavior change except one 
panic message.
   
   - C and Zig: in `opendal.h`, every struct and enum definition is identical 
to `main` once comments are removed, and so is every prototype. The only other 
difference is where the ten `opendal_stat_options_*` prototypes sit. cbindgen 
writes functions in module order, so they now follow the 
`opendal_list_options_*` prototypes from the generated module, with `_free` 
last, instead of the write option functions. Sorted, the comment-free lines of 
both headers are identical. Changed doc comments: `opendal_list_options` and 
its `start_after` member, and `opendal_stat_options`, its members other than 
the `has_*` flags, and its ten functions. `opendal_stat_options` is 80 bytes 
with unchanged offsets on macOS arm64 and on Linux x86-64 and arm64.
   - A C program compiled with `-Wall -Wextra -Werror` against `main`'s header 
prints the same output on macOS arm64 with `main`'s library and with this 
branch's library. It prints the size and offsets, initializes the struct by 
position and by designators, calls every setter (including NULL options and 
unset), checks that `version` is stored by pointer and survives `_free`, and 
stats a memory operator with each option, including the `UNSUPPORTED` and 
`CONFIG_INVALID` errors.
   - A stat string that is not valid UTF-8 still panics, and the panic still 
aborts the process because it cannot unwind through `extern "C"`. The message 
now names the field, `malformed version: …`, where it said `malformed option: 
…`.
   - Go: `go doc -short` is identical to `main`. `go doc -all` has the same 
declarations, and its doc text differs for `WithListFn`, `WithStatFn`, and the 
eight `StatWith*` options. `main`'s Go package passes its 79 tests against this 
branch's library, and this branch's Go package passes its 82 tests (`main`'s 79 
plus 3 new) against `main`'s library. The existing test files are unchanged.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - **Harness:** Claude Code via T3 Code | **Model:** Claude Opus 5.5 | 
**Effort:** xhigh | **Role:** Implemented the generator, templates, and tests. 
Ran the surface diffs, compatibility probes, mutation checks, and the C, Go, 
Zig, and `odev` CI steps on macOS arm64 and in Linux containers. Did not run 
the Go behavior tests, which need an `opendal-go-services` checkout. Drafted 
this description. The human author reviews the change and is responsible for it.
   


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