Repository navigation
feat(obs-util): port utf8_to_wchar/wchar_to_utf8 (#6) - #40
Closed
b7216309-jpg wants to merge 4 commits into
Closed
b7216309-jpg wants to merge 4 commits into
b7216309-jpg wants to merge 4 commits into
Conversation
Adds the utf8_to_wchar/wchar_to_utf8 shim, two oracle wrappers, the ENABLE_RUST_LIBOBS guard and Tier 1/Tier 3 tests. The safe core bodies are todo!(), so soldr cargo test -p obs-util --test utf8 fails 0/19 and --test utf8_parity fails 0/5. Only the non-Windows implementation is ported. On Windows utf8.c wraps MultiByteToWideChar/WideCharToMultiByte on 16-bit wchar_t, so the guard keeps the C file there and the shim is cfg(not(windows)). The core is generic over the wchar_t signedness (int on x86 Linux and macOS, unsigned int on Arm Linux), which only wchar_to_utf8 observes. The oracle compiles the non-Windows branch on every platform, once with wchar_t as int32_t and once as uint32_t, so parity covers both. libobs builds with hidden visibility and utf8.c has no EXPORT, so the shims are named as local in rust-exports.map and in rust-unexports-macos.txt rather than listed in rust-exports.txt. export_list.rs now checks that every shim is exported or hidden. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the safe core of the non-Windows libobs/util/utf8.c. GREEN for the Tier 1 (19/19) and Tier 3 (5/5) utf8 tests. The decoder writes each decoded character before the surrogate and BOM checks and only advances past it when it is kept, so a dropped character stays in the buffer past the returned count, as in C. The encoder drops bit 31 of six-byte sequences, which only an unsigned wchar_t reaches, as the C byte shuffling does. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Purely random bytes almost never form a lead byte followed by enough continuation bytes, and without UTF8_IGNORE_ERROR the first invalid byte makes C and Rust both return 0. A mutation that forbade 0xf6 instead of 0xf5 therefore passed the parity test. Add inputs built from lead bytes with 0-6 continuation bytes, mixed into otherwise valid text. With them the parity test catches every non-equivalent mutation tried: wrong forbidden octets, the six-byte lead mask, advancing past a dropped surrogate, BOM skipping without the flag, and off-by-one space and truncation checks. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 9, 2026
# Conflicts: # rust/obs-c-oracle/build.rs # rust/obs-c-oracle/src/lib.rs # rust/obs-util/tests/export_list.rs
6 of 7 tasks
Contributor
Author
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 #43 (Phase 3 tracking; #6 closed when #33 merged)
Ports the non-Windows
libobs/util/utf8.c(utf8_to_wchar,wchar_to_utf8) to Rust. This is step 2 of the Phase 3 port order, after crc32.Commits
ENABLE_RUST_LIBOBSguard, and Tier 1 and Tier 3 tests against atodo!()core. Tier 1 fails 0/19 and Tier 3 fails 0/5.Decisions (also recorded in #6)
utf8.cwrapsMultiByteToWideCharandWideCharToMultiByteon 16-bitwchar_t. The guard keeps the C file on Windows ($<OR:$<NOT:ENABLE_RUST_LIBOBS>,OS_WINDOWS>), andffi::utf8iscfg(not(windows)). This follows the policy's "per-OS files are ported per OS" rule.test_utf8is alreadyNOT MSVC.wchar_tsignedness. It isinton x86 Linux and macOS andunsigned inton Arm Linux. Onlywchar_to_utf8observes it: a negative value is an error, while the same bits as an unsigned value encode as six bytes with bit 31 dropped. The core is generic over aWChartrait implemented fori32andu32, following thePositionpattern in bitstream. The shim useslibc::wchar_t.libcis a new non-Windows dependency and was already inCargo.lock.oracle/utf8_s32.candutf8_u32.c#undef _WIN32and#define wchar_tasint32_toruint32_tbefore including the unmodifiedutil/utf8.c. Parity therefore covers both signedness variants on every OS, including Windows dev machines.utf8.chas noEXPORT, so withENABLE_RUST_LIBOBS=ONthe#[no_mangle]shims would leak into the dynamic symbol table. They are named aslocal:inrust-exports.mapand inrust-unexports-macos.txt, and they are not inrust-exports.txt.export_list.rsnow requires every shim to be either exported or hidden (not both), and every hidden shim to also be in the macOS list. The policy doc has a bullet for this.test_utf8compilesutf8.cinto the test executable, as Phase 3: characterize leaf utilities and port crc32 (#6) #34 set up. It therefore still characterizes the C source and does not exercise the swap. The swap is exercised bydstr.candplatform.cinside libobs with ON. The shim itself is covered byutf8_parity::shim(NULL input,insize0, the platformwchar_t).Intentional differences
None. Characterized and kept as-is: overlong forms and code points above U+10FFFF are accepted. Counting mode (
out == NULL) skips the surrogate and BOM checks. A dropped character stays in the output buffer past the returned count.UTF8_IGNORE_ERRORalso disables the forbidden-octet check. On error, partial output is left in the buffer. Parity compares the whole output buffer (sentinel-filled), not just the return value.Mutation check
I applied nine mutations to the core. The first parity generator (random bytes, edge bytes, valid strings) missed one: forbidding
0xf6instead of0xf5. WithoutUTF8_IGNORE_ERRORthe first invalid byte makes both sides return 0, and random bytes rarely form a complete sequence. Commit 3 adds lead bytes with 0–6 continuation bytes mixed into valid text. Parity now catches all of the following:0xf6instead of0xf50xc0not forbidden0x070xf8–0xfb)Verification
On Windows 11 (MSVC):
soldr cargo test --workspace --locked: 80 passed../lintpasses.cargo clippy -p obs-util -p libobs-rust --lib -D warningsis clean forx86_64-unknown-linux-gnu,aarch64-unknown-linux-gnuandaarch64-apple-darwin. This type-checks the non-Windows shim under both signedness variants.Not verified locally
utf8_parity::shim) and Tier 2 OFF/ON, including the exported-symbol diff fromrust/tools/linux-validate/run.sh. This machine has no Docker and no WSL, so they first run in CI. I'd especially like therust-linux-tier2and macOSrust-tier2symbol diffs to confirm that thelocal:and-unexported_symbols_listentries keep the export sets identical.🤖 Generated with Claude Code