Repository navigation
util: Port dstr-libc to obs-util - #1857
Merged
Merged
Conversation
test_dstr_libc pins what libobs/util/dstr-libc.c does today for the functions test_dstr never calls: wstrcmpi, wstrcmp_n, wstrcmpi_n, wstrstri and wcsdepad (NULL as the empty string, n == 0, an empty needle, only space/tab/CR/LF as padding), dstr_to_wcs/dstr_from_wcs over 2-, 3- and 4-byte UTF-8, dstr_from_mbs/dstr_to_mbs on ASCII and NULL, and dstr_to_upper/dstr_to_lower on ASCII and on a dstr whose first byte is NUL. Case mapping stays ASCII, the part every C locale maps alike. Registered in the native test graph like test_dstr. Refs #1846
rust/obs-util/src/dstr_libc.rs holds the safe core with todo!() bodies:
the wide compares (wstrcmpi, wstrcmp_n, wstrcmpi_n), wstrstri, wcsdepad
and the case-mapping loops of dstr_to_upper/dstr_to_lower, over
NUL-terminated slices of the host wchar_t. Case mapping calls the C
library's towupper/towlower, added to platform::crt.
ffi/dstr_libc.rs is the C ABI shim for the eleven non-variadic EXPORTs
(rust-exports.d/obs-util-dstr_libc.txt). The conversions call what the C
calls: os_mbs_to_utf8_ptr/os_utf8_to_wcs_ptr (still C,
platform-conversions.c; the oracle's platform_host.c now forwards the
plain names off Windows too), the ported wchar_to_utf8, and the dstr.h
inlines.
The variadic dstr_printf/dstr_catf/dstr_vprintf/dstr_vcatf are copied
verbatim to util/dstr-variadic.c.h in libobs.rust-variadic, as
base-variadic.c.h is. dstr-libc.c.h moves to libobs.ported-util, so the
C reference still compiles all of it; the libobs.util-libc group is gone.
Tier 1 (tests/strings/dstr_libc.rs) ports test_dstr_libc.c and
test_dstr_case: 8 cases fail on todo!("dstr-libc port"), and
test_dstr_case aborts the harness (the todo!() panics inside an extern
"C" shim). The conversion cases already pass: their shims are only the
C's calls.
Refs #1855
Refs #1846
The core follows dstr-libc.c step for step over NUL-terminated slices of the host wchar_t: one compare loop for wstrcmpi, wstrcmp_n and wstrcmpi_n (map, compare, then `*str1++ && *str2++ && --n`), wstrstri trying every offset up to the terminator, wcsdepad moving the string down and zeroing trailing space/tab/CR/LF, and the towupper/towlower loops. A slice without a 0 reads as if one followed it, so no input can index out of bounds. - Tier 1 (tests/strings/dstr_libc.rs): all 16 cases pass. - Tier 3 (dstr_libc_parity.rs): proptest against the oracle's oracle_* dstr-libc on wide strings with ASCII, padding and near misses, cased Latin-1/Greek and any value up to U+10FFFF, NULL pointers, and dstr conversions/case maps over arbitrary UTF-8 and bytes (array, bytes, len, capacity). Mutation check: testing `n` before the decrement, or dropping '\r' from the padding set, fails it. - port_comparison gains dstr/to_upper. No intentional differences. Fixes #1855 Refs #1846
This was referenced Oct 23, 2026
zackees
marked this pull request as ready for review
October 23, 2026 02:46
6 of 7 tasks
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.
Fixes #1855
Refs #1846
Unit 2 of #1846:
libobs/util/dstr-libc.c.htoobs-util.Commits
test/cmocka/test_dstr_libc.c(wide helpers, conversions, NULL handling), registered in the native test graph.todo!(), C ABI shim, export fragmentrust-exports.d/obs-util-dstr_libc.txt,dstr-libc.c.hmoved tolibobs.ported-util(thelibobs.util-libcgroup is gone), variadic printf copied verbatim toutil/dstr-variadic.c.hinlibobs.rust-variadic(asbase-variadic.c.h; the C reference still compiles all ofdstr-libc.c.h). Tier 1: 8 cases failed ontodo!("dstr-libc port"),test_dstr_caseaborted the harness (panic inside an extern "C" shim); the conversion cases already passed (their shims are only the C's calls).Tiers
tests/strings/dstr_libc.rs, 16 cases, pass.test_dstrandtest_dstr_libcrun unchanged against hybrid libobs and the C reference.tests/strings/dstr_libc_parity.rs, proptest vs the oracle (wide strings incl. non-ASCII and values up to U+10FFFF, NULLs, arbitrary UTF-8/bytes through the conversions and case maps). Mutation check: checkingnbefore the decrement, or dropping'\r'from the padding set, fails it.Case mapping calls the C library's
towupper/towlower(platform::crt).os_mbs_to_utf8_ptr/os_utf8_to_wcs_ptrstay C (unit 1 of #1846) and are called throughextern "C"; the oracle'splatform_host.cnow forwards them off Windows for cargo tests.No intentional differences. Characterized, not endorsed:
dstr_to_mbsusesos_mbs_to_utf8_ptr, as the C does.port_comparison (x86_64 Linux,
soldr cargo bench -p obs-c-oracle --bench port_comparison -- dstr/to_upper)Both sides do the same os_utf8_to_wcs_ptr (C) round trip; the Rust side goes through the ported
wchar_to_utf8and one extra NUL scan.