Repository navigation
obs-util: Port the window setting's string codec - #3386
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/rust-port-the-window-setting-s-s-422
branch
from
November 1, 2026 09:53
103b165 to
b0f6462
Compare
Behaviour-neutral extraction before the Rust port. Window and game capture save the chosen window as "title:class:exe", each part escaped. The codec's core moves from libobs/util/windows/window-helpers.c.h to libobs/util/windows/window-match.c.h, as three hidden functions declared without EXPORT in window-match.h: - ms_window_match_encode(): encode_dstr()'s two dstr_replace() passes, '#' to "#22", then ':' to "#3A", as one pass over the bytes (the second pass never met a ':' the first wrote), snprintf-style: it returns the escaped length and writes only when out is not NULL; - ms_window_match_decode(): decode_str()'s two passes in place, "#3A" to ':', then "#22" to '#', each left to right and never into what it wrote ("#2222" stays "#22"); it returns the new length; - ms_window_match_split(): strlist_split(str, ':', true)'s first three fields as offsets and lengths, false with fewer than three. window-helpers.c keeps every allocation: encode_dstr() sizes the string, bmalloc()s it, fills it and moves it into the dstr only when the length changed, so an empty dstr keeps its NULL array as dstr_replace() did. decode_str() copies a field with dstr_ncopy(), which gives NULL for an empty field as dstr_copy("") did, and decodes it. ms_build_window_strings() keeps its NULL outputs, its NULL-string return and its three decodes in order; the strlist allocation goes. add_window()'s description and join are unchanged. Checked in a scratch harness (not committed). It extracts origin/master's encode_dstr(), decode_str(), ms_build_window_strings() and add_window()'s string building verbatim, and this branch's with the moved file, over the real C dstr and bmem. It runs 299,614 strings (NULL, every string up to 6 bytes over "#:23Aax" and 0xC3, and 20 picked ones such as "#2222", "##3A22", "x#3a", "a:b:c:d" and high bytes) through the split, the encode of a dstr, the window list's description and join, and the split and decode of that join; an empty dstr and empty join parts too. Each output and each dstr length is logged. GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery: identical logs of 3,894,989 lines and no leaks. 23 planted mutants; the harness kills 21: each escape or its order changed or dropped, the NUL left out, a decode pass at the end of the string missed, a pass resuming inside its match, the passes swapped or the second dropped, lower-case "#3a" decoded, too few fields accepted, a field one byte long, the split from the last ':', and in the callers the empty-dstr shortcut, dstr_ncopy() replaced by a copy that keeps "", the decode dropped, the fields swapped or one too long, and an output left unset. The two it cannot see are equivalent: a write of the last byte, which the NUL then overwrites, and the NULL-string return, which the split also makes. Refs #3380.
test_window_match_steps pins the moved codec of the saved window string before the port: the encode of NULL, plain, '#', ':' and high bytes, its snprintf-style length and truncation; the decode of each escape, "#3A" before "#22" with each pass once ("#2222" is "#22", "#223A" is "#3A", "##3A22" is "#:22"), lower-case "#3a" left alone and NULL; the split of NULL, "", ":", "a:b", "::", ":::", "a:b:c:d" and empty fields, with all six outputs 0 when it fails; and the round trip of add_window()'s join through the split and decode for 169 triples of titles, classes and exes holding '#', ':' and both. Refs #3380.
Tier 1 for the codec of the saved window string, against todo!() stubs: encode(), encoded_len(), encode_into(), decode() and split() in obs_util::window_match. The five new cases of test_window_match_steps are ported 1:1 as steps_encode, steps_encode_truncates, steps_decode, steps_split and steps_round_trip. New edge cases compare the core with a model of origin/master's C (encode_dstr() and decode_str() as two dstr_replace() passes each, the split as strlist_split(str, ':', true)): every string up to 5 bytes over "#:23Aa", NUL and 0xC3, and a proptest over strings rich in '#', ':', '2', '3' and 'A', with the window list's join round-tripped. The three shims in src/ffi/window_match.rs come with them, hidden (rust-hidden.d), so the hybrid libobs on Windows links at every commit; the oracle renames the moved functions to oracle_* so they link next to the shims. Refs #3380.
The codec of the saved window string in obs_util::window_match: encode() and encoded_len() map '#' to "#22" and ':' to "#3A" byte by byte, which is what encode_dstr()'s two passes do (the second never meets a ':' the first wrote); encode_into() is the snprintf-style ms_window_match_encode(); decode() runs the two passes of ms_window_match_decode() in place, "#3A" then "#22", each left to right with a NUL after its result; split() gives the first three ':'-separated fields, empty ones kept. Each reads its input up to the first NUL, as the C does, and works on bytes, not UTF-8. Nothing here can panic or allocate except encode(). The shims, already in place, now reach a real core. Tier 1 passes (29 of 29). Refs #3380.
Tier 3 for the codec: oracle (the moved window-match.c.h), shims and core over NULL, 19 picked strings, and every string up to 5 bytes over "#:23Aa", 0xC3 and 0x01 (all up to 3 bytes at every level, a share of the longer ones at the reduced level). Each encode runs with a NULL buffer and at every size from 0 to two past the escaped length, and the whole buffer is compared; each decode compares the whole buffer, the bytes past the new NUL included; each split compares all six outputs, prefilled. Proptests run strings rich in '#', ':', '2', '3' and 'A', and the window list's title:class:exe round trip through the shims. No intentional difference. Mutation check: 10 mutants of the core, each killed by these tests (each escape changed, the decode passes swapped, a match needing a fourth byte or resuming inside itself, no NUL after a pass, a write past the room, two fields accepted, a field start off by one, and the measured length unescaped). The port_comparison bench gets a window_match/codec/32 pair: each window's saved string built, split and decoded in stack buffers. Refs #3380.
The rust/README.md row of window-match.c.h and the window_match module docs name the codec of the saved window string: what it encodes and decodes, in which order, what window-helpers.c keeps, and that it works on bytes. naming.md already maps libobs/util/ to obs-util, and obs-util's description and lib.rs list no module detail. Fixes #3380.
test_window_match_steps_rust builds the unchanged
test_window_match_steps.c against libobs_rust-static, so the C test
runs the Rust shims of all eight window match functions, the codec
included, not only the C it compiles in. The functions are hidden in
libobs, so the executable takes them from the production staticlib.
obs-util's archive member also needs libuuid, GIO, glib and libobs's
hidden base_default_log_handler() and base_log_literal(): the test
links the first three and compiles its own util/base-variadic.c, as
test_effect_param_types_steps_rust does with its adapters.
Hybrid backend and Linux only. On macOS and Windows obs-util's member
pulls in other host code, and no PR lane builds this test there to
check that link; the Tier 3 parity tests compare the same shims with
the C on every host.
Checked: 20 of 20 pass, and a planted Rust mutant ('#' escaped as
"#23") fails encode, encode_truncates and round_trip.
Refs #3380.
rdoupe
force-pushed
the
fix/rust-port-the-window-setting-s-s-422
branch
from
November 1, 2026 10:35
b0f6462 to
cfb8d69
Compare
rdoupe
marked this pull request as ready for review
November 1, 2026 11:01
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 #3380
What and why
Window capture and game capture on Windows save the chosen window as one string,
title:class:exe, with each part escaped (#as#22, then:as#3A). When a source loads,ms_build_window_strings()splits that string and decodes each part. This PR ports that codec toobs_util::window_match, the module that already holds the window helpers' match decisions (#3156). Nothing changes in behaviour.libobs: Move the window setting's string codec): the codec's core moves out oflibobs/util/windows/window-helpers.c.hintolibobs/util/windows/window-match.c.h(grouplibobs.ported-window-match), as three hidden functions declared inwindow-match.h:ms_window_match_encode()(snprintf-style),ms_window_match_decode()(in place) andms_window_match_split()(the first three fields as offsets and lengths).window-helpers.ckeeps every allocation anddstr_*call,add_window()'s description and join, andinsert_preserved_val()andms_check_window_property_setting()with their property-list calls.ms_build_window_strings()stays EXPORT, and its outputs stay exactly as they were: all three NULL for a NULL string or fewer than three fields, and NULL for an empty field (dstr_ncopy(), like thedstr_copy("")it replaces).test: Characterize the window string codec):test_window_match_stepsgets five new cases. They cover the encode and its truncation, the decode order (#2222is#22,#223Ais#3A, and lower-case#3astays as it is), the split of"",":","a:b","::",":::"and"a:b:c:d", and a round trip of 169 title/class/exe triples.obs-util: Test the window string codec): Tier 1 tests againsttodo!()stubs. The shims and theirrust-hidden.dnames come in this commit too, so the hybrid Windows libobs links at every commit.obs-util: Port the window string codec):encode(),encoded_len(),encode_into(),decode()andsplit()inobs_util::window_match, on bytes, reading each string up to its first NUL as the C does.obs-util: Compare the window string codec with C): the oracle, shims and core are compared over NULL, 19 hand-picked strings, every string up to 5 bytes over#:23Aa, 0xC3 and 0x01, and proptests, including the round trip of the window list's string through the shims. Each encode is checked at every buffer size. Each decode compares the whole buffer, including the bytes after the new NUL. Each split compares all six outputs. Awindow_match/codec/32pair is added to theport_comparisonbench.docs: Document the window string codec port): therust/README.mdrow and the module docs.naming.mdalready mapslibobs/util/toobs-util.The move was checked in a scratch harness. It extracts origin/master's
encode_dstr(),decode_str(),ms_build_window_strings()andadd_window()'s string building verbatim, and runs them next to this branch's versions over the real C dstr, on 299,614 strings (NULL, every string up to 6 bytes over#:23Aaxand 0xC3, and 20 hand-picked ones). It ran under GCC and Clang, at -O0 and -O2, with and without ASan/UBSan: the logs (3,894,989 lines) were identical and nothing leaked. Of 23 planted mutants it caught 21. The other two are equivalent: one writes the last byte, which the NUL then overwrites, and the other drops a NULL-string return that the split already makes.No intentional difference. Mutation check: the Tier 3 tests catch all 10 mutants of the Rust core (each escape changed, the decode passes swapped, a match that needs a fourth byte or restarts inside itself, no NUL after a pass, a write past the room, a split that accepts two fields, a field start off by one, and the measured length left unescaped).
test: Run the window match steps against Rust):test_window_match_steps_rustbuilds the unchanged C test againstlibobs_rust-static, so it runs the Rust shims of all eight window match functions. obs-util's archive member also needs libuuid, GIO and two log helpers that libobs hides, so the test links the libraries and compiles its ownutil/base-variadic.c, the same waytest_effect_param_types_steps_rustcompiles its adapters. It runs on Linux only: on macOS and Windows that archive member pulls in other host code, and no PR lane builds this test there to check the link. Tier 3 compares the same shims with the C on every host.No upstream issue.
RED → GREEN
soldr cargo test -p obs-util --lib -- platform::window_match::fails 7 tests withnot yet implemented:steps_encode,steps_encode_truncates,steps_decode,steps_split,steps_round_trip,edge_codec_against_modelandedge_prop_codec. The other 22 pass. On RED,local_gate.py --test-diff origin/masterfailed only those 7 (5966 passed, 6 skipped), and--lane lintpassed.soldr cargo test -p obs-util --lib -- platform::window_match).local_gate.py --test-diff origin/masterran 5978 tests: 5978 passed, 6 skipped (the same 6 skip on RED).--lane lintand--lane crosspass, and so doessoldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets -- -D warnings. Tier 2:test_window_match_stepspasses 20/20 against the C build, hybrid libobs andlibobs-c-reference(rebuilt for the run).test_window_match_steps_rustpasses 20/20 against the Rust shims. A planted Rust mutant (#escaped as#23) makes it failencode,encode_truncatesandround_trip. The exported symbol sets are identical on the C, hybrid and c-ref builds (1,767 each), and the three new shims are local (t) in hybrid libobs. The moved C and the new test compile clean with clang-cl/W4 /WXfor MSVC, andwindow-helpers.c.hcompiles with clang-cl and mingw.port_comparisonpasses its allocation check. Runs were on cfb8d69, rebased onto master 93b3ec2:./lint,--lane lint,--lane cross, MSVC clippy and the bench pass../unittest's Rust tiers ran 6056 tests: 6056 passed, 6 skipped. Its Docker Tier 2 lane can't reach Docker on this host, so Tier 2 ran natively with ctest, as above.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)