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 @@ -25,7 +25,7 @@
#include "libobs/obs-hotkey-background-press-fields.c.h"
#include "libobs/obs-hotkey-background-state.c.h"
#include "libobs/obs-hotkey-background-trigger-fields.c.h"
#include "libobs/obs-hotkey-combination-background-id.c.h"
#include "libobs/obs-hotkey-combination-background-id-fields.c.h"
#include "libobs/obs-hotkey-enum-fields.c.h"
#include "libobs/obs-hotkey-identity-fields.c.h"
#include "libobs/obs-hotkey-identity-setter-fields.c.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Unity group (BUILD.md): original combination background-id query for the C reference. */

#include "libobs/build/libobs.pch.h"

#include "libobs/obs-hotkey-combination-background-id-lock.c.h"
#include "libobs/obs-hotkey-combination-background-id.c.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-hotkey-combination-background-id+.h.c"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obs_hotkey_combination_get_background_id
33 changes: 33 additions & 0 deletions libobs/obs-hotkey-combination-background-id-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "libobs/build/libobs.pch.h"

extern bool obs_hotkey_seam_lock(void);
extern void obs_hotkey_seam_unlock(void);

/* Private adapters for the Rust combination background-id query. The callback
* table, its mutex and dstr ownership stay in C. */
typedef bool (*obs_hotkey_combination_background_id_func)(obs_key_combination_t combo, struct dstr *id);

bool obs_hotkey_combination_background_id_lock(void);
bool obs_hotkey_combination_background_id_lock(void)
{
return obs_hotkey_seam_lock();
}

/* Called only with the hotkey mutex held. */
const obs_hotkey_combination_background_id_func *obs_hotkey_combination_background_id_fields(void);
const obs_hotkey_combination_background_id_func *obs_hotkey_combination_background_id_fields(void)
{
return &obs->hotkeys.background.shortcut_id;
}

void obs_hotkey_combination_background_id_unlock(void);
void obs_hotkey_combination_background_id_unlock(void)
{
obs_hotkey_seam_unlock();
}

void obs_hotkey_combination_background_id_free(struct dstr *id);
void obs_hotkey_combination_background_id_free(struct dstr *id)
{
dstr_free(id);
}
16 changes: 16 additions & 0 deletions libobs/obs-hotkey-combination-background-id-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 wrapper 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-combination-background-id.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-combination-background-id-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 @@ -128,6 +128,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `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-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-binding-getters.c.h` | `obs-hotkey::binding_getters` | Three public binding getters: exact stored combination, independent binding ID and pointer identity. No intentional differences. Null stored hotkeys are preserved; null binding inputs remain outside the C contract. Full real-header binding/combination layouts and differential parity, with actual-library C characterization. |
| `libobs/obs-service-module-lookup.c.h` | `obs-output::service_module_lookup` | #3839: enabled/disabled list selection, next link, service count/id and load state. C supplies both global roots without selection; Rust reads the unchanged private module layout, checked field by field against `obs-internal.h`. No intended differences on defined C inputs; NULL modules and out-of-range id indexes are excluded as C UB. |
| `libobs/util/bitstream.c` | `obs-util::bitstream` | C ABI keeps the `uint8_t pos` wrap past byte 255; the safe API does not wrap |
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 @@ -353,6 +353,8 @@ mod canonical_hotkey_background_query_is_registered;
mod canonical_hotkey_background_trigger_swap_is_registered;
#[path = "native/registration/canonical_hotkey_backtab_is_registered.rs"]
mod canonical_hotkey_backtab_is_registered;
#[path = "native/registration/canonical_hotkey_combination_background_id_swap_is_registered.rs"]
mod canonical_hotkey_combination_background_id_swap_is_registered;
#[path = "native/registration/canonical_hotkey_identity_getters_is_registered.rs"]
mod canonical_hotkey_identity_getters_is_registered;
#[path = "native/registration/canonical_hotkey_mnemonic_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use super::*;

#[test]
fn canonical_hotkey_combination_background_id_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 name = "test_hotkey_combination_background_id";
graph.targets.retain(|key, _| key == name);
graph.tests.retain(|key, _| key == name);
for os in ["OS_LINUX", "OS_MACOS", "OS_WINDOWS"] {
let selected = graph.select(&[(os.into(), true)].into()).unwrap();
assert!(
matches!(selected.targets[name].sources.as_slice(), [Source::Path(path)]
if path == "test/cmocka/test_hotkey_combination_background_id.c")
);
assert_eq!(selected.tests[name].target, name);
}
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/hotkey-combination-background-id.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-hotkey-combination-background-id+.h.c"));
let group = fs::read_to_string(
root.join("libobs/build/libobs.ported-hotkey-combination-background-id+.h.c"),
)
.unwrap();
// The C reference gives the original its static lock pair through the seam.
let lock = "#include \"libobs/obs-hotkey-combination-background-id-lock.c.h\"";
let original = "#include \"libobs/obs-hotkey-combination-background-id.c.h\"";
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, callback slot and dstr_free stay in the production group.
assert!(hybrid.contains("#include \"libobs/obs-hotkey.c.h\""));
assert!(hybrid.contains("#include \"libobs/obs-hotkey-combination-background-id-fields.c.h\""));
let exports = fs::read_to_string(
root.join("libobs/cmake/rust-exports.d/obs-hotkey-combination_background_id.txt"),
)
.unwrap();
assert_eq!(exports.trim(), "obs_hotkey_combination_get_background_id");
}
230 changes: 230 additions & 0 deletions rust/obs-c-oracle/oracle/hotkey_combination_background_id.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/* Original combination background-id wrapper and its real-header adapters on
* one recording fixture. The probe runs the original and a candidate getter
* through the same lock, callback-field, unlock and dstr_free boundary and
* reports every difference instead of aborting, so mutants are observable. */
#include "libobs/build/libobs.pch.h"
#include <stddef.h>
#include <string.h>

typedef char *(*combo_id_getter)(obs_key_combination_t combo);

enum combo_id_output { NO_OUTPUT, EMPTY_OUTPUT, TEXT_OUTPUT, PARTIAL_OUTPUT, FAILED_EMPTY, REENTER, OUTPUT_KINDS };

static _Thread_local struct obs_core combo_id_core;
static _Thread_local bool combo_id_lock_result, combo_id_held, combo_id_with_callback;
static _Thread_local enum combo_id_output combo_id_kind;
static _Thread_local obs_key_combination_t combo_id_expected;
static _Thread_local combo_id_getter combo_id_current;
static _Thread_local char *combo_id_allocation;
static _Thread_local char combo_id_events[64];
static _Thread_local size_t combo_id_event_count;

static void combo_id_event(char value)
{
if (combo_id_event_count + 1 < sizeof(combo_id_events)) {
combo_id_events[combo_id_event_count++] = value;
combo_id_events[combo_id_event_count] = '\0';
}
}

/* 'X' marks a lock-discipline violation. */
static void combo_id_require(bool held)
{
if (combo_id_held != held)
combo_id_event('X');
}

static bool combo_id_wrong_callback(obs_key_combination_t combo, struct dstr *id)
{
(void)combo;
(void)id;
/* The field after unlock: a wrapper must invoke its saved callback. */
combo_id_event('W');
return false;
}

static bool combo_id_callback(obs_key_combination_t combo, struct dstr *id)
{
combo_id_require(false);
combo_id_event('C');
if (combo.key != combo_id_expected.key || combo.modifiers != combo_id_expected.modifiers)
combo_id_event('K');
if (id->array || id->len || id->capacity)
combo_id_event('Z');
if (combo_id_kind == REENTER) {
/* Reenter the getter under test after release, with no callback. */
combo_id_with_callback = false;
if (combo_id_current(combo))
combo_id_event('N');
} else if (combo_id_kind != NO_OUTPUT && combo_id_kind != FAILED_EMPTY) {
dstr_copy(id, combo_id_kind == EMPTY_OUTPUT ? "" : "background-id");
/* An empty successful result may still own an allocated empty string. */
if (!id->array)
id->array = bzalloc(1);
combo_id_allocation = id->array;
}
return combo_id_kind != PARTIAL_OUTPUT && combo_id_kind != FAILED_EMPTY;
}

bool oracle_combo_id_lock(void);
bool oracle_combo_id_lock(void)
{
combo_id_require(false);
combo_id_event('L');
combo_id_held = combo_id_lock_result;
/* The current callback is visible only while the lock is held. */
combo_id_core.hotkeys.background.shortcut_id = combo_id_with_callback ? combo_id_callback : NULL;
return combo_id_lock_result;
}

void oracle_combo_id_unlock(void);
void oracle_combo_id_unlock(void)
{
combo_id_require(true);
combo_id_event('U');
combo_id_held = false;
combo_id_core.hotkeys.background.shortcut_id = combo_id_wrong_callback;
}

static struct obs_core *combo_id_read_core(void)
{
combo_id_require(true);
combo_id_event('R');
return &combo_id_core;
}

static void combo_id_free(struct dstr *id)
{
combo_id_require(false);
combo_id_event('F');
if (id->array != combo_id_allocation)
combo_id_event('P');
dstr_free(id);
if (id->array || id->len || id->capacity)
combo_id_event('P');
}

static inline bool lock(void)
{
return oracle_combo_id_lock();
}

static inline void unlock(void)
{
oracle_combo_id_unlock();
}

char *oracle_obs_hotkey_combination_get_background_id(obs_key_combination_t combo);

#define obs combo_id_read_core()
#define dstr_free combo_id_free
#define obs_hotkey_seam_lock oracle_combo_id_lock
#define obs_hotkey_seam_unlock oracle_combo_id_unlock
#define obs_hotkey_combination_get_background_id oracle_obs_hotkey_combination_get_background_id
#include "libobs/obs-hotkey-combination-background-id.c.h"
#undef obs_hotkey_combination_get_background_id
#include "hotkey_combination_background_id_fields.inc"
#undef obs_hotkey_seam_unlock
#undef obs_hotkey_seam_lock
#undef dstr_free
#undef obs

struct combo_id_result {
char events[64];
bool null_result, transferred;
char text[16];
};

static void combo_id_arm(combo_id_getter getter, unsigned bits, obs_key_combination_t combo)
{
memset(&combo_id_core, 0, sizeof(combo_id_core));
memset(combo_id_events, 0, sizeof(combo_id_events));
combo_id_event_count = 0;
combo_id_lock_result = (bits & 1) != 0;
combo_id_with_callback = (bits & 2) != 0;
combo_id_kind = (enum combo_id_output)((bits >> 2) % OUTPUT_KINDS);
combo_id_held = false;
combo_id_expected = combo;
combo_id_current = getter;
combo_id_allocation = NULL;
combo_id_core.hotkeys.background.shortcut_id = combo_id_wrong_callback;
}

/* Arm the fixture for callers that reach the getter indirectly. */
void oracle_hotkey_combination_background_id_arm(unsigned bits, uint32_t modifiers, int key, combo_id_getter getter);
void oracle_hotkey_combination_background_id_arm(unsigned bits, uint32_t modifiers, int key, combo_id_getter getter)
{
obs_key_combination_t combo = {modifiers, (obs_key_t)key};
combo_id_arm(getter, bits, combo);
}

void oracle_hotkey_combination_background_id_events(char *out, size_t size);
void oracle_hotkey_combination_background_id_events(char *out, size_t size)
{
strncpy(out, combo_id_events, size - 1);
out[size - 1] = '\0';
}

static void combo_id_run(combo_id_getter getter, unsigned bits, obs_key_combination_t combo,
struct combo_id_result *out)
{
combo_id_arm(getter, bits, combo);
char *result = getter(combo);
combo_id_require(false);
memset(out, 0, sizeof(*out));
memcpy(out->events, combo_id_events, sizeof(out->events));
out->null_result = !result;
out->transferred = result && result == combo_id_allocation;
if (result)
strncpy(out->text, result, sizeof(out->text) - 1);
bfree(result);
/* A mutant may return with the fixture still locked. */
combo_id_held = false;
}

/* Bits of the result: 1 trace (order, discipline, callback input or partial
* free), 2 returned pointer or text. Allocation balance follows from the
* trace: every non-transferred allocation is freed exactly once (F, P). */
unsigned oracle_hotkey_combination_background_id_probe(unsigned bits, uint32_t modifiers, int key,
combo_id_getter getter);
unsigned oracle_hotkey_combination_background_id_probe(unsigned bits, uint32_t modifiers, int key,
combo_id_getter getter)
{
obs_key_combination_t combo = {modifiers, (obs_key_t)key};
struct combo_id_result original, candidate;
combo_id_run(oracle_obs_hotkey_combination_get_background_id, bits, combo, &original);
combo_id_run(getter, bits, combo, &candidate);
unsigned diff = 0;
if (strcmp(original.events, candidate.events) != 0 || strpbrk(candidate.events, "XWKZPN"))
diff |= 1;
if (original.null_result != candidate.null_result || original.transferred != candidate.transferred ||
strcmp(original.text, candidate.text) != 0)
diff |= 2;
return diff;
}

/* One getter's trace, for exact expectations in Rust. */
void oracle_hotkey_combination_background_id_trace(unsigned bits, combo_id_getter getter, char *out, size_t size);
void oracle_hotkey_combination_background_id_trace(unsigned bits, combo_id_getter getter, char *out, size_t size)
{
struct combo_id_result run;
obs_key_combination_t combo = {INTERACT_CONTROL_KEY, OBS_KEY_A};
combo_id_run(getter ? getter : oracle_obs_hotkey_combination_get_background_id, bits, combo, &run);
strncpy(out, run.events, size - 1);
out[size - 1] = '\0';
}

void oracle_hotkey_combination_background_id_layout(size_t *out);
void oracle_hotkey_combination_background_id_layout(size_t *out)
{
out[0] = sizeof(struct dstr);
out[1] = _Alignof(struct dstr);
out[2] = offsetof(struct dstr, array);
out[3] = offsetof(struct dstr, len);
out[4] = offsetof(struct dstr, capacity);
out[5] = sizeof(obs_key_combination_t);
out[6] = _Alignof(obs_key_combination_t);
out[7] = offsetof(obs_key_combination_t, modifiers);
out[8] = offsetof(obs_key_combination_t, key);
out[9] = sizeof(combo_id_core.hotkeys.background.shortcut_id);
}
Loading
Loading