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
3 changes: 2 additions & 1 deletion ci/test_bench_libobs_stand_ins.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# obs-encoder, which the bench links through obs-data.
# The encoder name getter is absent too: #5253 exports it from obs-encoder;
# the synthetic interleaver replaces only its private name seam.
# The key-name store is absent: #5321 exports it from obs-hotkey (hidden in
# libobs, defined by the workspace).
SYMBOLS = (
"obs_encoder_group_num_started",
"obs_encoder_interleave_info",
Expand All @@ -59,7 +61,6 @@
"obs_hotkey_seam_unlock",
"obs_hotkeys_mutex_lock",
"obs_hotkeys_mutex_unlock",
"obs_hotkeys_store_key_translation",
"obs_output_actual_start",
"obs_output_actual_stop",
"obs_output_begin_data_capture",
Expand Down
2 changes: 1 addition & 1 deletion libobs/build/libobs.core+.h.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "libobs/obs-hotkey-identity-fields.c.h"
#include "libobs/obs-hotkey-identity-setter-fields.c.h"
#include "libobs/obs-hotkey-inject-entry-fields.c.h"
#include "libobs/obs-hotkey-key-translation.c.h"
#include "libobs/obs-hotkey-key-translation-fields.c.h"
#include "libobs/obs-hotkey-object-fields.c.h"
#include "libobs/obs-hotkey-owned-translations-fields.c.h"
#include "libobs/obs-hotkey-pair-meta-setter-calls.c.h"
Expand Down
5 changes: 5 additions & 0 deletions libobs/build/libobs.ported-hotkey-key-translation+.h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Unity group (BUILD.md): original key-translation query and store for the C reference. */

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

#include "libobs/obs-hotkey-key-translation.c.h"
5 changes: 5 additions & 0 deletions libobs/build/ported-source-sets/hotkey-key-translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LIBOBS_PORTED_SOURCES": [
"build/libobs.ported-hotkey-key-translation+.h.c"
]
}
5 changes: 5 additions & 0 deletions libobs/cmake/rust-hidden.d/obs-hotkey-key_translation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# obs-hotkey-key-translation.c: the platform key name functions and
# obs_hotkeys_set_translations_s() call them inside libobs. Declared in
# obs-internal.h without EXPORT, so the shims stay hidden the same way.
obs_get_hotkey_translation
obs_hotkeys_store_key_translation
22 changes: 22 additions & 0 deletions libobs/obs-hotkey-key-translation-fields.c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "libobs/build/libobs.pch.h"

/* Private adapters for the Rust key-translation query and store. The name
* array, obs->hotkeys.translations[], and its bmalloc/bfree ownership stay in
* C. As in the original, no lock is taken and the key is not range-checked. */
char **obs_hotkey_key_translation_slot(obs_key_t key);
char **obs_hotkey_key_translation_slot(obs_key_t key)
{
return &obs->hotkeys.translations[key];
}

void obs_hotkey_key_translation_free(char *translation);
void obs_hotkey_key_translation_free(char *translation)
{
bfree(translation);
}

char *obs_hotkey_key_translation_dup(const char *translation);
char *obs_hotkey_key_translation_dup(const char *translation)
{
return bstrdup(translation);
}
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The private output starting/encoder-demand queries use lazy safe Rust decisions
| `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-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). |
| `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 @@ -359,6 +359,8 @@ mod canonical_hotkey_backtab_is_registered;
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_key_translation_swap_is_registered.rs"]
mod canonical_hotkey_key_translation_swap_is_registered;
#[path = "native/registration/canonical_hotkey_mnemonic_is_registered.rs"]
mod canonical_hotkey_mnemonic_is_registered;
#[path = "native/registration/canonical_hotkey_pair_latch_is_registered.rs"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use super::*;

#[test]
fn canonical_hotkey_key_translation_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_key_translation";
let rust_test = "test_hotkey_key_translation_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_key_translation.c";
let record = "test/cmocka/hotkey-key-translation-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();
// The unchanged characterization keeps testing the original C source.
assert!(
matches!(selected.targets[c_test].sources.as_slice(), [Source::Path(path)]
if path == test_source)
);
assert_eq!(selected.tests[c_test].target, c_test);
assert_eq!(selected.targets.contains_key(rust_test), available);
if !available {
continue;
}
// Its external seam reaches the Rust symbols through the real
// adapters, bound to the test's own core in one unity group.
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["key_translation"],
[test_source, record]
);
assert_eq!(target.definitions, ["HOTKEY_KEY_TRANSLATION_EXTERNAL"]);
assert_eq!(selected.tests[rust_test].target, rust_test);
}
}
let record_text = fs::read_to_string(root.join(record)).unwrap();
let fields = "#include \"libobs/obs-hotkey-key-translation-fields.c.h\"";
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_KEY_TRANSLATION_EXTERNAL"));
let ported = fs::read_to_string(
root.join("libobs/build/ported-source-sets/hotkey-key-translation.json"),
)
.unwrap();
assert!(ported.contains("build/libobs.ported-hotkey-key-translation+.h.c"));
let group =
fs::read_to_string(root.join("libobs/build/libobs.ported-hotkey-key-translation+.h.c"))
.unwrap();
let original = "#include \"libobs/obs-hotkey-key-translation.c.h\"";
assert!(group.contains(original));
let hybrid = fs::read_to_string(root.join("libobs/build/libobs.core+.h.c")).unwrap();
assert!(!hybrid.contains(original));
// The C-owned name array and its allocator stay in the production group.
assert!(hybrid.contains(fields));
// Standalone Rust-static consumers get the same real adapters.
let support =
fs::read_to_string(root.join("test/cmocka/build/rust-static-support.json")).unwrap();
assert!(support.contains("\"test/cmocka/hotkey-key-translation-link-support.c\""));
let link =
fs::read_to_string(root.join("test/cmocka/hotkey-key-translation-link-support.c")).unwrap();
assert!(link.contains(fields));
let hidden =
fs::read_to_string(root.join("libobs/cmake/rust-hidden.d/obs-hotkey-key_translation.txt"))
.unwrap();
let names: Vec<_> = hidden
.lines()
.filter(|line| !line.starts_with('#') && !line.trim().is_empty())
.collect();
assert_eq!(
names,
[
"obs_get_hotkey_translation",
"obs_hotkeys_store_key_translation"
]
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"schema": 1,
"targets": {
"test_hotkey_key_translation_rust": {
"sources": [
"test/cmocka/test_hotkey_key_translation.c",
"test/cmocka/hotkey-key-translation-record-support.c"
],
"pch": "libobs/build/libobs.pch.h",
"unity_groups": {
"key_translation": [
"test/cmocka/test_hotkey_key_translation.c",
"test/cmocka/hotkey-key-translation-record-support.c"
]
},
"definitions": [
"HOTKEY_KEY_TRANSLATION_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_key_translation_rust": {
"target": "test_hotkey_key_translation_rust",
"command": [
"${target}"
],
"requires": "HAVE_LIBOBS_RUST_STATIC"
}
}
}
5 changes: 0 additions & 5 deletions rust/obs-c-oracle/benches/port_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,6 @@ mod libobs_stand_ins {
called("obs_hotkeys_mutex_unlock")
}

#[unsafe(no_mangle)]
pub extern "C" fn obs_hotkeys_store_key_translation() -> ! {
called("obs_hotkeys_store_key_translation")
}

#[unsafe(no_mangle)]
pub extern "C" fn obs_output_interleave_first_audio_encoder_index() -> ! {
called("obs_output_interleave_first_audio_encoder_index")
Expand Down
Loading
Loading