Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libobs/build/libobs.core+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions libobs/build/libobs.ported-hotkey-background-state+.h.c
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/hotkey-background-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-hotkey-background-state+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_hotkeys_get_background_state
4 changes: 4 additions & 0 deletions libobs/cmake/rust-hidden.d/obs-hotkey-background_state.txt
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions libobs/obs-hotkey-background-state-fields.c.h
Original file line number Diff line number Diff line change
@@ -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();
}
16 changes: 16 additions & 0 deletions libobs/obs-hotkey-background-state-lock.c.h
Original file line number Diff line number Diff line change
@@ -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();
}
3 changes: 2 additions & 1 deletion libobs/obs-hotkey-background-state.c.h
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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; 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). |
Expand Down
2 changes: 2 additions & 0 deletions rust/obs-build/tests/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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.
#[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]
);
// 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);
}
}
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");
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"]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"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",
"obs_hotkeys_get_background_state=obs_hotkeys_background_state_request"
],
"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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ fn read(path: &Path) -> Result<Value, String> {
/// `_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 {
Expand Down
Loading
Loading