Skip to content

obs-hotkey: swap hotkey-combination background-id query to safe Rust (Refs #5288) - #5325

Merged
rdoupe merged 2 commits into
masterfrom
port/5288-hotkey-combination-background-id
Nov 20, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/5288-hotkey-combination-background-id

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #5288.

Swap only obs_hotkey_combination_get_background_id into obs-hotkey. Safe Rust takes the existing hotkey mutex, reads the backend's shortcut_id callback while holding it, releases the lock and only then calls the saved callback, exactly once, with the combination by value and an empty dstr. A failed lock returns NULL with no field read. A missing callback or a false result frees the partial dstr and returns NULL. A true result hands id.array to the caller unchanged, including NULL and an allocated empty string, so the caller's bfree always matches the callback's allocator. The mutex, the callback slot and dstr_free stay in C behind four private adapters (libobs/obs-hotkey-combination-background-id-fields.c.h, in the core group). The original wrapper moves to the libobs.ported-hotkey-combination-background-id group, which builds the C reference only. There it gets its static lock/unlock pair from the existing hotkey seam (obs-hotkey-combination-background-id-lock.c.h). The extracted file only changes its comment, so the unchanged C test and the standalone hotkey fixtures still compile it as before.

The hazard the issue names: background_query_parity.rs defined a same-named fake of this getter. Now that the real getter is defined in the same crate, the fake is gone. That test drives the real getter on the shared recording fixture instead. The status fake (obs_hotkeys_get_background_state) stays until the background-state swap (#5259) lands.

Tests:

  • Tier 1 mirrors every assertion of the unchanged test_hotkey_combination_background_id.c (from libobs: characterize and extract hotkey combination background id (Refs #5275) #5287) against the safe core: the nine cases for each of the three combinations, the L/R/U/C/F traces, the counters, exact ownership transfer, NULL on callback success, and reentry.
  • Tier 3 runs the original extracted C and the shim on one recording fixture through the same real-named adapters. It compares the full trace, the returned pointer and text, and a check that every non-transferred allocation is freed exactly once. It also covers the original's traces against the characterization, real-header dstr/obs_key_combination_t/callback-slot layout, edge cases and proptest.
  • Mutation cases cover six broken versions: a call under the lock, a read after unlock, a leaked partial id, a dropped result, a read after a failed lock and an altered combination.

Evidence

RED (1bcf2a898, the safe core is a stub that returns None):

soldr cargo test -p obs-data --test obs-tests-core -- hotkey::combination_background_id hotkey::background_query
test result: FAILED. 4 passed; 6 failed

GREEN (4e1699e9c, on 3b8563940):

soldr cargo test -p obs-data --test obs-tests-core -- hotkey::combination_background_id hotkey::background_query
test result: ok. 10 passed; 0 failed

soldr cargo test -p obs-data --test obs-tests-core
test result: ok. 6173 passed; 0 failed; 5 ignored

soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build::
test result: ok. 323 passed; 0 failed

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'hotkey|portal_shortcuts|wayland_hotkeys'
libobs exported symbols, C vs Rust: IDENTICAL (1769 symbols)
100% tests passed, 0 tests failed out of 1044   (hybrid libobs and C reference, each; every *_rust target built)
100% tests passed, 0 tests failed out of 44     (repeat pass of the hotkey tests, ON and OFF)
test_hotkey_combination_background_id ... Passed (all four runs)

uv run --no-project ci/windows_link_check.py      exit 0 (Tier 2 win-x64 and mac-arm64 links)

./lint                                            lane lint: ok

The change has no user-visible effect, so it adds no features-ledger line. Native Windows/macOS execution is not claimed.

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 19, 2026 20:52
…Refs #5288)

Tier 1 mirrors every assertion of the unchanged
test_hotkey_combination_background_id.c against the safe query. Tier 3
runs the extracted original and the shim on one recording fixture through
the new real-named lock, callback-slot, unlock and dstr_free adapters, with
six mutants. background_query_parity drops its same-named fake getter and
drives the real getter on that fixture instead.

The safe query is a stub that returns None:

    soldr cargo test -p obs-data --test obs-tests-core -- hotkey::combination_background_id hotkey::background_query
    test result: FAILED. 4 passed; 6 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(Refs #5288)

obs_hotkey_combination_get_background_id now comes from obs-hotkey in the
hybrid libobs. Safe Rust takes the existing hotkey mutex, captures the
backend's shortcut_id callback, releases the lock and only then calls the
saved callback once with the combination by value. A failed lock returns
NULL with no field read; a missing callback or a false result frees the
partial dstr and returns NULL; a true result transfers id.array unchanged.
The mutex, callback slot and dstr_free stay in C behind private adapters.
The original wrapper moves to libobs.ported-hotkey-combination-background-id,
which gives it its static lock pair through the existing seam.

    soldr cargo test -p obs-data --test obs-tests-core -- hotkey::combination_background_id hotkey::background_query
    test result: ok. 10 passed; 0 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ci-Attestation: {"at":1795141142,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":94,"stamp":"dae2b56ee79163274b0b3f9c597495bf","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141142,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":94,"stamp":"64dadec6784a44b6b04a04b11175fd85","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141142,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":94,"stamp":"63eeff4d6503b5e0bf71081f3a916378","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141142,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":94,"stamp":"c553f39cc407a25f59f79cfded9542f1","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"general/all/client-lint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"1fa72d8b2329b0c0b960fb2a4d389559","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141142,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":94,"stamp":"b95bfa8d10cb18f27474db7d9f9fbdd6","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"3c29b023b1aba9c71d4e0d240f4c4c1c","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"68a93310b322d57de61f713576074ed6","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"4f4833965661898ec04cee56eda48f90","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"f1f22e63a4ab31a5588cc91a64694afd","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"923ab93b6ee188ec99c42df526f4e6ad","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"460214df84df78bd764d87b4708876c7","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"ae4245f056e3477a35e8ca9de2e728f6","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"15552ab23b2a9cabf588eaf83ff11702","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"5b7d41956b8148dd31022c9284f24005","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"d5cff465fef4180d3508352bf042e701","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"45496753a706a23275e544311d4afbfc","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141047,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"8237acc3dd2eeb6c241b8077be33f3e8eaf869884058d8f0c801ef7659da4329","lane":"client-lint","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":63,"stamp":"d8452b7d0f552c98d074c51d561c234b","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}
Ci-Attestation: {"at":1795141366,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"b2087d1d1f640d75467108e499b87897e52d9b8d8227fb8a6f2907a94f11b2af","lane":"client-test-x86_64-unknown-linux-gnu","parents":["1bcf2a898d96a1c7bfdfe065d38e814718bcd829"],"secs":224,"stamp":"0969529f982fd5c9af60ff84a18ee586","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"869cc329a4d9053ba424088d01b05b6bb695bcad","coverage":"all-tracked-applicable-files","diff":["ci/test_hotkey_register_extraction.py","libobs/build/libobs.core+.h.c","libobs/build/libobs.ported-hotkey-combination-background-id+.h.c","libobs/build/ported-source-sets/hotkey-combination-background-id.json","libobs/cmake/rust-exports.d/obs-hotkey-combination_background_id.txt","libobs/obs-hotkey-combination-background-id-fields.c.h","libobs/obs-hotkey-combination-background-id-lock.c.h","libobs/obs-hotkey-combination-background-id.c.h","libobs/obs-hotkey.c.h","libobs/obs-hotkeys-background-status-changed.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_hotkey_combination_background_id_swap_is_registered.rs","rust/obs-build/tests/native/registration/headless_characterizations_expected.json","rust/obs-build/tests/native/registration/portal_output_expected.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json","rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json","rust/obs-c-oracle/oracle/hotkey_combination_background_id.c","rust/obs-hotkey/src/combination_background_id.rs","rust/obs-hotkey/src/ffi/combination_background_id.rs","rust/obs-hotkey/src/ffi/mod.rs","rust/obs-hotkey/src/lib.rs","rust/obs-hotkey/tests/hotkey/background_query_parity.rs","rust/obs-hotkey/tests/hotkey/combination_background_id.rs","rust/obs-hotkey/tests/hotkey/combination_background_id_parity.rs","rust/obs-hotkey/tests/hotkey/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_hotkeys_background_status_changed.c","test/cmocka/tests.d/test_hotkeys_background_status_changed.cmake"],"head":"987b89c46ed3aaeab67f31cf67cf5eb924acd716","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"9e9e205e8e89c2f6ff36b305ea2f3965453462c9ae322234adc4a6cb87791544","tree":"dba1e45a032bf9008dd396ae7ad361ca60dc3f4d"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 20, 2026 02:23
@rdoupe
rdoupe added this pull request to the merge queue Nov 20, 2026
Merged via the queue into master with commit 5bc3cf4 Nov 20, 2026
46 checks passed
@rdoupe
rdoupe deleted the port/5288-hotkey-combination-background-id branch November 20, 2026 04:18
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 20, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant