From 63c40fdc3f3155ce032c5e6e2a605a64486c267d Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Fri, 20 Nov 2026 16:28:36 -0500 Subject: [PATCH 1/4] test: mirror hotkey background-state characterization (RED, Refs #5259) Tier 1 mirrors every assertion of the unchanged test_hotkey_background_state.c against the safe query. Tier 3 runs the extracted original and the shim on one recording fixture through the new real-named lock, state, flags and unlock adapters (obs-hotkey-background-state-fields.c.h), with nine mutants. background_query_parity drops its same-named fake of obs_hotkeys_get_background_state and drives the real getter on that fixture instead. The safe query is a stub that returns NATIVE without locking: soldr cargo test -p obs-data --test obs-tests-core -- hotkey::background_state hotkey::background_query test result: FAILED. 4 passed; 8 failed Co-Authored-By: Claude Opus 5.5 --- libobs/obs-hotkey-background-state-fields.c.h | 35 +++ .../oracle/hotkey_background_state.c | 184 ++++++++++++ rust/obs-hotkey/src/background_state.rs | 31 +++ rust/obs-hotkey/src/ffi/background_query.rs | 4 +- rust/obs-hotkey/src/ffi/background_state.rs | 46 +++ rust/obs-hotkey/src/ffi/mod.rs | 1 + rust/obs-hotkey/src/lib.rs | 1 + .../tests/hotkey/background_query_parity.rs | 57 ++-- .../tests/hotkey/background_state.rs | 160 +++++++++++ .../tests/hotkey/background_state_parity.rs | 263 ++++++++++++++++++ rust/obs-hotkey/tests/hotkey/main.rs | 2 + 11 files changed, 754 insertions(+), 30 deletions(-) create mode 100644 libobs/obs-hotkey-background-state-fields.c.h create mode 100644 rust/obs-c-oracle/oracle/hotkey_background_state.c create mode 100644 rust/obs-hotkey/src/background_state.rs create mode 100644 rust/obs-hotkey/src/ffi/background_state.rs create mode 100644 rust/obs-hotkey/tests/hotkey/background_state.rs create mode 100644 rust/obs-hotkey/tests/hotkey/background_state_parity.rs diff --git a/libobs/obs-hotkey-background-state-fields.c.h b/libobs/obs-hotkey-background-state-fields.c.h new file mode 100644 index 0000000000..0e8a89f593 --- /dev/null +++ b/libobs/obs-hotkey-background-state-fields.c.h @@ -0,0 +1,35 @@ +#include "libobs/build/libobs.pch.h" + +/* Defined in obs-hotkey.c.h, later in the same unity group, or by the + * recording fixture that includes this file. */ +static inline bool lock(void); +static inline void unlock(void); + +/* Private adapters for the Rust background-state query. The hotkey mutex and + * the background fields stay in C; Rust reads each field once, only between a + * successful lock and its unlock. */ +bool obs_hotkeys_background_state_lock(void); +bool obs_hotkeys_background_state_lock(void) +{ + return lock(); +} + +/* Called only with the hotkey mutex held. */ +enum obs_hotkeys_background_state obs_hotkeys_background_state_read(void); +enum obs_hotkeys_background_state obs_hotkeys_background_state_read(void) +{ + return obs->hotkeys.background.state; +} + +/* Called only with the hotkey mutex held. */ +uint32_t obs_hotkeys_background_state_flags(void); +uint32_t obs_hotkeys_background_state_flags(void) +{ + return obs->hotkeys.background.flags; +} + +void obs_hotkeys_background_state_unlock(void); +void obs_hotkeys_background_state_unlock(void) +{ + unlock(); +} diff --git a/rust/obs-c-oracle/oracle/hotkey_background_state.c b/rust/obs-c-oracle/oracle/hotkey_background_state.c new file mode 100644 index 0000000000..018c169ffc --- /dev/null +++ b/rust/obs-c-oracle/oracle/hotkey_background_state.c @@ -0,0 +1,184 @@ +/* Original background-state query and its real-header adapters on one + * recording fixture. The probe runs the original and a candidate getter + * through the same lock, field-read and unlock boundary and reports every + * difference instead of aborting, so mutants are observable. */ +#include "libobs/build/libobs.pch.h" +#include +#include + +typedef enum obs_hotkeys_background_state (*state_getter)(uint32_t *flags); + +/* What a NULL-output run reports as its output, and what a non-NULL output + * holds before the call. */ +#define STATE_UNTOUCHED UINT32_C(0x5eed5eed) + +static _Thread_local struct obs_core state_core; +static _Thread_local bool state_lock_result, state_held; +static _Thread_local enum obs_hotkeys_background_state state_value; +static _Thread_local uint32_t state_flags; +static _Thread_local uint32_t *state_output; +static _Thread_local char state_events[64]; +static _Thread_local size_t state_event_count; + +static void state_event(char value) +{ + if (state_event_count + 1 < sizeof(state_events)) { + state_events[state_event_count++] = value; + state_events[state_event_count] = '\0'; + } +} + +/* 'X' marks a lock-discipline violation. */ +static void state_require(bool held) +{ + if (state_held != held) + state_event('X'); +} + +bool oracle_background_state_lock(void); +bool oracle_background_state_lock(void) +{ + state_require(false); + state_event('L'); + /* 'Z': the optional output was not cleared before the lock attempt. */ + if (state_output && *state_output != 0) + state_event('Z'); + state_held = state_lock_result; + /* The fields are current only while the lock is held. */ + state_core.hotkeys.background.state = state_value; + state_core.hotkeys.background.flags = state_flags; + return state_lock_result; +} + +void oracle_background_state_unlock(void); +void oracle_background_state_unlock(void) +{ + state_require(true); + state_event('U'); + /* 'F': the flags were not stored before the lock was released. */ + if (state_output && *state_output != state_flags) + state_event('F'); + state_held = false; + /* A read after unlock sees other values, as well as an 'X'. */ + state_core.hotkeys.background.state = (enum obs_hotkeys_background_state)~(unsigned)state_value; + state_core.hotkeys.background.flags = ~state_flags; +} + +static struct obs_core *state_read_core(void) +{ + state_require(true); + state_event('R'); + return &state_core; +} + +static inline bool lock(void) +{ + return oracle_background_state_lock(); +} + +static inline void unlock(void) +{ + oracle_background_state_unlock(); +} + +enum obs_hotkeys_background_state oracle_obs_hotkeys_get_background_state(uint32_t *flags); + +#define obs state_read_core() +#define obs_hotkeys_get_background_state oracle_obs_hotkeys_get_background_state +#include "libobs/obs-hotkey-background-state.c.h" +#undef obs_hotkeys_get_background_state +#include "hotkey_background_state_fields.inc" +#undef obs + +struct state_result { + char events[64]; + int state; + uint32_t output; +}; + +/* Bits: 1 the lock succeeds, 2 the caller passes a flags output. */ +static void state_arm(unsigned bits, int value, uint32_t flags) +{ + memset(&state_core, 0, sizeof(state_core)); + memset(state_events, 0, sizeof(state_events)); + state_event_count = 0; + state_lock_result = (bits & 1) != 0; + state_held = false; + state_value = (enum obs_hotkeys_background_state)value; + state_flags = flags; + state_output = NULL; +} + +/* Arm the fixture for callers that reach the getter indirectly. */ +void oracle_hotkey_background_state_arm(unsigned bits, int value, uint32_t flags); +void oracle_hotkey_background_state_arm(unsigned bits, int value, uint32_t flags) +{ + state_arm(bits, value, flags); +} + +void oracle_hotkey_background_state_events(char *out, size_t size); +void oracle_hotkey_background_state_events(char *out, size_t size) +{ + strncpy(out, state_events, size - 1); + out[size - 1] = '\0'; +} + +static void state_run(state_getter getter, unsigned bits, int value, uint32_t flags, struct state_result *out) +{ + state_arm(bits, value, flags); + uint32_t output = STATE_UNTOUCHED; + state_output = (bits & 2) ? &output : NULL; + enum obs_hotkeys_background_state result = getter(state_output); + state_require(false); + memset(out, 0, sizeof(*out)); + memcpy(out->events, state_events, sizeof(out->events)); + out->state = (int)result; + out->output = output; + /* A mutant may return with the fixture still locked. */ + state_held = false; + state_output = NULL; +} + +/* Bits of the result: 1 trace (order, discipline, clearing or storing the + * output), 2 returned state, 4 output value. */ +unsigned oracle_hotkey_background_state_probe(unsigned bits, int value, uint32_t flags, state_getter getter); +unsigned oracle_hotkey_background_state_probe(unsigned bits, int value, uint32_t flags, state_getter getter) +{ + struct state_result original, candidate; + state_run(oracle_obs_hotkeys_get_background_state, bits, value, flags, &original); + state_run(getter, bits, value, flags, &candidate); + unsigned diff = 0; + if (strcmp(original.events, candidate.events) != 0 || strpbrk(candidate.events, "XZF")) + diff |= 1; + if (original.state != candidate.state) + diff |= 2; + if (original.output != candidate.output) + diff |= 4; + return diff; +} + +/* One getter's trace, returned state and output, for exact expectations in + * Rust. A NULL getter runs the original. */ +int oracle_hotkey_background_state_trace(unsigned bits, int value, uint32_t flags, state_getter getter, char *out, + size_t size, uint32_t *output); +int oracle_hotkey_background_state_trace(unsigned bits, int value, uint32_t flags, state_getter getter, char *out, + size_t size, uint32_t *output) +{ + struct state_result run; + state_run(getter ? getter : oracle_obs_hotkeys_get_background_state, bits, value, flags, &run); + strncpy(out, run.events, size - 1); + out[size - 1] = '\0'; + *output = run.output; + return run.state; +} + +void oracle_hotkey_background_state_layout(size_t *out); +void oracle_hotkey_background_state_layout(size_t *out) +{ + out[0] = sizeof(enum obs_hotkeys_background_state); + out[1] = _Alignof(enum obs_hotkeys_background_state); + out[2] = sizeof(state_core.hotkeys.background.flags); + out[3] = OBS_HOTKEYS_BACKGROUND_NATIVE; + out[4] = OBS_HOTKEYS_BACKGROUND_FAILED; + out[5] = STATE_UNTOUCHED; +} diff --git a/rust/obs-hotkey/src/background_state.rs b/rust/obs-hotkey/src/background_state.rs new file mode 100644 index 0000000000..8fe82ae6a3 --- /dev/null +++ b/rust/obs-hotkey/src/background_state.rs @@ -0,0 +1,31 @@ +//! The background hotkey state and its flags, read under the caller's +//! hotkey mutex. The mutex and both fields stay with the caller. + +use core::cell::Cell; + +/// `OBS_HOTKEYS_BACKGROUND_NATIVE`, also the answer when the lock fails. +pub const NATIVE: i32 = crate::background_query::NATIVE; + +/// Access to the C-owned mutex and the two background fields. +pub trait BackgroundState { + /// Take the hotkey mutex; false when there is no core. + fn lock(&mut self) -> bool; + /// The stored state, unchecked; read only while the lock is held. + fn state(&mut self) -> i32; + /// The stored flags, every bit; read only while the lock is held. + fn flags(&mut self) -> u32; + /// Release exactly the lock that succeeded. + fn unlock(&mut self); +} + +/// The background state, and its flags in `flags` when given. +/// +/// `flags` is cleared before the lock is tried. A failed lock returns +/// [`NATIVE`] and reads nothing. Otherwise the state and then the flags are +/// read under the lock, the lock is released once, and the captured state is +/// returned, unknown values included. +pub fn query(backend: &mut B, flags: Option<&Cell>) -> i32 { + // RED stub: the real orchestration lands in the GREEN commit. + let _ = (backend, flags); + NATIVE +} diff --git a/rust/obs-hotkey/src/ffi/background_query.rs b/rust/obs-hotkey/src/ffi/background_query.rs index 42ac1eaa90..87b0797208 100644 --- a/rust/obs-hotkey/src/ffi/background_query.rs +++ b/rust/obs-hotkey/src/ffi/background_query.rs @@ -1,4 +1,6 @@ -//! The original public query, with C owning background status and identifiers. +//! The public combination query. Its state and identifier getters are this +//! crate's own shims, reached through their C names; C owns the status and +//! the identifiers. use super::nix_hotkey_state::obs_key_combination; use core::ffi::{c_char, c_int}; use obs_util::ffi::darray::bfree; diff --git a/rust/obs-hotkey/src/ffi/background_state.rs b/rust/obs-hotkey/src/ffi/background_state.rs new file mode 100644 index 0000000000..2c6b81e862 --- /dev/null +++ b/rust/obs-hotkey/src/ffi/background_state.rs @@ -0,0 +1,46 @@ +//! The public background-state query over C-owned state: the existing +//! hotkey mutex and `obs->hotkeys.background`, behind the private adapters +//! of `libobs/obs-hotkey-background-state-fields.c.h`. +use core::cell::Cell; +use core::ffi::c_int; + +unsafe extern "C" { + fn obs_hotkeys_background_state_lock() -> bool; + fn obs_hotkeys_background_state_read() -> c_int; + fn obs_hotkeys_background_state_flags() -> u32; + fn obs_hotkeys_background_state_unlock(); +} + +struct Core; +impl crate::background_state::BackgroundState for Core { + fn lock(&mut self) -> bool { + // SAFETY: the adapter checks core presence before taking its mutex. + unsafe { obs_hotkeys_background_state_lock() } + } + fn state(&mut self) -> i32 { + // SAFETY: the safe query reads the field only after lock succeeded; + // the core is live under the existing mutex. + unsafe { obs_hotkeys_background_state_read() } + } + fn flags(&mut self) -> u32 { + // SAFETY: as for the state, between a successful lock and its unlock. + unsafe { obs_hotkeys_background_state_flags() } + } + fn unlock(&mut self) { + // SAFETY: the safe query releases exactly the successfully acquired lock. + unsafe { obs_hotkeys_background_state_unlock() }; + } +} + +/// Return the background hotkey state, and its flags through `flags` when +/// it is not NULL. +/// +/// # Safety +/// As for the C API: `flags` is NULL or points to a writable `uint32_t`. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_hotkeys_get_background_state(flags: *mut u32) -> c_int { + // SAFETY: the caller passes NULL or a valid, writable uint32_t that it + // does not access during the call. + let flags = unsafe { flags.as_mut() }.map(Cell::from_mut); + crate::background_state::query(&mut Core, flags) +} diff --git a/rust/obs-hotkey/src/ffi/mod.rs b/rust/obs-hotkey/src/ffi/mod.rs index 00c82f4975..c0cc4b612e 100644 --- a/rust/obs-hotkey/src/ffi/mod.rs +++ b/rust/obs-hotkey/src/ffi/mod.rs @@ -6,6 +6,7 @@ pub mod background_enum; pub mod background_error; pub mod background_press; pub mod background_query; +pub mod background_state; pub mod background_trigger; pub mod binding_getters; pub mod binding_press; diff --git a/rust/obs-hotkey/src/lib.rs b/rust/obs-hotkey/src/lib.rs index c97bb0c9ac..2d03f6e283 100644 --- a/rust/obs-hotkey/src/lib.rs +++ b/rust/obs-hotkey/src/lib.rs @@ -42,6 +42,7 @@ pub mod background_enum; pub mod background_error; pub mod background_press; pub mod background_query; +pub mod background_state; pub mod background_trigger; pub mod binding_getters; pub mod binding_press; diff --git a/rust/obs-hotkey/tests/hotkey/background_query_parity.rs b/rust/obs-hotkey/tests/hotkey/background_query_parity.rs index 82d6494972..a6893e636a 100644 --- a/rust/obs-hotkey/tests/hotkey/background_query_parity.rs +++ b/rust/obs-hotkey/tests/hotkey/background_query_parity.rs @@ -1,13 +1,15 @@ //! Exact C/Rust query parity. No exclusions or intentional differences. //! -//! The identifier lookup is the real Rust getter on the shared recording -//! fixture of `combination_background_id_parity`, never a same-named fake: -//! the getter is defined in this crate, so a second definition would collide. +//! The state query and the identifier lookup are the real Rust getters on the +//! shared recording fixtures of `background_state_parity` and +//! `combination_background_id_parity`, never same-named fakes: both getters +//! are defined in this crate, so a second definition would collide. use core::ffi::{CStr, c_char, c_int, c_void}; use core::mem::{align_of, offset_of, size_of}; use obs_hotkey::background_query::NATIVE; use obs_hotkey::ffi::{ background_query::obs_hotkey_combination_is_background, + background_state::obs_hotkeys_get_background_state, combination_background_id::obs_hotkey_combination_get_background_id, nix_hotkey_state::obs_key_combination, }; @@ -18,25 +20,13 @@ use std::cell::RefCell; #[derive(Default)] struct World { - state: i32, - queries: Vec>, releases: usize, } thread_local! { static WORLD: RefCell = RefCell::new(World::default()); } -// The production shim resolves its unported status dependency to this local -// test hook. It is per-thread; allocation-accounting parity re-execs first. -#[unsafe(no_mangle)] -unsafe extern "C" fn obs_hotkeys_get_background_state(flags: *mut u32) -> c_int { - assert!(flags.is_null()); - WORLD.with_borrow_mut(|world| { - world.queries.push(None); - world.state - }) -} - unsafe extern "C" fn query_state(_: *mut c_void, flags: *mut u32) -> c_int { - // SAFETY: the original query passes a null optional output. + // SAFETY: the original query passes a null optional output; the getter + // reaches only the armed per-thread state fixture. unsafe { obs_hotkeys_get_background_state(flags) } } unsafe extern "C" fn query_id(_: *mut c_void, combo: obs_key_combination) -> *mut c_char { @@ -57,6 +47,8 @@ unsafe extern "C" { getter: Getter, ); fn oracle_hotkey_combination_background_id_events(out: *mut c_char, size: usize); + fn oracle_hotkey_background_state_arm(bits: u32, value: c_int, flags: u32); + fn oracle_hotkey_background_state_events(out: *mut c_char, size: usize); fn oracle_hotkey_background_query_layout(out: *mut usize); fn oracle_hotkey_background_query( combo: obs_key_combination, @@ -68,10 +60,10 @@ unsafe extern "C" { } fn reset(state: i32, present: bool, combo: obs_key_combination) { - WORLD.set(World { - state, - ..World::default() - }); + WORLD.set(World::default()); + // The state lock succeeds and holds `state`; no flags are asked for. + // SAFETY: arms this thread's state fixture. + unsafe { oracle_hotkey_background_state_arm(1, state, u32::MAX) }; // Lock succeeds and a callback is registered; it fills the identifier // ("background-id") or succeeds with none. let bits = 3 | if present { 2 << 2 } else { 0 }; @@ -86,15 +78,23 @@ fn reset(state: i32, present: bool, combo: obs_key_combination) { } } -fn lookups() -> String { +fn events(read: unsafe extern "C" fn(*mut c_char, usize)) -> String { let mut out = [0 as c_char; 64]; // SAFETY: the oracle writes a terminated trace of at most 63 bytes. unsafe { - oracle_hotkey_combination_background_id_events(out.as_mut_ptr(), out.len()); + read(out.as_mut_ptr(), out.len()); CStr::from_ptr(out.as_ptr()).to_str().unwrap().to_owned() } } +fn lookups() -> String { + events(oracle_hotkey_combination_background_id_events) +} + +fn queries() -> String { + events(oracle_hotkey_background_state_events) +} + #[test] fn real_header_layout() { let mut layout = [0; 6]; @@ -120,7 +120,7 @@ fn compare(state: i32, modifiers: u32, key: i32, present: bool) { reset(state, present, combo); // SAFETY: combo contains a valid key; our hooks provide all C dependencies. let rust = unsafe { obs_hotkey_combination_is_background(combo) }; - let rust_queries = WORLD.with_borrow(|world| world.queries.clone()); + let rust_queries = queries(); let rust_lookups = lookups(); // SAFETY: the returned identifier must have been released by the shim. assert_eq!( @@ -137,13 +137,12 @@ fn compare(state: i32, modifiers: u32, key: i32, present: bool) { assert_eq!(lookups(), rust_lookups); // The fixture marks a combination that differs from this one with 'K'. assert_eq!(rust_lookups, if state == NATIVE { "" } else { "LRUC" }); - WORLD.with_borrow(|world| { - assert_eq!(world.queries, rust_queries); - assert_eq!(world.releases, usize::from(state != NATIVE)); - }); + assert_eq!(queries(), rust_queries); + WORLD.with_borrow(|world| assert_eq!(world.releases, usize::from(state != NATIVE))); // SAFETY: the oracle callback returns the identifier to the same allocator. assert_eq!(unsafe { bnum_allocs() }, before, "C leaked the identifier"); - assert_eq!(rust_queries.len(), 1); + // One locked state read, with no flags output. + assert_eq!(rust_queries, "LRU"); } #[test] diff --git a/rust/obs-hotkey/tests/hotkey/background_state.rs b/rust/obs-hotkey/tests/hotkey/background_state.rs new file mode 100644 index 0000000000..35ede17446 --- /dev/null +++ b/rust/obs-hotkey/tests/hotkey/background_state.rs @@ -0,0 +1,160 @@ +//! Tier 1: every assertion of the unchanged test_hotkey_background_state.c +//! against the safe query. The backend records lock, field reads and unlock, +//! checks the optional output at each, and swaps the fields at unlock so a +//! read after unlock is caught. +use core::cell::Cell; +use obs_hotkey::background_state::{BackgroundState, NATIVE, query}; + +// The declared states, in the C test's order (enum obs_hotkeys_background_state). +const ACTIVE: i32 = 5; +const STARTING: i32 = 1; +const IDLE: i32 = 3; +const WAITING: i32 = 4; +const DECLINED: i32 = 6; +const CLOSED: i32 = 7; +const FAILED: i32 = 8; +const UNAVAILABLE: i32 = 2; + +struct Backend<'a> { + lock_result: bool, + locked: bool, + locks: u32, + unlocks: u32, + reads: u32, + output: Option<&'a Cell>, + expected_state: i32, + expected_flags: u32, + state: i32, + flags: u32, + events: String, +} + +impl BackgroundState for Backend<'_> { + fn lock(&mut self) -> bool { + assert!(!self.locked); + assert_eq!(self.locks, 0); + assert_eq!(self.reads, 0); + // Clearing the optional output precedes even a failed lock attempt. + if let Some(output) = self.output { + assert_eq!(output.get(), 0); + } + self.locks += 1; + self.events.push('L'); + self.locked = self.lock_result; + // Fields become current only when the lock succeeds. + self.state = self.expected_state; + self.flags = self.expected_flags; + self.lock_result + } + fn state(&mut self) -> i32 { + assert!(self.locked); + self.reads += 1; + self.events.push('S'); + self.state + } + fn flags(&mut self) -> u32 { + assert!(self.locked); + self.reads += 1; + self.events.push('F'); + self.flags + } + fn unlock(&mut self) { + assert!(self.locked); + assert_eq!(self.locks, 1); + assert_eq!(self.unlocks, 0); + assert_eq!(self.reads, if self.output.is_some() { 2 } else { 1 }); + if let Some(output) = self.output { + assert_eq!(output.get(), self.expected_flags); + } + // The returned state must be captured before releasing the lock. + self.state = NATIVE; + self.flags = 0; + self.locked = false; + self.unlocks += 1; + self.events.push('U'); + } +} + +/// The C test's `query()`: one call and every count it checks afterwards. +fn run(success: bool, with_flags: bool, state: i32, flags: u32) -> String { + let value = Cell::new(u32::MAX); + let output = with_flags.then_some(&value); + let mut backend = Backend { + lock_result: success, + locked: false, + locks: 0, + unlocks: 0, + reads: 0, + output, + expected_state: state, + expected_flags: flags, + state: 0, + flags: 0, + events: String::new(), + }; + let result = query(&mut backend, output); + assert_eq!(result, if success { state } else { NATIVE }); + assert_eq!( + value.get(), + match (with_flags, success) { + (false, _) => u32::MAX, + (true, true) => flags, + (true, false) => 0, + } + ); + assert_eq!(backend.locks, 1); + assert_eq!(backend.unlocks, u32::from(success)); + assert_eq!( + backend.reads, + match (success, with_flags) { + (false, _) => 0, + (true, true) => 2, + (true, false) => 1, + } + ); + assert!(!backend.locked); + backend.events +} + +#[test] +fn failed_lock() { + assert_eq!(run(false, true, ACTIVE, u32::MAX), "L"); + assert_eq!(run(false, false, ACTIVE, u32::MAX), "L"); +} + +#[test] +fn states_and_flags() { + let states = [ + NATIVE, + ACTIVE, + STARTING, + IDLE, + WAITING, + DECLINED, + CLOSED, + FAILED, + UNAVAILABLE, + // Characterized, not endorsed: unknown native enum values pass through. + 12345, + ]; + let flags = [0, 1, 0x8000_0000, 0xa5a5_1234, u32::MAX]; + for state in states { + for flag in flags { + assert_eq!(run(true, true, state, flag), "LSFU"); + assert_eq!(run(true, false, state, flag), "LSU"); + } + } +} + +#[test] +fn edge_any_state_and_flags_pass_through() { + // Beyond the C test: negative and extreme raw values pass through as well. + for state in [i32::MIN, -1, 9, i32::MAX] { + for flag in [0, 0x3f, u32::MAX] { + for with_flags in [false, true] { + run(true, with_flags, state, flag); + run(false, with_flags, state, flag); + } + } + } +} diff --git a/rust/obs-hotkey/tests/hotkey/background_state_parity.rs b/rust/obs-hotkey/tests/hotkey/background_state_parity.rs new file mode 100644 index 0000000000..a07e83d110 --- /dev/null +++ b/rust/obs-hotkey/tests/hotkey/background_state_parity.rs @@ -0,0 +1,263 @@ +//! Tier 3: the original extracted C query versus the shim on one recording +//! fixture, through the same real-named lock, field and unlock adapters. +//! Compares the full trace (including when the optional output is cleared and +//! stored), the returned state and the output. No intentional differences. +//! Mutants show the probe catches each broken contract. +use core::ffi::{CStr, c_char, c_int}; +use core::mem::{align_of, size_of}; +use obs_hotkey::background_state::NATIVE; +use obs_hotkey::ffi::background_state::obs_hotkeys_get_background_state; +use proptest::prelude::*; + +type Getter = unsafe extern "C" fn(*mut u32) -> c_int; +unsafe extern "C" { + fn oracle_hotkey_background_state_probe(bits: u32, value: c_int, flags: u32, getter: Getter) + -> u32; + fn oracle_hotkey_background_state_trace( + bits: u32, + value: c_int, + flags: u32, + getter: Option, + out: *mut c_char, + size: usize, + output: *mut u32, + ) -> c_int; + fn oracle_hotkey_background_state_layout(out: *mut usize); + fn obs_hotkeys_background_state_lock() -> bool; + fn obs_hotkeys_background_state_read() -> c_int; + fn obs_hotkeys_background_state_flags() -> u32; + fn obs_hotkeys_background_state_unlock(); +} + +/// Bits: 1 the lock succeeds, 2 the caller passes a flags output. +const SUCCESS: u32 = 1; +const OUTPUT: u32 = 2; +/// The fixture's output before the call, and what a NULL output reports. +const UNTOUCHED: u32 = 0x5eed_5eed; + +fn probe(bits: u32, value: c_int, flags: u32, getter: Getter) -> u32 { + // SAFETY: the oracle owns the whole fixture and passes the getter NULL or + // its own output; every adapter the getter reaches records into it. + unsafe { oracle_hotkey_background_state_probe(bits, value, flags, getter) } +} + +fn check(bits: u32, value: c_int, flags: u32) { + assert_eq!( + probe(bits, value, flags, obs_hotkeys_get_background_state), + 0, + "bits={bits:#x} value={value} flags={flags:#x}" + ); +} + +fn trace(bits: u32, value: c_int, flags: u32, getter: Option) -> (String, c_int, u32) { + let mut out = [0 as c_char; 64]; + let mut output = 0; + // SAFETY: the oracle writes a terminated trace of at most 63 bytes and + // one output value. + unsafe { + let state = oracle_hotkey_background_state_trace( + bits, + value, + flags, + getter, + out.as_mut_ptr(), + out.len(), + &mut output, + ); + let text = CStr::from_ptr(out.as_ptr()).to_str().unwrap().to_owned(); + (text, state, output) + } +} + +#[test] +fn real_header_layout() { + let mut layout = [0; 6]; + // SAFETY: the oracle writes six size_t measurements from the real headers. + unsafe { oracle_hotkey_background_state_layout(layout.as_mut_ptr()) }; + assert_eq!( + layout, + [ + size_of::(), + align_of::(), + size_of::(), + NATIVE as usize, + 8, + UNTOUCHED as usize, + ] + ); +} + +#[test] +fn original_traces_match_the_characterization() { + // The C characterization's expected sequences, from the original itself. + for (bits, expected, state, output) in [ + (0, "L", NATIVE, UNTOUCHED), + (OUTPUT, "L", NATIVE, 0), + (SUCCESS, "LRU", 12345, UNTOUCHED), + (SUCCESS | OUTPUT, "LRRU", 12345, 0xa5a5_1234), + ] { + let want = (expected.to_owned(), state, output); + assert_eq!(trace(bits, 12345, 0xa5a5_1234, None), want, "bits={bits:#x}"); + assert_eq!( + trace(bits, 12345, 0xa5a5_1234, Some(obs_hotkeys_get_background_state)), + want, + "bits={bits:#x}" + ); + } +} + +#[test] +fn characterized_edges() { + // Every declared state, an unknown and the extremes, with the C test's flags. + let states = [0, 1, 2, 3, 4, 5, 6, 7, 8, 12345, -1, i32::MIN, i32::MAX]; + let flags = [0, 1, 0x8000_0000, 0xa5a5_1234, u32::MAX]; + for bits in 0..4 { + for state in states { + for flag in flags { + check(bits, state, flag); + } + } + } +} + +proptest! { + #![proptest_config(ProptestConfig { + cases: obs_c_oracle::parity::cases(256), failure_persistence: None, + ..ProptestConfig::default() + })] + #[test] + fn get_background_state_matches_c(bits in 0..4u32, value in any::(), flags in any::()) { + check(bits, value, flags); + } +} + +/// Write the output the way the C does, through a raw pointer. +unsafe fn store(flags: *mut u32, value: u32) { + if !flags.is_null() { + // SAFETY: the fixture passes NULL or its own writable output. + unsafe { *flags = value }; + } +} + +unsafe extern "C" fn skips_clear(flags: *mut u32) -> c_int { + // SAFETY: fixture adapters; the output is deliberately left uncleared. + unsafe { + if !obs_hotkeys_background_state_lock() { + return NATIVE; + } + let state = obs_hotkeys_background_state_read(); + store(flags, obs_hotkeys_background_state_flags()); + obs_hotkeys_background_state_unlock(); + state + } +} + +unsafe extern "C" fn reads_on_failed_lock(flags: *mut u32) -> c_int { + // SAFETY: fixture adapters; the state is deliberately read without the lock. + unsafe { + store(flags, 0); + if !obs_hotkeys_background_state_lock() { + let _ = obs_hotkeys_background_state_read(); + return NATIVE; + } + obs_hotkeys_background_state_unlock(); + obs_hotkeys_get_background_state(flags) + } +} + +unsafe extern "C" fn unlocks_failed_lock(flags: *mut u32) -> c_int { + // SAFETY: fixture adapters; a failed lock is deliberately released. + unsafe { + store(flags, 0); + if !obs_hotkeys_background_state_lock() { + obs_hotkeys_background_state_unlock(); + return NATIVE; + } + obs_hotkeys_background_state_unlock(); + obs_hotkeys_get_background_state(flags) + } +} + +unsafe extern "C" fn reads_state_after_unlock(flags: *mut u32) -> c_int { + // SAFETY: fixture adapters; the state is deliberately read after unlock. + unsafe { + store(flags, 0); + if !obs_hotkeys_background_state_lock() { + return NATIVE; + } + if !flags.is_null() { + store(flags, obs_hotkeys_background_state_flags()); + } + obs_hotkeys_background_state_unlock(); + obs_hotkeys_background_state_read() + } +} + +unsafe extern "C" fn stores_flags_after_unlock(flags: *mut u32) -> c_int { + // SAFETY: fixture adapters; the flags are deliberately stored after unlock. + unsafe { + store(flags, 0); + if !obs_hotkeys_background_state_lock() { + return NATIVE; + } + let state = obs_hotkeys_background_state_read(); + let value = if flags.is_null() { + 0 + } else { + obs_hotkeys_background_state_flags() + }; + obs_hotkeys_background_state_unlock(); + store(flags, value); + state + } +} + +unsafe extern "C" fn masks_flags(flags: *mut u32) -> c_int { + // SAFETY: as the shim, then the stored flags deliberately lose high bits. + unsafe { + let state = obs_hotkeys_get_background_state(flags); + if !flags.is_null() { + *flags &= 0x3f; + } + state + } +} + +unsafe extern "C" fn clamps_unknown(flags: *mut u32) -> c_int { + // SAFETY: as the shim, then unknown states deliberately become NATIVE. + let state = unsafe { obs_hotkeys_get_background_state(flags) }; + if (0..=8).contains(&state) { + state + } else { + NATIVE + } +} + +unsafe extern "C" fn reports_state_on_failed_lock(flags: *mut u32) -> c_int { + // SAFETY: as the shim; a failed lock deliberately reports ACTIVE. + unsafe { + store(flags, 0); + if !obs_hotkeys_background_state_lock() { + return 5; + } + obs_hotkeys_background_state_unlock(); + obs_hotkeys_get_background_state(flags) + } +} + +#[test] +fn mutants_are_caught() { + let all = SUCCESS | OUTPUT; + assert_eq!(probe(all, 5, 0xa5a5_1234, skips_clear) & 1, 1); + assert_eq!(probe(OUTPUT, 5, 0xa5a5_1234, skips_clear) & 4, 4); + assert_eq!(probe(0, 5, 0, reads_on_failed_lock) & 1, 1); + assert_eq!(probe(0, 5, 0, unlocks_failed_lock) & 1, 1); + assert_eq!(probe(SUCCESS, 5, 0, reads_state_after_unlock) & 3, 3); + assert_eq!(probe(all, 5, 0xa5a5_1234, stores_flags_after_unlock) & 1, 1); + assert_eq!(probe(all, 5, u32::MAX, masks_flags) & 4, 4); + assert_eq!(probe(SUCCESS, 12345, 0, clamps_unknown) & 2, 2); + assert_eq!(probe(OUTPUT, 5, 0, reports_state_on_failed_lock) & 2, 2); + for bits in 0..4 { + check(bits, 5, 0xa5a5_1234); + } +} diff --git a/rust/obs-hotkey/tests/hotkey/main.rs b/rust/obs-hotkey/tests/hotkey/main.rs index c375b9c949..f7cab26eba 100644 --- a/rust/obs-hotkey/tests/hotkey/main.rs +++ b/rust/obs-hotkey/tests/hotkey/main.rs @@ -12,6 +12,8 @@ mod background_press; mod background_press_parity; mod background_query; mod background_query_parity; +mod background_state; +mod background_state_parity; mod background_trigger; mod background_trigger_parity; mod binding_getters; From 53d842a08de6689e93eec8a19be8e5e0113df6b7 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Fri, 20 Nov 2026 16:33:51 -0500 Subject: [PATCH 2/4] obs-hotkey: swap hotkey background-state query to safe Rust (Refs #5259) obs_hotkeys_get_background_state now comes from obs-hotkey in the hybrid libobs. Safe Rust clears a non-NULL flags output before trying the existing hotkey lock; a failed lock returns OBS_HOTKEYS_BACKGROUND_NATIVE with no field read and no unlock; otherwise it reads the state and, for a non-NULL output, the flags under the lock, stores the flags, unlocks once and returns the captured state. Unknown enum values and every flag bit pass through. The mutex and obs->hotkeys.background stay in C behind private adapters (obs-hotkey-background-state-fields.c.h) that reuse the static lock pair of obs-hotkey.c.h. The original moves to libobs.ported-hotkey-background-state, which gives it its static lock pair through the existing seam. The unchanged test_hotkey_background_state keeps testing the C source; its HOTKEY_BACKGROUND_STATE_EXTERNAL twin test_hotkey_background_state_rust runs the same assertions on the Rust shim, with the real adapters bound to the test's own recording core and lock pair in one unity group. The standalone hotkey fixtures keep compiling the original against their own core, as for the combination background-id swap. soldr cargo test -p obs-data --test obs-tests-core -- hotkey::background_state hotkey::background_query test result: ok. 12 passed; 0 failed soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build:: test result: ok. 337 passed; 0 failed Co-Authored-By: Claude Opus 5.5 --- libobs/build/libobs.core+.h.c | 2 +- ...libobs.ported-hotkey-background-state+.h.c | 6 ++ .../hotkey-background-state.json | 5 ++ .../obs-hotkey-background_state.txt | 1 + libobs/obs-hotkey-background-state-lock.c.h | 16 ++++ libobs/obs-hotkey-background-state.c.h | 3 +- rust/README.md | 1 + rust/obs-build/tests/native.rs | 2 + ...key_background_state_swap_is_registered.rs | 81 +++++++++++++++++++ .../test_hotkey_background_state_rust.json | 45 +++++++++++ .../registration/rust_static_entries.rs | 5 +- rust/obs-hotkey/src/background_state.rs | 15 +++- test/cmocka/build/test-graph.json | 38 +++++++++ .../hotkey-background-state-record-support.c | 8 ++ 14 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 libobs/build/libobs.ported-hotkey-background-state+.h.c create mode 100644 libobs/build/ported-source-sets/hotkey-background-state.json create mode 100644 libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt create mode 100644 libobs/obs-hotkey-background-state-lock.c.h create mode 100644 rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs create mode 100644 rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json create mode 100644 test/cmocka/hotkey-background-state-record-support.c diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index 488f8717aa..3fe240b102 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -24,7 +24,7 @@ #include "libobs/obs-hotkey-background-enum-fields.c.h" #include "libobs/obs-hotkey-background-error-fields.c.h" #include "libobs/obs-hotkey-background-press-fields.c.h" -#include "libobs/obs-hotkey-background-state.c.h" +#include "libobs/obs-hotkey-background-state-fields.c.h" #include "libobs/obs-hotkey-background-trigger-fields.c.h" #include "libobs/obs-hotkey-combination-background-id-fields.c.h" #include "libobs/obs-hotkey-enum-fields.c.h" diff --git a/libobs/build/libobs.ported-hotkey-background-state+.h.c b/libobs/build/libobs.ported-hotkey-background-state+.h.c new file mode 100644 index 0000000000..bb8b803392 --- /dev/null +++ b/libobs/build/libobs.ported-hotkey-background-state+.h.c @@ -0,0 +1,6 @@ +/* Unity group (BUILD.md): original hotkey background-state query for the C reference. */ + +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-hotkey-background-state-lock.c.h" +#include "libobs/obs-hotkey-background-state.c.h" diff --git a/libobs/build/ported-source-sets/hotkey-background-state.json b/libobs/build/ported-source-sets/hotkey-background-state.json new file mode 100644 index 0000000000..cea92cf179 --- /dev/null +++ b/libobs/build/ported-source-sets/hotkey-background-state.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-hotkey-background-state+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt b/libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt new file mode 100644 index 0000000000..ec2070c48c --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt @@ -0,0 +1 @@ +obs_hotkeys_get_background_state diff --git a/libobs/obs-hotkey-background-state-lock.c.h b/libobs/obs-hotkey-background-state-lock.c.h new file mode 100644 index 0000000000..223e731161 --- /dev/null +++ b/libobs/obs-hotkey-background-state-lock.c.h @@ -0,0 +1,16 @@ +#include "libobs/build/libobs.pch.h" + +extern bool obs_hotkey_seam_lock(void); +extern void obs_hotkey_seam_unlock(void); + +/* The extracted query calls the static lock pair of obs-hotkey.c.h. In the + * C reference's own group it reaches the same mutex through the seam. */ +static inline bool lock(void) +{ + return obs_hotkey_seam_lock(); +} + +static inline void unlock(void) +{ + obs_hotkey_seam_unlock(); +} diff --git a/libobs/obs-hotkey-background-state.c.h b/libobs/obs-hotkey-background-state.c.h index 3edcf3fc09..0ab338b9be 100644 --- a/libobs/obs-hotkey-background-state.c.h +++ b/libobs/obs-hotkey-background-state.c.h @@ -1,6 +1,7 @@ #include "libobs/build/libobs.pch.h" -/* Defined in obs-hotkey.c.h, later in the same unity group. */ +/* Defined in obs-hotkey.c.h later in a hotkey unity group, or before this + * file by obs-hotkey-background-state-lock.c.h in the C reference. */ static inline bool lock(void); static inline void unlock(void); diff --git a/rust/README.md b/rust/README.md index ceadb55a79..f60dfa0250 100644 --- a/rust/README.md +++ b/rust/README.md @@ -127,6 +127,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions | `libobs/obs-hotkey-inject-entry.c.h` | `obs-hotkey::inject_entry` | Captures one injection event after the existing hotkey seam locks, forwards every binding in the existing C array walk, including false events, then unlocks. Preserves all modifier bits and one captured strict flag through callbacks and live registry mutation. Unchanged C recorder, safe mirrors, real-header layout and original-C differential parity. No intentional differences. | | `libobs/obs-hotkey-unregister-entry.c.h` | `obs-hotkey::unregister_entry` | Public single/pair unregistration dispatch through the existing lock/unlock seams, with exact size_t forwarding and no-core silence. The existing single remover and real C pair helper retain notification, binding/weak-owner release and member/hash/free order. Frozen Tier 2 recorder and existing API tests run unchanged; Tier 3 compares original-C seam traces with bounded edge/random calls. No intentional differences; no layouts cross the new boundary. | | `libobs/obs-hotkey-background-query.c.h` | `obs-hotkey::background_query` | Swapped in hybrid libobs (#3969). The public combination query preserves the native short circuit, identifier lookup and release. Actual-library native fallback characterization, real-header combination layout, callback-based differential parity and isolated allocation accounting. No exclusions or intentional differences. | +| `libobs/obs-hotkey-background-state.c.h` | `obs-hotkey::background_state` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-background-state` keeps the original for the C reference). The public `obs_hotkeys_get_background_state`: Rust clears a non-NULL `flags` output before trying the existing hotkey lock; a failed lock returns `OBS_HOTKEYS_BACKGROUND_NATIVE` with no field read and no unlock; otherwise the state and then (only for a non-NULL output) the flags are read under the lock, the flags are stored before the lock is released once, and the captured state is returned. Unknown enum values and every flag bit pass through unchanged. The mutex and `obs->hotkeys.background` stay in C behind private adapters (`obs-hotkey-background-state-fields.c.h`), which reuse the static lock pair of `obs-hotkey.c.h`. The standalone hotkey fixtures keep compiling the original against their own core. The unchanged `test_hotkey_background_state` keeps testing the C source; its `HOTKEY_BACKGROUND_STATE_EXTERNAL` twin `test_hotkey_background_state_rust` runs the same assertions on the Rust shim, with the real adapters bound to the test's own recording core and lock pair in one unity group. Tier 1 mirrors every assertion plus negative and extreme raw states; Tier 3 runs the original and the shim on one recording fixture (trace, clear-before-lock and store-before-unlock checks, returned state and output) over any state, flags and output presence, with mutants for a skipped clear, a read or an unlock after a failed lock, a read or a store after unlock, masked flags, clamped unknown states and a non-NATIVE failure. `background_query_parity` now drives this real getter instead of a same-named fake. No intentional differences; no network protocol (Tier 4 inapplicable). | | `libobs/obs-hotkey-background-trigger.c.h` | `obs-hotkey::background_trigger` | Owned background trigger retrieval under the existing hotkey mutex. Preserves exact combo/wake_data, callback-before-unlock, rejected-output cleanup and exact allocation transfer, including allocated empty and successful NULL results. Unchanged C characterization, safe-core assertions, real-header layouts and differential ownership/dispatch parity. No intentional differences. | | `libobs/obs-hotkey-combination-background-id.c.h` | `obs-hotkey::combination_background_id` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-combination-background-id` keeps the original for the C reference). 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, NULL or an allocated empty string included. The mutex, the callback slot and `dstr_free` stay in C behind private adapters (`obs-hotkey-combination-background-id-fields.c.h`), so the caller's bfree always matches the callback's allocator. Tier 1 mirrors every assertion of the unchanged `test_hotkey_combination_background_id`; Tier 3 runs the original and the shim on one recording fixture (trace, returned pointer and text) with real-header `dstr`/combination layout checks and mutants for 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. `background_query_parity` now drives this real getter instead of a same-named fake. No intentional differences; no network protocol (Tier 4 inapplicable). | | `libobs/obs-hotkey-key-translation.c.h` | `obs-hotkey::key_translation` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-key-translation` keeps the original for the C reference). The hidden key name store `obs_hotkeys_store_key_translation` and its query `obs_get_hotkey_translation` (both `obs-internal.h`, listed in `rust-hidden.d`). The query returns NULL for `OBS_KEY_NONE` without touching the core, else the stored pointer itself (read again to return it, as C's ternary) or the caller's default; the store frees the old name (NULL too), clears the slot and stores a `bstrdup` copy. No lock and no key range check, as in C. The `obs->hotkeys.translations[]` array and `bfree`/`bstrdup` stay in C behind private adapters (`obs-hotkey-key-translation-fields.c.h`), also a shared Rust-static support member. The unchanged `test_hotkey_key_translation` keeps testing the C source; its `HOTKEY_KEY_TRANSLATION_EXTERNAL` twin `test_hotkey_key_translation_rust` runs the same assertions on the Rust symbols, with the real adapters bound to the test's own core. Tier 1 mirrors every assertion; Tier 3 runs the original and the shims on one recording core (free/copy trace, read count, returned pointer, stored slot, allocation balance, other keys) with mutants. The translations shim now calls this store directly, and its parity records the store calls through the oracle core. No intentional differences; no network protocol (Tier 4 inapplicable). | diff --git a/rust/obs-build/tests/native.rs b/rust/obs-build/tests/native.rs index 08f148e984..d5648d4b6d 100644 --- a/rust/obs-build/tests/native.rs +++ b/rust/obs-build/tests/native.rs @@ -357,6 +357,8 @@ mod canonical_hotkey_background_app_id_is_registered; mod canonical_hotkey_background_press_swap_is_registered; #[path = "native/registration/canonical_hotkey_background_query_is_registered.rs"] mod canonical_hotkey_background_query_is_registered; +#[path = "native/registration/canonical_hotkey_background_state_swap_is_registered.rs"] +mod canonical_hotkey_background_state_swap_is_registered; #[path = "native/registration/canonical_hotkey_background_trigger_swap_is_registered.rs"] mod canonical_hotkey_background_trigger_swap_is_registered; #[path = "native/registration/canonical_hotkey_backtab_is_registered.rs"] diff --git a/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs new file mode 100644 index 0000000000..480444cdc7 --- /dev/null +++ b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs @@ -0,0 +1,81 @@ +use super::*; + +const ORIGINAL: &str = "libobs/obs-hotkey-background-state.c.h"; + +/// The unchanged characterization keeps testing the original; its external +/// twin runs the same assertions on the Rust shim through the real adapters. +#[test] +fn canonical_hotkey_background_state_swap_is_registered() { + use obs_build::validation::graph::{Graph, Source}; + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + let mut graph = Graph::load(&root.join("test/cmocka/build/test-graph.json")).unwrap(); + let c_test = "test_hotkey_background_state"; + let rust_test = "test_hotkey_background_state_rust"; + graph + .targets + .retain(|key, _| key == c_test || key == rust_test); + graph + .tests + .retain(|key, _| key == c_test || key == rust_test); + let test_source = "test/cmocka/test_hotkey_background_state.c"; + let record = "test/cmocka/hotkey-background-state-record-support.c"; + for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] { + for available in [false, true] { + let facts = [ + (os.into(), true), + ("HAVE_LIBOBS_RUST_STATIC".into(), available), + ] + .into(); + let selected = graph.select(&facts).unwrap(); + assert!(matches!(selected.targets[c_test].sources.as_slice(), + [Source::Path(a)] if a == test_source)); + assert!(selected.targets[c_test].definitions.is_empty()); + assert_eq!(selected.tests[c_test].target, c_test); + assert_eq!(selected.targets.contains_key(rust_test), available); + if !available { + continue; + } + let target = &selected.targets[rust_test]; + assert!(matches!(target.sources.as_slice(), + [Source::Path(a), Source::Path(b)] if a == test_source && b == record)); + assert_eq!(target.unity_groups["background_state"], [test_source, record]); + assert_eq!(target.definitions, ["HOTKEY_BACKGROUND_STATE_EXTERNAL"]); + assert_eq!(selected.tests[rust_test].target, rust_test); + } + } + files_are_wired(&root, test_source, record); +} + +/// The record support, the ported group, the hybrid group and the export. +fn files_are_wired(root: &Path, test_source: &str, record: &str) { + let fields = "#include \"libobs/obs-hotkey-background-state-fields.c.h\""; + let record_text = fs::read_to_string(root.join(record)).unwrap(); + assert!(record_text.contains("#define obs record_core()")); + assert!(record_text.contains(fields)); + let test_text = fs::read_to_string(root.join(test_source)).unwrap(); + assert!(test_text.contains("#ifndef HOTKEY_BACKGROUND_STATE_EXTERNAL")); + let ported = fs::read_to_string( + root.join("libobs/build/ported-source-sets/hotkey-background-state.json"), + ) + .unwrap(); + assert!(ported.contains("build/libobs.ported-hotkey-background-state+.h.c")); + let group = fs::read_to_string( + root.join("libobs/build/libobs.ported-hotkey-background-state+.h.c"), + ) + .unwrap(); + // The C reference gives the original its static lock pair through the seam. + let lock = "#include \"libobs/obs-hotkey-background-state-lock.c.h\""; + let original = format!("#include \"{ORIGINAL}\""); + assert!(group.find(lock).unwrap() < group.find(&original).unwrap()); + let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core+.h.c")).unwrap(); + assert!(!hybrid.contains(&original)); + // The C-owned mutex and fields stay in the production group, ahead of + // the static lock pair the adapters forward-declare. + let owner = "#include \"libobs/obs-hotkey.c.h\""; + assert!(hybrid.find(fields).unwrap() < hybrid.find(owner).unwrap()); + let exports = fs::read_to_string( + root.join("libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt"), + ) + .unwrap(); + assert_eq!(exports.trim(), "obs_hotkeys_get_background_state"); +} diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json b/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json new file mode 100644 index 0000000000..83d3d542e8 --- /dev/null +++ b/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json @@ -0,0 +1,45 @@ +{ + "schema": 1, + "targets": { + "test_hotkey_background_state_rust": { + "sources": [ + "test/cmocka/test_hotkey_background_state.c", + "test/cmocka/hotkey-background-state-record-support.c" + ], + "pch": "libobs/build/libobs.pch.h", + "unity_groups": { + "background_state": [ + "test/cmocka/test_hotkey_background_state.c", + "test/cmocka/hotkey-background-state-record-support.c" + ] + }, + "definitions": [ + "HOTKEY_BACKGROUND_STATE_EXTERNAL" + ], + "libraries": [ + "libobs_rust-static", + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "header_libraries": [ + "SIMDe::SIMDe" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + } + }, + "tests": { + "test_hotkey_background_state_rust": { + "target": "test_hotkey_background_state_rust", + "command": [ + "${target}" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + } + } +} diff --git a/rust/obs-build/tests/native/registration/rust_static_entries.rs b/rust/obs-build/tests/native/registration/rust_static_entries.rs index 677f068dcc..f7316605ac 100644 --- a/rust/obs-build/tests/native/registration/rust_static_entries.rs +++ b/rust/obs-build/tests/native/registration/rust_static_entries.rs @@ -31,8 +31,9 @@ fn read(path: &Path) -> Result { /// `_rust` naming convention; core-relinked fixtures are C-source /// characterizations relinked in place by their swap (#5187), or the /// `_rust` twin of one that keeps testing its original C source (the canvas -/// video-info validity and mix-clearing swaps, #5310 and #5326, and the -/// hotkey background status notification, #5303). +/// video-info validity and mix-clearing swaps, #5310 and #5326, the hotkey +/// background status notification, #5303, and the hotkey background-state +/// query, #5259). const UNSUFFIXED: [&str; 2] = ["hotkey-control", "core-relinked"]; struct Entries { diff --git a/rust/obs-hotkey/src/background_state.rs b/rust/obs-hotkey/src/background_state.rs index 8fe82ae6a3..cd41b87632 100644 --- a/rust/obs-hotkey/src/background_state.rs +++ b/rust/obs-hotkey/src/background_state.rs @@ -25,7 +25,16 @@ pub trait BackgroundState { /// read under the lock, the lock is released once, and the captured state is /// returned, unknown values included. pub fn query(backend: &mut B, flags: Option<&Cell>) -> i32 { - // RED stub: the real orchestration lands in the GREEN commit. - let _ = (backend, flags); - NATIVE + if let Some(flags) = flags { + flags.set(0); + } + if !backend.lock() { + return NATIVE; + } + let state = backend.state(); + if let Some(flags) = flags { + flags.set(backend.flags()); + } + backend.unlock(); + state } diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 5d92ed3e57..41549506ae 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -6395,6 +6395,37 @@ "SIMDe::SIMDe" ] }, + "test_hotkey_background_state_rust": { + "sources": [ + "test/cmocka/test_hotkey_background_state.c", + "test/cmocka/hotkey-background-state-record-support.c" + ], + "pch": "libobs/build/libobs.pch.h", + "unity_groups": { + "background_state": [ + "test/cmocka/test_hotkey_background_state.c", + "test/cmocka/hotkey-background-state-record-support.c" + ] + }, + "definitions": [ + "HOTKEY_BACKGROUND_STATE_EXTERNAL" + ], + "libraries": [ + "libobs_rust-static", + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "header_libraries": [ + "SIMDe::SIMDe" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + }, "test_hotkey_background_trigger": { "sources": [ "libobs/obs-hotkey-binding-press.c.h", @@ -24908,6 +24939,13 @@ ], "target": "test_hotkey_background_state" }, + "test_hotkey_background_state_rust": { + "target": "test_hotkey_background_state_rust", + "command": [ + "${target}" + ], + "requires": "HAVE_LIBOBS_RUST_STATIC" + }, "test_hotkey_background_trigger": { "target": "test_hotkey_background_trigger", "command": [ diff --git a/test/cmocka/hotkey-background-state-record-support.c b/test/cmocka/hotkey-background-state-record-support.c new file mode 100644 index 0000000000..6ef873ed68 --- /dev/null +++ b/test/cmocka/hotkey-background-state-record-support.c @@ -0,0 +1,8 @@ +/* test_hotkey_background_state_rust: the real private adapters of the + * background-state query, bound to the unchanged characterization's own + * recording core and lock pair. One unity group includes this after the + * test, so record_core(), lock() and unlock() are the test's own, exactly as + * its non-external branch binds the original. */ +#define obs record_core() +#include "libobs/obs-hotkey-background-state-fields.c.h" +#undef obs From 793482f5c7efafebcc6d5fd27aaaa2ebbb987913 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Fri, 20 Nov 2026 16:33:54 -0500 Subject: [PATCH 3/4] style: apply ./lint --fix formatting (Refs #5259) Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1795211226,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":95,"stamp":"9d4cda5d784ca14b01846f4363b91ae6","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211226,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":95,"stamp":"2d8299d12a12ccab912710ed967a4b5e","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211226,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":95,"stamp":"bd9be5b5188c47a7d87525fadaa0f441","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211226,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":95,"stamp":"2409d7611eabc03d3bd9abda2a35eb25","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"general/all/client-lint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"8c368edce3e6d6d1f2f10dc3b52aa2f4","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211226,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":95,"stamp":"cb322b27e06d7d7a9f796b9e3a4bb7dd","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"f23ecf0d4a6791ef1349ec397e049b8e","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"a403cf63a3f4316cb0efb602eb4023e9","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"365c4c0fc716c7d6098ebf62fb08b3e0","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"1c453d06b9955ba56063c1f3c239ae67","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"338222d283f85eec6055e790099c585d","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"6a42f0473b3a1170a43f67703a97a872","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"05cfc9fabb0b1cbd26b1bd69fae48aa5","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"53fdf68dfab14cdf7c785b1e23989a2d","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"716b25e266062b0cf26bda74ea68fb16","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"604c332e924d45b1692f73b04bc81c7d","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"943b42b03fe4214dff1006dcd6303907","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211130,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"83f335d183eea0f8329009de9f46f6f225188bb6b036cb033f3c44f06aa79f0f","lane":"client-lint","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":65,"stamp":"e88ec447c9a1fdf14d238936d8afda58","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Ci-Attestation: {"at":1795211436,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"72e925408dfdcdced555b0d9081b0f9073de5028164d1ffeef3bf0495ea99559","lane":"client-test-x86_64-unknown-linux-gnu","parents":["53d842a08de6689e93eec8a19be8e5e0113df6b7"],"secs":210,"stamp":"55da3b10288172e757039397452212e9","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a","v":1,"via":"run"} Client-Checks: {"checks":{"base":"935d60992db2de2ebd4afc783339abc458f0dea2","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.ported-hotkey-background-state+.h.c","libobs/build/ported-source-sets/hotkey-background-state.json","libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt","libobs/obs-hotkey-background-state-fields.c.h","libobs/obs-hotkey-background-state-lock.c.h","libobs/obs-hotkey-background-state.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json","rust/obs-build/tests/native/registration/rust_static_entries.rs","rust/obs-c-oracle/oracle/hotkey_background_state.c","rust/obs-hotkey/src/background_state.rs","rust/obs-hotkey/src/ffi/background_query.rs","rust/obs-hotkey/src/ffi/background_state.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/background_state.rs","rust/obs-hotkey/tests/hotkey/background_state_parity.rs","rust/obs-hotkey/tests/hotkey/main.rs","test/cmocka/build/test-graph.json","test/cmocka/hotkey-background-state-record-support.c"],"head":"9aa08ae2d7966700b1e47b2ec0681c72d5935bf3","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":"d753f6377a18607e8eb3701b0718ea7f945cbc9e1df8c8f4825cccb12badb459","tree":"eb31b66c9c879ecea1dfa6e0d74a46410917339a"}} --- ...key_background_state_swap_is_registered.rs | 12 ++++++----- .../oracle/hotkey_background_state.c | 2 +- .../tests/hotkey/background_state_parity.rs | 21 +++++++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs index 480444cdc7..481f16dbed 100644 --- a/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs @@ -38,7 +38,10 @@ fn canonical_hotkey_background_state_swap_is_registered() { let target = &selected.targets[rust_test]; assert!(matches!(target.sources.as_slice(), [Source::Path(a), Source::Path(b)] if a == test_source && b == record)); - assert_eq!(target.unity_groups["background_state"], [test_source, record]); + assert_eq!( + target.unity_groups["background_state"], + [test_source, record] + ); assert_eq!(target.definitions, ["HOTKEY_BACKGROUND_STATE_EXTERNAL"]); assert_eq!(selected.tests[rust_test].target, rust_test); } @@ -59,10 +62,9 @@ fn files_are_wired(root: &Path, test_source: &str, record: &str) { ) .unwrap(); assert!(ported.contains("build/libobs.ported-hotkey-background-state+.h.c")); - let group = fs::read_to_string( - root.join("libobs/build/libobs.ported-hotkey-background-state+.h.c"), - ) - .unwrap(); + let group = + fs::read_to_string(root.join("libobs/build/libobs.ported-hotkey-background-state+.h.c")) + .unwrap(); // The C reference gives the original its static lock pair through the seam. let lock = "#include \"libobs/obs-hotkey-background-state-lock.c.h\""; let original = format!("#include \"{ORIGINAL}\""); diff --git a/rust/obs-c-oracle/oracle/hotkey_background_state.c b/rust/obs-c-oracle/oracle/hotkey_background_state.c index 018c169ffc..c7d0a71eef 100644 --- a/rust/obs-c-oracle/oracle/hotkey_background_state.c +++ b/rust/obs-c-oracle/oracle/hotkey_background_state.c @@ -60,7 +60,7 @@ void oracle_background_state_unlock(void) state_event('F'); state_held = false; /* A read after unlock sees other values, as well as an 'X'. */ - state_core.hotkeys.background.state = (enum obs_hotkeys_background_state)~(unsigned)state_value; + state_core.hotkeys.background.state = (enum obs_hotkeys_background_state) ~(unsigned)state_value; state_core.hotkeys.background.flags = ~state_flags; } diff --git a/rust/obs-hotkey/tests/hotkey/background_state_parity.rs b/rust/obs-hotkey/tests/hotkey/background_state_parity.rs index a07e83d110..ac1f8a447d 100644 --- a/rust/obs-hotkey/tests/hotkey/background_state_parity.rs +++ b/rust/obs-hotkey/tests/hotkey/background_state_parity.rs @@ -11,8 +11,12 @@ use proptest::prelude::*; type Getter = unsafe extern "C" fn(*mut u32) -> c_int; unsafe extern "C" { - fn oracle_hotkey_background_state_probe(bits: u32, value: c_int, flags: u32, getter: Getter) - -> u32; + fn oracle_hotkey_background_state_probe( + bits: u32, + value: c_int, + flags: u32, + getter: Getter, + ) -> u32; fn oracle_hotkey_background_state_trace( bits: u32, value: c_int, @@ -97,9 +101,18 @@ fn original_traces_match_the_characterization() { (SUCCESS | OUTPUT, "LRRU", 12345, 0xa5a5_1234), ] { let want = (expected.to_owned(), state, output); - assert_eq!(trace(bits, 12345, 0xa5a5_1234, None), want, "bits={bits:#x}"); assert_eq!( - trace(bits, 12345, 0xa5a5_1234, Some(obs_hotkeys_get_background_state)), + trace(bits, 12345, 0xa5a5_1234, None), + want, + "bits={bits:#x}" + ); + assert_eq!( + trace( + bits, + 12345, + 0xa5a5_1234, + Some(obs_hotkeys_get_background_state) + ), want, "bits={bits:#x}" ); From 87d24dcaf77487a0d54b2c1d50336a6927e28b70 Mon Sep 17 00:00:00 2001 From: Ryan Doupe Date: Fri, 20 Nov 2026 17:08:09 -0500 Subject: [PATCH 4/4] obs-hotkey: route the background-state twin through a hidden request entry (Refs #5259) macOS Tier 2 failed test_hotkey_background_state_rust (locks 0 != 1 at test_hotkey_background_state.c:77): the two-level namespace bound the twin's call of obs_hotkeys_get_background_state to libobs's export instead of the Rust static archive and the test's recording adapters. The twin now calls the hidden obs_hotkeys_background_state_request entry (rust-hidden.d), as the hotkey control fixtures do for their exported entries; the public name forwards to it. soldr cargo test -p obs-data --test obs-tests-core -- hotkey::background_state hotkey::background_query test result: ok. 12 passed; 0 failed soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build:: test result: ok. 337 passed; 0 failed Co-Authored-By: Claude Opus 5.5 Ci-Attestation: {"at":1795213369,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":95,"stamp":"e4cb02cc6d8abfa7177ff07ccd827a80","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213369,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":95,"stamp":"7f35c665ebd55348e74db448343c2bcb","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213369,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":95,"stamp":"e651c3c7b4f4c15cea11b9958e94907c","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213369,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":95,"stamp":"2e6c8d219c8bc600617f35e8e9286dbd","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"general/all/client-lint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"51e6f82976666004c59963159e26d607","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213369,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":95,"stamp":"e118d1af8a7c441689714e39519cc572","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"07960f7cee1f34ab9974760f0d50e0e6","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"e86e339b905bfe543f7cee88c39f6bd0","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"bb463bba6c2c57f91664d0b5e39bd051","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"60301a19090d86e494c94937d104e9f2","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"d733f0a4604544a16b7e967684cc6963","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"a56dc8cabe40d1934efa22649b1c7b29","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"4d810a61911aa62afe604098f16bf851","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"1fec6332c8fdcf90817c9a5d555eed74","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"1723205ec42cf25a34f8e205f7ceac2b","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"e4855e3661e440f1ec2e09a14e15552c","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"4f4b747002622952f9ae6c380950641a","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213273,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"964d508b067323168e1dfc1ce86fafa206b8e371772d097b0a4e0cb9736c6a94","lane":"client-lint","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":66,"stamp":"3cd2128ae8d2c2b7f0abb59113de6724","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Ci-Attestation: {"at":1795213522,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"1459647b76ae1dc6df11d5697c16720de27eebb66caeea064c0289c1ac1c9c79","lane":"client-test-x86_64-unknown-linux-gnu","parents":["793482f5c7efafebcc6d5fd27aaaa2ebbb987913"],"secs":152,"stamp":"ca49d460029aa40b7ad37c6a75129120","tree":"0bbc4ba6c9368c19912c833035352fc018769270","v":1,"via":"run"} Client-Checks: {"checks":{"base":"935d60992db2de2ebd4afc783339abc458f0dea2","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.ported-hotkey-background-state+.h.c","libobs/build/ported-source-sets/hotkey-background-state.json","libobs/cmake/rust-exports.d/obs-hotkey-background_state.txt","libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt","libobs/obs-hotkey-background-state-fields.c.h","libobs/obs-hotkey-background-state-lock.c.h","libobs/obs-hotkey-background-state.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json","rust/obs-build/tests/native/registration/rust_static_entries.rs","rust/obs-c-oracle/oracle/hotkey_background_state.c","rust/obs-hotkey/src/background_state.rs","rust/obs-hotkey/src/ffi/background_query.rs","rust/obs-hotkey/src/ffi/background_state.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/background_state.rs","rust/obs-hotkey/tests/hotkey/background_state_parity.rs","rust/obs-hotkey/tests/hotkey/main.rs","test/cmocka/build/test-graph.json","test/cmocka/hotkey-background-state-record-support.c"],"head":"3448289bba500692a72459ad47a0a5e09d5016fe","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":"528945ea2f230a5f46fdc62c75376a6cfed1952170a4f4eb450748d2e14c7815","tree":"0bbc4ba6c9368c19912c833035352fc018769270"}} --- .../rust-hidden.d/obs-hotkey-background_state.txt | 4 ++++ rust/README.md | 2 +- ..._hotkey_background_state_swap_is_registered.rs | 15 ++++++++++++++- .../test_hotkey_background_state_rust.json | 3 ++- rust/obs-hotkey/src/ffi/background_state.rs | 12 ++++++++++++ test/cmocka/build/test-graph.json | 3 ++- 6 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt diff --git a/libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt b/libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt new file mode 100644 index 0000000000..2a9894d19f --- /dev/null +++ b/libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt @@ -0,0 +1,4 @@ +# obs-hotkey-background-state.c.h: the private entry of the exported +# obs_hotkeys_get_background_state, for standalone fixtures that bind their +# own recording adapters (test_hotkey_background_state_rust). +obs_hotkeys_background_state_request diff --git a/rust/README.md b/rust/README.md index f60dfa0250..7ae112f52a 100644 --- a/rust/README.md +++ b/rust/README.md @@ -127,7 +127,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions | `libobs/obs-hotkey-inject-entry.c.h` | `obs-hotkey::inject_entry` | Captures one injection event after the existing hotkey seam locks, forwards every binding in the existing C array walk, including false events, then unlocks. Preserves all modifier bits and one captured strict flag through callbacks and live registry mutation. Unchanged C recorder, safe mirrors, real-header layout and original-C differential parity. No intentional differences. | | `libobs/obs-hotkey-unregister-entry.c.h` | `obs-hotkey::unregister_entry` | Public single/pair unregistration dispatch through the existing lock/unlock seams, with exact size_t forwarding and no-core silence. The existing single remover and real C pair helper retain notification, binding/weak-owner release and member/hash/free order. Frozen Tier 2 recorder and existing API tests run unchanged; Tier 3 compares original-C seam traces with bounded edge/random calls. No intentional differences; no layouts cross the new boundary. | | `libobs/obs-hotkey-background-query.c.h` | `obs-hotkey::background_query` | Swapped in hybrid libobs (#3969). The public combination query preserves the native short circuit, identifier lookup and release. Actual-library native fallback characterization, real-header combination layout, callback-based differential parity and isolated allocation accounting. No exclusions or intentional differences. | -| `libobs/obs-hotkey-background-state.c.h` | `obs-hotkey::background_state` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-background-state` keeps the original for the C reference). The public `obs_hotkeys_get_background_state`: Rust clears a non-NULL `flags` output before trying the existing hotkey lock; a failed lock returns `OBS_HOTKEYS_BACKGROUND_NATIVE` with no field read and no unlock; otherwise the state and then (only for a non-NULL output) the flags are read under the lock, the flags are stored before the lock is released once, and the captured state is returned. Unknown enum values and every flag bit pass through unchanged. The mutex and `obs->hotkeys.background` stay in C behind private adapters (`obs-hotkey-background-state-fields.c.h`), which reuse the static lock pair of `obs-hotkey.c.h`. The standalone hotkey fixtures keep compiling the original against their own core. The unchanged `test_hotkey_background_state` keeps testing the C source; its `HOTKEY_BACKGROUND_STATE_EXTERNAL` twin `test_hotkey_background_state_rust` runs the same assertions on the Rust shim, with the real adapters bound to the test's own recording core and lock pair in one unity group. Tier 1 mirrors every assertion plus negative and extreme raw states; Tier 3 runs the original and the shim on one recording fixture (trace, clear-before-lock and store-before-unlock checks, returned state and output) over any state, flags and output presence, with mutants for a skipped clear, a read or an unlock after a failed lock, a read or a store after unlock, masked flags, clamped unknown states and a non-NATIVE failure. `background_query_parity` now drives this real getter instead of a same-named fake. No intentional differences; no network protocol (Tier 4 inapplicable). | +| `libobs/obs-hotkey-background-state.c.h` | `obs-hotkey::background_state` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-background-state` keeps the original for the C reference). The public `obs_hotkeys_get_background_state`: Rust clears a non-NULL `flags` output before trying the existing hotkey lock; a failed lock returns `OBS_HOTKEYS_BACKGROUND_NATIVE` with no field read and no unlock; otherwise the state and then (only for a non-NULL output) the flags are read under the lock, the flags are stored before the lock is released once, and the captured state is returned. Unknown enum values and every flag bit pass through unchanged. The mutex and `obs->hotkeys.background` stay in C behind private adapters (`obs-hotkey-background-state-fields.c.h`), which reuse the static lock pair of `obs-hotkey.c.h`. The standalone hotkey fixtures keep compiling the original against their own core. The unchanged `test_hotkey_background_state` keeps testing the C source; its `HOTKEY_BACKGROUND_STATE_EXTERNAL` twin `test_hotkey_background_state_rust` runs the same assertions on the Rust shim, with the real adapters bound to the test's own recording core and lock pair in one unity group; it calls the hidden `obs_hotkeys_background_state_request` entry (listed in `rust-hidden.d`), since a Darwin two-level namespace would otherwise bind the public name to libobs's export. Tier 1 mirrors every assertion plus negative and extreme raw states; Tier 3 runs the original and the shim on one recording fixture (trace, clear-before-lock and store-before-unlock checks, returned state and output) over any state, flags and output presence, with mutants for a skipped clear, a read or an unlock after a failed lock, a read or a store after unlock, masked flags, clamped unknown states and a non-NATIVE failure. `background_query_parity` now drives this real getter instead of a same-named fake. No intentional differences; no network protocol (Tier 4 inapplicable). | | `libobs/obs-hotkey-background-trigger.c.h` | `obs-hotkey::background_trigger` | Owned background trigger retrieval under the existing hotkey mutex. Preserves exact combo/wake_data, callback-before-unlock, rejected-output cleanup and exact allocation transfer, including allocated empty and successful NULL results. Unchanged C characterization, safe-core assertions, real-header layouts and differential ownership/dispatch parity. No intentional differences. | | `libobs/obs-hotkey-combination-background-id.c.h` | `obs-hotkey::combination_background_id` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-combination-background-id` keeps the original for the C reference). 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, NULL or an allocated empty string included. The mutex, the callback slot and `dstr_free` stay in C behind private adapters (`obs-hotkey-combination-background-id-fields.c.h`), so the caller's bfree always matches the callback's allocator. Tier 1 mirrors every assertion of the unchanged `test_hotkey_combination_background_id`; Tier 3 runs the original and the shim on one recording fixture (trace, returned pointer and text) with real-header `dstr`/combination layout checks and mutants for 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. `background_query_parity` now drives this real getter instead of a same-named fake. No intentional differences; no network protocol (Tier 4 inapplicable). | | `libobs/obs-hotkey-key-translation.c.h` | `obs-hotkey::key_translation` | Swapped in hybrid `libobs` (group `libobs.ported-hotkey-key-translation` keeps the original for the C reference). The hidden key name store `obs_hotkeys_store_key_translation` and its query `obs_get_hotkey_translation` (both `obs-internal.h`, listed in `rust-hidden.d`). The query returns NULL for `OBS_KEY_NONE` without touching the core, else the stored pointer itself (read again to return it, as C's ternary) or the caller's default; the store frees the old name (NULL too), clears the slot and stores a `bstrdup` copy. No lock and no key range check, as in C. The `obs->hotkeys.translations[]` array and `bfree`/`bstrdup` stay in C behind private adapters (`obs-hotkey-key-translation-fields.c.h`), also a shared Rust-static support member. The unchanged `test_hotkey_key_translation` keeps testing the C source; its `HOTKEY_KEY_TRANSLATION_EXTERNAL` twin `test_hotkey_key_translation_rust` runs the same assertions on the Rust symbols, with the real adapters bound to the test's own core. Tier 1 mirrors every assertion; Tier 3 runs the original and the shims on one recording core (free/copy trace, read count, returned pointer, stored slot, allocation balance, other keys) with mutants. The translations shim now calls this store directly, and its parity records the store calls through the oracle core. No intentional differences; no network protocol (Tier 4 inapplicable). | diff --git a/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs index 481f16dbed..4e3f6d13cd 100644 --- a/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_hotkey_background_state_swap_is_registered.rs @@ -1,6 +1,7 @@ use super::*; const ORIGINAL: &str = "libobs/obs-hotkey-background-state.c.h"; +const REQUEST: &str = "obs_hotkeys_get_background_state=obs_hotkeys_background_state_request"; /// The unchanged characterization keeps testing the original; its external /// twin runs the same assertions on the Rust shim through the real adapters. @@ -42,7 +43,11 @@ fn canonical_hotkey_background_state_swap_is_registered() { target.unity_groups["background_state"], [test_source, record] ); - assert_eq!(target.definitions, ["HOTKEY_BACKGROUND_STATE_EXTERNAL"]); + // The request entry keeps a Darwin call off libobs's export. + assert_eq!( + target.definitions, + ["HOTKEY_BACKGROUND_STATE_EXTERNAL", REQUEST] + ); assert_eq!(selected.tests[rust_test].target, rust_test); } } @@ -80,4 +85,12 @@ fn files_are_wired(root: &Path, test_source: &str, record: &str) { ) .unwrap(); assert_eq!(exports.trim(), "obs_hotkeys_get_background_state"); + let hidden = + fs::read_to_string(root.join("libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt")) + .unwrap(); + let names: Vec<_> = hidden + .lines() + .filter(|line| !line.starts_with('#') && !line.trim().is_empty()) + .collect(); + assert_eq!(names, ["obs_hotkeys_background_state_request"]); } diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json b/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json index 83d3d542e8..efee4635e0 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_hotkey_background_state_rust.json @@ -14,7 +14,8 @@ ] }, "definitions": [ - "HOTKEY_BACKGROUND_STATE_EXTERNAL" + "HOTKEY_BACKGROUND_STATE_EXTERNAL", + "obs_hotkeys_get_background_state=obs_hotkeys_background_state_request" ], "libraries": [ "libobs_rust-static", diff --git a/rust/obs-hotkey/src/ffi/background_state.rs b/rust/obs-hotkey/src/ffi/background_state.rs index 2c6b81e862..9866c2de0a 100644 --- a/rust/obs-hotkey/src/ffi/background_state.rs +++ b/rust/obs-hotkey/src/ffi/background_state.rs @@ -39,6 +39,18 @@ impl crate::background_state::BackgroundState for Core { /// As for the C API: `flags` is NULL or points to a writable `uint32_t`. #[unsafe(no_mangle)] pub unsafe extern "C" fn obs_hotkeys_get_background_state(flags: *mut u32) -> c_int { + // SAFETY: the same contract, forwarded unchanged. + unsafe { obs_hotkeys_background_state_request(flags) } +} + +/// Private entry for isolated C fixtures. The public name is also exported by +/// libobs, and a Darwin two-level namespace binds a fixture's call to it +/// there instead of to the fixture's own recording adapters. +/// +/// # Safety +/// As for [`obs_hotkeys_get_background_state`]. +#[unsafe(no_mangle)] +pub unsafe extern "C" fn obs_hotkeys_background_state_request(flags: *mut u32) -> c_int { // SAFETY: the caller passes NULL or a valid, writable uint32_t that it // does not access during the call. let flags = unsafe { flags.as_mut() }.map(Cell::from_mut); diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 41549506ae..429a6827c3 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -6408,7 +6408,8 @@ ] }, "definitions": [ - "HOTKEY_BACKGROUND_STATE_EXTERNAL" + "HOTKEY_BACKGROUND_STATE_EXTERNAL", + "obs_hotkeys_get_background_state=obs_hotkeys_background_state_request" ], "libraries": [ "libobs_rust-static",