Repository navigation
obs-util: Port the window match decisions - #3156
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/rust-port-window-match-rating-an-361
branch
from
October 31, 2026 13:13
e1c40d8 to
e8d06be
Compare
Behaviour-neutral extraction before the Rust port. The pure decisions of libobs/util/windows/window-helpers.c.h move to the new libobs/util/windows/window-match.c.h, as hidden functions on C strings, bools and ints declared without EXPORT in window-match.h: - ms_window_match_is_internal_exe(): is_microsoft_internal_window_exe() and its two tables, whole (15 exact names with astrcmpi(), the prefix "windowsinternal" with astrcmpi_n(); NULL is not internal); - ms_window_match_is_untitled_explorer(): add_window()'s second skip test, explorer.exe (strcmp(), as dstr_cmp() did, NULL as "") with an empty title; - ms_window_match_is_generic_class() and ms_window_match_is_uwp_class(): is_generic_class() with its table and is_uwp_class(), whole; - ms_window_match_rating(): window_rating()'s score chain, from the priority, the two class flags, the two matches and the raw dstr_cmpi() of the titles (its abs() moves with it). add_window()'s two skip tests stay two calls, not one: the title is read between them, and only when the exe is not internal. window_rating() keeps its three reads and the three dstr_cmpi() compares in their order, and every dstr_free(). The priorities, "no match" (0x7FFFFFFF) and the 0x1000 exe penalty are named in window-match.h; window-helpers.c checks the priorities against enum window_priority with _Static_assert, since window-helpers.h includes windows.h. Everything else stays in window-helpers.c: the Win32 reads, the window walk, check_window_valid(), the UWP child swap, the best-so-far compares, the callback and the list strings. Checked in a scratch harness (not committed). It extracts origin/master's tables, is_microsoft_internal_window_exe(), add_window(), window_rating(), is_generic_class() and is_uwp_class() verbatim, and this branch's add_window() and window_rating() with the moved file, over stand-ins for the three window reads and obs_property_list_add_string() that log each call and value, and the real C dstr. It lists 59,616 windows (every internal name, upper, first-upper and alternate case, with a byte added before or after, one cut, ".foo.exe" and a UTF-8 suffix; 16 titles including NULL, empty, near misses and high bytes; 18 classes including NULL, empty, each generic and UWP name in other cases and cut short) with no callback and three, and rates 1,728 windows against 17 saved classes, 8 saved titles and 6 saved exes (NULL included) under each priority and one past the last. GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery: identical logs of 16,317,636 lines. 30 planted mutants, and the harness fails all 30: each compare made case-sensitive or not, a table entry dropped, the prefix cut short or compared whole, NULL taken as internal, the explorer test with || or without the title, the generic test as a prefix test, the demotion from or to the wrong priority, the UWP exe test negated or loosened, the penalty on the wrong side, applied to no match or as 0x100, each priority ignoring its match, abs() dropped, an unknown priority taken as a match or as the exe priority, and in the callers the title's emptiness negated, the matches or flags swapped and the title read before the exe. The new file has its own group, libobs.window-match, in the Windows sources, with a precompiled header of window-match.h, util/dstr.h, <stdlib.h> and <string.h>, so a C test can compile it on any OS; libobs-windows.pch.h includes the header for window-helpers.c. clang-cl /W4 /WX against the Windows SDK accepts both libobs.window-match and libobs.windows+. The exported symbol sets are unchanged: Linux and macOS build neither file, and on Windows the functions are not exported. git blame on the moved lines shows upstream commits by jpark37 (the shared helpers and the Chrome rule), R1CH (the internal exe list), Lain (the rating), qhy040404 (the WinUI 3 class) and derrod (SDL_app). Refs #3154. Co-authored-by: jpark37 <[email protected]> Co-authored-by: R1CH <[email protected]> Co-authored-by: Lain <[email protected]>
test_window_match_steps compiles libobs/util/windows/window-match.c.h (ASan and UBSan) and calls only its five hidden functions through window-match.h, so it needs no Windows header and runs on every platform (15 cases). It links libobs only for astrcmpi(), astrcmpi_n() and astrstri(). - the constants: the three priorities, "no match" and the penalty; - the internal exes: each of the 15 names as is, upper, first-upper and alternate case, and not with a byte before or after, one cut or a trailing space; "windowsinternal" as a prefix in any case and with a UTF-8 tail, and not one byte short or after a byte; NULL, empty, explorer.exe and other exes are not internal; - the untitled Explorer: explorer.exe with an empty title, and not with a title, cut short, padded, empty or NULL; - the generic classes: "Chrome" and "SDL_app" anywhere in any case, and not cut short or spelled apart; - the UWP classes: the two names exactly, and not in another case, cut, extended, or ApplicationFrameWindow; - the rating under each priority with the class and exe matches and title results of 0, +-1, +-200 and +-255; the generic demotion of the class priority; the UWP title-only match and its exe test; and every priority and one past the last crossed with the four flags and title results of 0, 1, -1 and 200. Characterized, not endorsed: - Explorer.exe (any case but lower) with an empty title is listed: the compare is case-sensitive, unlike the internal names; - a priority outside the three matches nothing, except a UWP window by its exact title. The class penalty cannot push a match past "no match": the largest distance astrcmpi() returns is 255, which is pinned. It is in the native test graph, in name order, on every platform, with window-match.h and its precompiled header as watch inputs. No assert_in_range or fail_msg, so it builds with cmocka 1.x and 2.x and links on Windows. Passes on the C libobs build (15/15). No real-libobs test reaches window-helpers.c: it runs only on Windows. Refs #3154.
RED for the port of libobs/util/windows/window-match.c.h to a new window_match module of rust/obs-util, next to platform_windows and dstr. The safe core is a stub (todo!()): is_internal_exe(), is_untitled_explorer(), is_generic_class(), is_uwp_class() and rating(). The constants and tables are filled in: the three priorities, NO_MATCH, EXE_PENALTY, INTERNAL_EXES_EXACT, INTERNAL_EXES_PARTIAL, GENERIC_CLASS_SUBSTRINGS, UWP_CLASSES and EXPLORER_EXE. tests/platform/window_match.rs ports test_window_match_steps 1:1: its 15 cases under the same names (steps_*), in the same order, with the same values and expectations, the characterized-not-endorsed cases included. Edge cases (edge_*) check the core against a model of the origin/master C, its expressions inline with C-locale tolower() written out: the internal-exe and untitled-Explorer tests over every listed name in four case patterns with 13 one-byte prefixes and suffixes (NUL, high bytes and the neighbours of the letters among them), every one-byte cut and every dropped byte; the class tests over "Chrome", "SDL_app" and both UWP names built the same way at offsets 0 to 4; and the rating over nine priorities (the three, their neighbours and the ends of int), the four flags and title results from -300 to 300 and at the ends of int, where the C is undefined (abs(INT_MIN), the penalty past INT_MAX) and the core wraps. Three proptests: the exe and class tests over arbitrary bytes, and the rating. The tests are a module of the obs-util library harness's platform suite; no new test binary. soldr cargo test -p obs-util --lib -- tests::platform::window_match:: passes 1 of 22 (the constants) and fails 21 with "not yet implemented". Refs #3154.
GREEN for #3154. Ports libobs/util/windows/window-match.c.h, the pure decisions of the window helpers, to the window_match module of rust/obs-util. window-helpers.c stays C around it: every Win32 call, the reads of each window's exe, title and class, the three dstr_cmpi() compares, the window walk, the best-so-far compares, the callback and the list strings. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/window_match.rs): - is_internal_exe(): astrcmpi() against the 15 exact names, then astrcmpi_n() against the prefix over its own length; None is not internal; - is_untitled_explorer(): the exe, up to its NUL, equal to "explorer.exe" byte for byte (None as empty), and an empty title; - is_generic_class(): astrstri() of "Chrome" and "SDL_app"; - is_uwp_class(): equal to one of the two class names byte for byte; - rating(): the generic demotion, then the UWP title-only match with its exe test, or the class, title or exe priority; NO_MATCH for anything else. The compares are crate::dstr's astrcmpi, astrcmpi_n and astrstri, the ports the hybrid libobs already exports, which fold ASCII only as tolower() does in the C locale. The module denies clippy's arithmetic, as, indexing, unwrap, expect, panic, todo, unimplemented and unreachable lints, and keeps no state. No intentional difference. Where the C is undefined (abs(INT_MIN), and the penalty past INT_MAX), rating() wraps; astrcmpi() returns at most 255 either way. Shims (src/ffi/window_match.rs): the five functions keep the C signatures. A NULL class, which the C's strcmp() would dereference in ms_window_match_is_uwp_class(), is not a UWP class; both callers return before asking with one. C side: the file leaves libobs.window-match for its own ported group, libobs.ported-window-match, registered in libobs/build/ported-source-sets/window-match.json for Windows, with the same precompiled header contents. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt (MSVC exports only what rust-exports.d lists, so no fragment). libobs-rust already links obs-util's ffi. ci/test_ported_sources.py checks the group is ported on Windows only. test_window_match_steps still compiles the C file into itself, unchanged. It gets no _rust variant: the shims' archive member holds the rest of obs-util, which needs libuuid, GIO and libobs's hidden base_default_log_handler, so it does not link on its own (as test_context_name_helpers); Tier 3 compares the shims with the C. soldr cargo test -p obs-util --lib -- tests::platform::window_match:: passes 22 of 22, and test_window_match_steps 15 of 15 on the C and hybrid builds. The exported symbols are identical on the Linux C, hybrid and C reference builds (1767 each), the five shims local (t). Refs #3154. Co-authored-by: jpark37 <[email protected]> Co-authored-by: R1CH <[email protected]> Co-authored-by: Lain <[email protected]>
Tier 3 for the window_match port. The oracle (rust/obs-c-oracle/oracle/window_match.c) compiles the unchanged libobs/util/windows/window-match.c.h with its five functions renamed to oracle_* and its compares on the oracle's C dstr (oracle_astrcmpi, oracle_astrcmpi_n and oracle_astrstri, which fold with C's tolower()), and gives its five constants; bound in src/window_match.rs. tests/platform/window_match_parity.rs compares the oracle, the shims and the core exactly, all three sides: - the constants; - the internal-exe and untitled-Explorer tests over every listed name, the prefix and explorer.exe in each case pattern of their first three letters, with each of the 255 one-byte suffixes, each byte dropped and each prefix cut, both title states; - every byte value (1 to 255) in every position of every listed exe, so the core's ASCII folding is shown to match C's tolower() in the C locale over all bytes; - the generic and UWP class tests over "Chrome", "SDL_app" and both UWP names built the same way, at offsets 0 to 4 with 0x80, 0xc3 or 0xff before, inside (at each position) and after them, and every byte value in every position, alone and inside other bytes; - NULL for the three tests that take it; - the rating over every priority from -1 to 4, the four flags and title results from -300 to 300, +-255 and the defined ends of int; - proptests (4,096 cases each) of the exe and class tests over arbitrary bytes and over listed names in any case between arbitrary bytes, and of the rating over any priority and title result. No intentional difference. Excluded, as the C leaves them undefined: a title result of INT_MIN (abs()) and one whose distance plus the penalty passes INT_MAX; astrcmpi() returns at most 255 in magnitude. The Tier 1 tests pin what the core does with them. A NULL class for the UWP test, which the C's strcmp() dereferences, is checked on the Rust side only. steps_internal_exact_names in the Tier 1 tests now writes out the C test's 15 names instead of reading the core's table, as the C test does, so a change to the table fails it too. Mutation check (done once, not committed); failing tests per mutant: | Mutant | Tier 1 | Tier 3 | |---|---|---| | internal: case-sensitive | 2 | 3 | | internal: prefix one byte short | 2 | 2 | | internal: prefix compared whole | 2 | 2 | | internal: None internal | 2 | 1 | | internal: time.exe changed | 1 | 3 | | explorer: case-insensitive | 2 | 3 | | explorer: \|\| title | 2 | 5 | | explorer: not cut at NUL | 1 | 0 | | generic: case-sensitive | 2 | 3 | | generic: prefix only | 2 | 3 | | uwp: case-insensitive | 2 | 3 | | uwp: prefix match | 2 | 2 | | rating: demotion from title | 4 | 1 | | rating: demotion to exe | 5 | 1 | | rating: UWP exe test negated | 3 | 1 | | rating: UWP ignores exe | 3 | 1 | | rating: penalty on exe match | 5 | 1 | | rating: penalty on no match | 4 | 1 | | rating: penalty saturating | 1 | 0 | | rating: class ignores class | 4 | 1 | | rating: title gives distance | 5 | 1 | | rating: exe ignores exe | 5 | 1 | | rating: abs dropped | 6 | 1 | | rating: abs saturating | 1 | 0 | | rating: unknown priority matches | 4 | 2 | | exact: distance 1 exact | 6 | 1 | | EXE_PENALTY + 1 | 1 | 2 | | NO_MATCH - 1 | 1 | 3 | | shim internal: None | 0 | 3 | | shim explorer: title negated | 0 | 3 | | shim generic: None | 0 | 3 | | shim uwp: NULL is UWP | 0 | 1 | | shim rating: matches swapped | 0 | 1 | | shim rating: flags swapped | 0 | 1 | All 34 are killed; the shim mutants by Tier 3, the tier that reaches the shims, and the three Tier 3 cannot reach (a NUL inside a slice, and the inputs the C leaves undefined) by Tier 1. One more, the shim keeping the string's NUL, is equivalent: the core stops every compare at the first NUL. The proptest regression files keep seeds the mutants failed on. Tier 1 and Tier 3 pass (22/22 and 11/11). At the reduced parity level the longest new test takes 0.26 s (parity_classes_every_byte); peak RSS 21 MB over 25 runs; no threads of their own. Refs #3154.
rust/README.md's port table has a row for libobs/util/windows/window-match.c.h, after platform-windows.c: the five functions (the list's two skip tests, the two class tests and the rating), what stays C in window-helpers.c (every Win32 call, the reads, the three dstr_cmpi() compares, the walk, the best-so-far compares and the list strings), the case folding and how Tier 3 checks it, what is characterized, the inputs the C leaves undefined, the null class, and the tests that cover it. The crate table's obs-util/ row (ports of libobs/util/*), the crate's description and its lib.rs module docs already cover the module, and naming.md's libobs/util/ row maps the directory to the crate. port_comparison gets benches/port_comparison/window_match.rs: 32 windows through the list's two tests, then the two class tests of a generic, a UWP and a plain saved class and every window rated under the three priorities, folded into a checksum both sides must match. Linux x86_64: Rust 2.07 us, C 3.50 us. It allocates nothing with bmalloc. No docs/features.md line: a port with no change in behaviour. Fixes #3154.
rdoupe
force-pushed
the
fix/rust-port-window-match-rating-an-361
branch
from
October 31, 2026 14:42
e8d06be to
2255fca
Compare
rdoupe
marked this pull request as ready for review
October 31, 2026 15:08
This was referenced Nov 1, 2026
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 #3154
What and why
Ports the pure decisions of the Windows window helpers (
libobs/util/windows/window-helpers.c.h) to a newwindow_matchmodule ofrust/obs-util. They decide which windows the window and game capture property lists hide (Microsoft shell and system processes, and untitled Explorer windows) and how well a window matches a capture source's saved window, which picks the window the source reattaches to when it reopens. No change in behaviour.Commits:
is_microsoft_internal_window_exe(),is_generic_class()andis_uwp_class()with their tables,add_window()'s untitled-Explorer test andwindow_rating()'s score chain move tolibobs/util/windows/window-match.c.h, as hidden functions on C strings, bools and ints.window_rating()keeps its three reads and its threedstr_cmpi()compares;add_window()keeps its two skip tests as two calls, since the title is read between them. Checked with a scratch harness against origin/master's code over stand-ins for the window reads (GCC and Clang, -O0/-O2, with and without ASan/UBSan: identical logs of 16.3M lines; 30 planted mutants, all caught). clang-cl /W4 /WX against the Windows SDK acceptslibobs.windows+and the new group.test_window_match_steps(cmocka, every OS, 15 cases).obs_util::window_matchTier 1 againsttodo!().src/ffi/window_match.rs, inlibobs.ported-window-match(Windows). The shims are hidden (rust-hidden.txt, rust-exports.map local:, rust-unexports-macos.txt).tolower(); the rating over every priority from -1 to 4, the flags and title results), with a mutation check: 34 mutants killed, one equivalent.port_comparisonbench (Rust 2.07 µs, C 3.50 µs).No intentional difference. Characterized, not endorsed:
Explorer.exe(any case but lower) with an empty title is listed, and a priority outside the three matches nothing but a UWP window by its exact title.test_window_match_stepshas no_rustvariant: obs-util's archive member needs libuuid, GIO and libobs's hidden log handler, so it does not link on its own (astest_context_name_helpers); Tier 3 compares the shims instead.Upstream authors of the moved code (jpark37, R1CH, Lain) keep their credit on the commits; qhy040404 and derrod wrote the WinUI 3 and SDL_app rules. No upstream issue.
Test cost: new tests (22 Tier 1, 11 Tier 3) at the reduced parity level: longest 0.26 s (
parity_classes_every_byte), peak RSS 21 MB over 25 runs, no threads of their own.RED → GREEN
soldr cargo test -p obs-util --lib -- tests::platform::window_match::passes 1 of 22 (the constants) and fails 21 with "not yet implemented";--test-diff origin/masteron it: 5,580 passed, the same 21 failed, 6 skipped;--lane lintpasses.test_window_match_steps1/1 under ctest on the C build, hybrid libobs and libobs-c-reference (15/15 cases each). Exported symbols identical on the Linux C, hybrid and C reference builds (1767 each), the five shims local.--test-diff origin/master: 5,612 passed, 6 skipped;./unittest's Rust tiers 5,637 and 895 passed, 6 skipped;./lint,--lane lintand--lane crosspass; theport_comparisonbench test passes;soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets -- -D warningsis clean. Runs were on e8d06be (test-diff on the same commits before the rebase onto d811d41); after the rebase onto 1b3a74f, Tier 1 and Tier 3, Tier 2 on all three builds, the export comparison, the bench test and--lane lintwere rerun on 2255fca. Tier 2 ran natively with ctest: Docker is not available on the build host, so./unittest's Docker Tier 2 lane and the local-gate stamp could not run, and the head is unstamped.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable