Skip to content

obs-core: Port the module list calls - #4467

Merged
rdoupe merged 9 commits into
masterfrom
fix/rust-port-port-the-module-list-c-734
Nov 10, 2026
Merged

rdoupe merged 9 commits into
masterfrom
fix/rust-port-port-the-module-list-c-734

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4465

What and why

Ports the module list calls (libobs/obs-module-lists.c.h, extracted in #4139) to rust/obs-core, new module module_lists: obs_log_loaded_modules(), obs_module_add_source(), _add_output(), _add_encoder(), _add_service(), obs_find_module_file(), obs_module_get_config_path(), obs_add_module_path(), obs_add_safe_module() and obs_add_disabled_module(). All ten are EXPORT in obs.h and keep their names.

  1. RED: Tier 1 tests against a todo!() core over a model core. The first eight port test_module_lists' cases one to one; the rest pin the order of the reads, every loaded module in the log, and the one intentional difference.
  2. GREEN: the safe core, generic over the core and its modules (Lists). Each read, log line and push is one call of it, in the C's order and under the C's conditions. The paths come from the cores that are already Rust (module_paths::find_file, module_names::config_path).
  3. The exported C shims and the swap. Every field and list of the core and of a module goes through the module list seam (libobs: Add the module list seam #4288), so nothing mirrors struct obs_core or struct obs_module; the one mirror is struct obs_module_path, with a layout test. The copies are bmalloc'd (bstrdup(), as the lists' owners bfree them) and the pushes are obs-util's darray_push_back() with each list's element size. obs-module-lists.c.h moves from libobs.core into its own ported group, so hybrid libobs runs the Rust and the C reference keeps the C.
  4. Tier 3: the original file and the seam compiled over a stand-in core, against the shims.
  5. Docs.
  6. Review fix, its own RED then GREEN pair: the C reads each string argument only past its guard (an id only for a module, a file only for a module, a name only with a core, the search paths only with a core and neither NULL, where the NULL test reads nothing), and the shims read them all up front. The core's deferred-read calls take each string as a reader called only past the guard, and the shims pass readers whose NULL test reads nothing. ignored_strings_are_not_read hands both sides an unreadable non-NULL pointer for every ignored argument; the shims before the fix fault on it.
  7. Review fix, test only: the parity test compares the logs and lists as raw bytes, not as lossy text, which merged distinct bytes past 0x7f. A mutant that rewrites id bytes past 0x7f, which the text comparison let through, now fails it.
  8. Docs: the module list row notes the string reads.

Intentional difference (a fix): obs_log_loaded_modules() read the core's first module without checking the core, where the calls beside it check it, so an embedder, plugin or script that called it before obs_startup() or after obs_shutdown() crashed on a NULL read. The port returns without logging when there is no core. It is listed in the parity test header and in rust/README.md, the parity test leaves out exactly that call, and a Rust-side test pins it.

Kept as the C has it: a NULL id is pushed as a NULL entry, and obs_module_get_config_path() reads the core's config path without checking the core. No call takes a lock, as none did.

The round's check of the encoder registration's short-structure caps read needed no change: it is covered by test_encoder_short_scaling_caps (test/cmocka/test_register_short_info.c) and test_encoder_sizes (obs_core::module_register_copy).

(no upstream issue)

RED → GREEN

  • RED commit: 2207d87 (obs-core: Test the module list calls port): soldr cargo test -p obs-data --locked --test obs-tests-core module_lists fails 16 of 16 with not yet implemented.
  • RED commit of the review fix: dd8d999 (obs-core: Test the module list string reads): type_id_read_only_with_module, path_file_read_only_with_module, module_paths_read_only_past_the_checks and names_read_only_with_core fail with not yet implemented; the other 16 pass. GREEN: ce8a7e7.
  • GREEN: runs were on 60e9df4.
    • Tier 1: obs_core::module_lists, 20/20.
    • Tier 3: obs_core::module_lists_parity, 6/6, byte for byte: every result, log line and list (entries, NULL against empty, sizes and capacities, the search paths' type) compared with the original file over test_module_lists' calls, the log with NULL files, NULL config paths and names, and proptests over random worlds and calls, plus the struct obs_module_path layout, and an unreadable pointer for every argument a call ignores. Mutants of the search path check, the log order, the heading, the data path read, the type and name lists, the search path's type, the id copy, the list growth, the config path read and the name copy each fail it, as does one that rewrites id bytes past 0x7f (12 of 12).
    • Tier 2 (private Xvfb, after rebasing onto master 45dc048): test_module_lists, test_module_lists_seam, test_core_module_load, test_register_short_info and test_module_register_copy_steps: 5/5 on the C build, hybrid libobs and libobs-c-reference, 0 skipped.
    • Export sets: 1767 symbols, identical on the C, hybrid and C reference builds and unchanged from master; the ten calls are exported, the seam accessors stay local (t), and hybrid libobs compiles no C for the new group.
    • Local gates: ./lint; ./unittest (host tests 7773/7773 with 6 skipped and 914/914, Docker Tier 2 858/858 on both libobs builds); --lane lint, --lane dylint, --lane cross, the Windows MSVC clippy --all-targets, ci/windows_link_check.py and the port_comparison bench test all pass. The head is stamped by the local gate (lint, dylint, rust-test, cross and tier2-linux run).
  • Real app (UI, protocol output or logging changes): not applicable; the log lines are unchanged, and the one change is a call that crashed now returning.

Test cost: new tests: 26 (20 Tier 1, 6 Tier 3), about 0.02 s together, peak RSS 12.3 MB over 20 runs with OBS_PARITY_CASES=reduced, no threads of their own; generated strings are capped at 8 bytes, worlds at 4 modules and 24 calls.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

Tier 1 tests for obs_core::module_lists, the module list calls of
libobs/obs-module-lists.c.h, against a todo!() core over a model core.
The first eight port test_module_lists' cases one to one: the calls
with no core, the log with no loaded module, the type lists with and
without a module, the file and config path lookups, the search path and
safe and disabled name lists, and the NULL id. The rest pin the order
of the reads, every loaded module in the log, and the one intentional
difference: obs_log_loaded_modules() with no core logs nothing, where
the C crashes on the core's first module. Proptests cover when each
list is pushed to.

Refs #4465.
The safe core of libobs/obs-module-lists.c.h: log_loaded_modules()
(obs_log_loaded_modules()), add_type() (obs_module_add_source() and its
output, encoder and service siblings), find_file()
(obs_find_module_file()), config_path() (obs_module_get_config_path()),
add_module_path() (obs_add_module_path()) and add_name()
(obs_add_safe_module() and obs_add_disabled_module()).

The core and its modules are the caller's Lists: each read, log line
and push is one call of it, in the C's order and under the C's
conditions, and none takes a lock. The paths come from the cores that
are already Rust, module_paths::find_file() and
module_names::config_path().

One intentional difference: with no core, log_loaded_modules() logs
nothing and returns, where the C logs the heading and then crashes
reading the core's first module.

Refs #4465.
The C ABI of obs_core::module_lists: the ten module list calls,
EXPORT in obs.h, so libobs exports the shims under their names
(rust-exports.d). Every field and list of the core and of a module goes
through the module list seam, so nothing mirrors struct obs_core or
struct obs_module; struct obs_module_path, the entry of the core's
search paths, is the one mirror. Each copy is a bmalloc'd bstrdup(),
one allocation as in the C, since the lists' owners bfree() them, and
each push is obs-util's darray_push_back() with the typed list's
element size. A NULL id pushes a NULL entry, as before. The log lines
go to blog() with the C's format strings.

obs-module-lists.c.h moves from libobs.core into its own ported group,
libobs.ported-module-lists, so hybrid libobs links the Rust calls and
the C reference keeps the C. test_module_lists and
test_module_lists_seam see the swap through the hybrid libobs.

obs_log_loaded_modules() with no core (before obs_startup() or after
obs_shutdown()) now logs nothing, where it crashed reading the core's
first module.

Refs #4465.
Tier 3 for obs_core::ffi::module_lists: the original
obs-module-lists.c.h, compiled as oracle_obs_* with the module list
seam under its own names over a thread-local stand-in core, against
the shims on two copies of the same world (a core or none, its module
config path, modules with their files, data paths and names, some
loaded). blog() is the oracle's recording stand-in on both sides.
After every call it compares the result and the log, and at the end
every list of the core and of each module: entries (NULL against empty
included), sizes and capacities, and the search paths' type. It runs
test_module_lists' calls in its order and proptests over random worlds
and calls; the file lookups run on a directory of the test's own. A
layout test checks struct obs_module_path against the C.

The intentional difference, obs_log_loaded_modules() with no core, is
left out of the comparison (the C crashes) and pinned on the Rust side.
Mutants of the search path check, the log order and heading, the data
path read, the type and name lists, the search path's type, the id
copy, the list growth, the config path read and the name copy each
fail it.

Refs #4465.
The rust/README.md rows (obs-core's and the new module_lists row),
naming.md's obs-core row, and the obs-core description and module docs
for libobs/obs-module-lists.c.h, over the module list seam. One
intentional difference: obs_log_loaded_modules() with no core logs
nothing.

Fixes #4465.
The C reads each string argument of the module list calls only past
its guard: obs_module_add_*()'s id only for a module (bstrdup(id)),
obs_find_module_file()'s and obs_module_get_config_path()'s file only
for a module, obs_add_module_path()'s paths only with a core and
neither NULL (a NULL test reads nothing), and the safe and disabled
names only with a core. The shims read every string before the core
checks its guard, so an ignored pointer is dereferenced.

Tier 1 tests for deferred-read versions of the calls, whose string
arguments are readers called only past the guard, against todo!()
stubs: they count which strings each call reads and in what order.

Refs #4465.
The deferred-read calls: add_type_deferred() reads the id only for a
module, find_file_deferred() and config_path_deferred() the file only
for a module (after the module's data path, and its config path and
name), add_module_path_deferred() the binary path and then the data
path only with a core and neither NULL, and add_name_deferred() the
name only with a core. The calls on plain strings now wrap them.

The shims pass each C string as a reader whose NULL test reads
nothing, so a pointer a call ignores is never dereferenced, as in the
C. ignored_strings_are_not_read gives both sides an unreadable
non-NULL pointer for every argument a call ignores; the shims before
this faulted on it.

Refs #4465.
The parity test turned the logs and the list state into text with
String::from_utf8_lossy(), while its ids, names, files and paths are
any bytes but NUL, so two different bytes past 0x7f both became the
replacement character and compared equal. It now compares the raw
bytes. A mutant that rewrites every id byte past 0x7f to 0xff, which
the text comparison let through, fails it.

Test only; no change to the port.

Refs #4465.
The module_lists row of rust/README.md now says each string argument
is read only past the guard the C reads it after.

Fixes #4465.

Local-Gate: v1 tree=c75f335a234e392e0dce7cac0f0f8c05373afb91 secs=2454 lanes=lint:run,dylint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1794293152,"gate":"rust/all/fmt","host":"linux-x86_64","key":"2d758203b9995b718d44985742efe7fe3db36e929fbf8fde0433e602b3fb6dbc","lane":"lint","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":150,"stamp":"0ca43b53a584bc65b01c2742a88c6143","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"2d758203b9995b718d44985742efe7fe3db36e929fbf8fde0433e602b3fb6dbc","lane":"lint","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":150,"stamp":"ac377dcb0e80c22810ac73c8bfeecf18","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"425944b9b42d0641977a93792f7105ae3c0c2e0aa97ba88e3be2d6fbdbeb1074","lane":"dylint","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":14,"stamp":"b3983f986c55466d6740c0761ebc7cac","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"5b25834c8c05e66f082fc5a14751566c6afc68b01e32c17c9999c3b4e6937075","lane":"rust-test","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":219,"stamp":"b508c007c94c4cfaa2f3ca9fa5bd59f0","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"ea429209ddb6ca5d1925bd3c78ce17e2b78718dbdd799d1b753cff8ec3bf269f","lane":"cross","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":226,"stamp":"485e0617296d4ff12936f15d69c7c129","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"ea429209ddb6ca5d1925bd3c78ce17e2b78718dbdd799d1b753cff8ec3bf269f","lane":"cross","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":226,"stamp":"655e1fb751c8f132859e19c98803d75f","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"ea429209ddb6ca5d1925bd3c78ce17e2b78718dbdd799d1b753cff8ec3bf269f","lane":"cross","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":226,"stamp":"5d8d6a10b327832a5211e7ceb400329d","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"ea429209ddb6ca5d1925bd3c78ce17e2b78718dbdd799d1b753cff8ec3bf269f","lane":"cross","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":226,"stamp":"58ebb8fa8dee09a6023b9db91d51776c","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
Ci-Attestation: {"at":1794293152,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"735caed43d6dbae66e9c09b0faa71896e62bd140926fdb50f4ba524bc0005eb0","lane":"tier2-linux","parents":["9da0eb985e26af452577f70ee07c1e8709efcd8c"],"secs":2454,"stamp":"372d6d4029c39e105e2f202cece55244","tree":"c75f335a234e392e0dce7cac0f0f8c05373afb91","v":1,"via":"run"}
@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-module-list-c-734 branch from ae05b80 to 60e9df4 Compare November 10, 2026 06:46
@rdoupe
rdoupe marked this pull request as ready for review November 10, 2026 07:27
@rdoupe
rdoupe requested a review from zackees as a code owner November 10, 2026 07:27
@rdoupe
rdoupe added this pull request to the merge queue Nov 10, 2026
@rdoupe

rdoupe commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Handed off to the coordinator

Merged via the queue into master with commit 14d963d Nov 10, 2026
39 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-module-list-c-734 branch November 10, 2026 08:36
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port the module list calls (obs-module-lists.c)

1 participant