Repository navigation
util: Port platform-file.c helpers to obs-util - #1444
Merged
Merged
Conversation
Refs obs-rust#262 (slice 3, files). rust/obs-util/src/platform_file.rs with todo!() cores and C ABI shims in ffi/platform_file.rs for os_fopen, os_wfopen, os_fgetsize, os_stat (Windows), os_fseeki64, os_ftelli64, os_fread_mbs, os_fread_utf8, the os_quick_read_*/os_quick_write_* helpers and os_get_file_size. The streams are the C library's own FILE *, opened through CFile in the platform boundary (platform/{unix,windows}/file.rs). - Tier 1 (tests/platform/platform_file.rs): 1:1 ports of test_platform_file.c and of the platform-file cases in test_platform.c. Aborts on todo!("os_quick_write_utf8_file port"). - Tier 3 (tests/platform/platform_file_parity.rs): reads, writes, NULL and missing paths, seek/tell/size, every safe-write extension combination, wide paths and (Windows) os_stat against the real platform-file.c compiled as oracle_*, with streams crossed between the sides, plus proptests over random contents. - Tier 2: ENABLE_RUST_LIBOBS=ON drops util/platform-file.c (new libobs.ported-platform group); exports in rust-exports.d/obs-util-platform_file.txt. - Oracle: the Windows forwarders for os_fopen, os_fseeki64, os_ftelli64 and os_quick_*_utf8_file leave platform_host.c, since obs-util now defines those names; os_stat is renamed oracle_os_stat on Windows for the same reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs obs-rust#262 (slice 3, files). The cores follow platform-file.c step for step over the C library's stdio: fopen/fseeko/ftello on Unix, _wfopen/_fseeki64/_ftelli64/_wstat on Windows with paths converted by the ported utf8_to_wchar, and mbstowcs/wcstombs for the _mbs_ helpers (the locale conversions of platform.c's os_mbs_to_utf8_ptr/os_utf8_to_mbs_ptr, which stay C). os_quick_write_utf8_file_safe replaces through the ported os_safe_replace and logs the same two errors. Mutation check: dropping the BOM skip, seeking back one byte off in os_fgetsize, or inverting the leading-'.' extension rule each fails Tier 1 and Tier 3 cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
swilk19
force-pushed
the
port/platform-file-rust
branch
from
October 18, 2026 22:56
ba93944 to
a3da6d0
Compare
swilk19
marked this pull request as ready for review
October 18, 2026 23:09
zackees
approved these changes
Oct 18, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM.
Checked the core against platform-file.c.h on master:
quick_write_utf8_file: the BOM and data writes have the samefwrite(…, n, 1)shapes. Early failures close the stream throughCFile'sDrop, as C'sfclosebeforereturn falsedoes, and success isfclose == 0.quick_write_mbs_file: a NULL or empty input writes nothing and succeeds, and anfclosefailure makes the call fail, as in C.quick_write_utf8_file_safe: rejects a NULL or empty temp extension, buildspath[.]extthe way the dstr code does, skips an empty backup extension, and callsos_safe_replacewith the same three arguments.fread_utf8returns nothing for an empty or BOM-only file;fgetsizerestores the position and keeps errno.
The test coverage is strong: Tier 1 ports of both C tests, and Tier 3 parity against the real platform-file.c (cross-side stream use, past-4 GiB seek, every temp/backup combination, proptests). Tier 2 drops the C file through the libobs.ported-platform group.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #262 (slice 3, files).
Follows #1443 (the verbatim move into
platform-file.c, merged).RED (
util: Test platform-file.c helpers against Rust stubs):rust/obs-util/src/platform_file.rswithtodo!()cores and C ABI shims inffi/platform_file.rsforos_fopen,os_wfopen,os_fgetsize,os_stat(Windows),os_fseeki64/os_ftelli64,os_fread_mbs/os_fread_utf8,os_quick_read_*/os_quick_write_*(incl._safe) andos_get_file_size. Aborts ontodo!("os_quick_write_utf8_file port (#262)").tests/platform/platform_file.rs): 1:1 ports oftest_platform_file.cand the platform-file cases oftest_platform.c.tests/platform/platform_file_parity.rs): reads (BOM edge cases, embedded NULs, high bytes), writes, NULL and missing paths, seek/tell/size incl. past 4 GiB, every safe-write temp/backup extension combination with and without an existing target, wide paths, andos_staton Windows, all against the realplatform-file.ccompiled asoracle_*. Streams opened by one side are read by the other, since C callers mix them with their own stdio. Proptests over random contents.ENABLE_RUST_LIBOBS=ONdropsutil/platform-file.c(newlibobs.ported-platformgroup, samelibobs-platform.pch.h); exports inrust-exports.d/obs-util-platform_file.txt.os_fopen,os_fseeki64,os_ftelli64andos_quick_*_utf8_fileleaveplatform_host.c(andci/test_oracle_standins.py), since obs-util now defines those symbols;os_statbecomesoracle_os_staton Windows for the same reason.GREEN (
util: Port platform-file.c helpers to obs-util): the streams are the C library's ownFILE *, opened through aCFiletype in the platform boundary (platform/{unix,windows}/file.rs):fopen/fseeko/ftelloon Unix;_wfopen/_fseeki64/_ftelli64/_wstat64i32on Windows (MSVC branch), with paths converted by the portedutf8_to_wchar. The cores follow the C step for step.Design note vs. my claim: I said Windows
os_fopenwould keep calling the Cos_utf8_to_wcs_ptr(slice 1). obs-util's test binaries don't linkplatform.c, so instead the platform layer calls the portedutf8_to_wchardirectly, the functionos_utf8_to_wcs_ptrwraps. The_mbs_helpers likewise dombstowcs/wcstombs+utf8_to_wchar/wchar_to_utf8privately, the wayos_mbs_to_utf8_ptr/os_utf8_to_mbs_ptrcompose them. No slice 1 symbol is exported or changed; slice 1 can later swap these private helpers for its port.Intentional differences, documented on the shims: where C would crash (a NULL
FILE *,modeorpstr, a NULL path toos_quick_write_utf8_file_safe, NULLstrwith a nonzero length), the shim returns the failure value.Local checks:
./unittestgreen: Rust Tiers 1–3, exported symbols C vs Rust IDENTICAL (1766), and 307/307 cmocka tests against bothlibobsandlibobs-with-rust.os_stat; full obs-util is 533 passed with the same 9 WSL-only failures (UNC working directory, interop process spawns) as master; obs-data 32/32.os_fgetsize, or inverting the leading-.extension rule each fails Tier 1 and Tier 3 cases.The
rust/obs-util/src/platform/windows/paths start the Windows and macOS Rust and Tier 2 lanes here.🤖 Generated with Claude Code