Skip to content

libobs: Port the module load rules to obs-core - #2807

Merged
rdoupe merged 6 commits into
masterfrom
fix/1837-libobs-move-the-hotkey-binding-p
Oct 28, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/1837-libobs-move-the-hotkey-binding-p

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2801

What and why

The next slice of libobs/obs-module.c.h moves to rust/obs-core (module_load_rules): the pure decisions of the module loader. Those are the open gates of obs_open_module(), which required export is missing, the version rule (a module built for a newer libobs is refused, the patch number ignored), the safe and disabled list rules, obs_get_module_allow_disable(), the core and legacy plugin types that load_all_callback(), find_core_module(), obs_is_core_module() and obs_is_legacy_module() ask about, what load_all_callback() does with each obs_open_module() code and obs_init_module() result, whether a failure is counted, and the obs_load_core_modules() result.

No seam is needed. Each rule takes plain values the caller already read at that point and returns a bool, a list answer, or route bits plus the state of the disabled module to make. Every lookup, call and log message stays in obs-module.c.h, in the same place and under the same condition:

  • get_plugin_info(), obs_get_module(), obs_host_skip_module(), os_dlopen(), os_dlsym() and the ver() call;
  • the module set-up, obs_create_disabled_module(), obs_init_module() and free_module();
  • the failure list and its split, load_core_modules(), obs_module_paths_find() and obs_module_names_find_core();
  • every blog(), with the same text, level and order.

The lookups and reads stay where they were: obs_open_module() reads the core only with a module pointer and a path (its gate asks obs_module_load_rules_arg_missing() for each argument in the original || chain), load_module_exports() still stops at the first missing export, a list's array and length are read and its name matched (obs_module_names_listed(), already Rust) only when the list is not empty, the disabled list only for a module that is not core, the core list only for a legacy plugin, the module type after obs_open_module() only for a module that failed to open (the open route returns CORE_CONTINUES and the C then asks obs_module_load_rules_is_core(), after making the disabled module, as before), and nothing runs after the first skip.

No exported function moves, so there is no rust-exports.d fragment, and the 1766 exported symbols are unchanged on the C, hybrid and c-reference builds. The unit is its own file, obs-module-load-rules.c.h, with its own header, obs-module-load-rules.h. The header copies the six MODULE_* codes, the core and legacy module types and three load states, and defines the route bits; obs-module.c.h checks the copies against obs-defs.h and obs.h with _Static_assert.

Overlap: the PR that moves the hotkey binding press count (#1837) also adds an include to libobs/build/libobs.core+.h.c; whichever lands second keeps both lines.

Commits:

  • libobs: Move module load rules to their own file: a behaviour-neutral extraction, with thirteen hidden entry points. A scratch harness extracted master's ten functions and the moved ones over a logging stand-in (os_dlopen, os_dlsym, the exports, get_plugin_info, obs_get_module, the list match, the core list, obs_create_disabled_module, obs_init_module, free_module, the failure string, the core module walk and blog). It built both with gcc and clang at -O0 and -O2 and under ASan/UBSan, and ran 300,000 random worlds through obs_open_module() and its gates, load_all_callback(), obs_load_core_modules() twice, find_core_module() and the queries: 2.48 million log lines, identical in all six builds. Eight planted mutants of the moved file were each caught.
  • test: Characterize the module load rules: test_module_load_steps, registered in test-graph.json in sorted order, under xvfb-run where a display is needed, with libm off MSVC.
    • The steps, compiled into the test from the moved file: every rule at its edges, and load_all_callback()'s whole decision built on the steps against the decisions read off the C before the move, for all 512 settings of what it reads (a plugin or not, each list empty or not and the name on it or not, a core module's name, already loaded, the init result, a failure list) by 7 module types and 8 codes, including which lookups run.
    • The callers, on the real libobs: obs_open_module() before obs_startup() and without a module pointer or path, a missing file and its warning, obs_get_module_allow_disable(), and obs_is_core_module()/obs_is_legacy_module() on NULL. test_core_module_load (Linux) already loads real stub modules through obs_load_core_modules(): one that can't be opened, one built for a newer libobs, and a retry after a failure.
  • RED, GREEN, Tier 3, then docs.
  • Review fixes, folded into the commits above: three reads that had moved earlier (the core in the open gate, a list's array and length, the module type in the open route) are back in place; the characterization compiles the moved file with ASan and UBSan; the export lists are sorted. The move harness was rerun on the folded head against master: identical logs in all six builds. There is no _rust variant of the characterization, as for test_canvas_rules_steps and test_module_type_rules_steps: the shims' archive member does not link on its own; Tier 3 compares the shims with the C, and the caller cases run against the hybrid libobs.

Kept, characterized, not endorsed: an open code obs_open_module() never returns goes on to obs_init_module(), as the C's switch has no default.

Intentional difference: where the C would write the disabled state through a NULL pointer, the shims do not; obs-module.c always passes a local. route_null_state pins it.

RED → GREEN

  • RED commit: 61d57f6 obs-core: Add Tier 1 tests for module load rules. obs_core::module_load_rules has 27 tests: the seventeen C cases 1:1, the edges, and six 2048-case proptests. 24 of them fail on todo!() (Route::bits(), Route::state(), List::code() and the constants are not stubs).
  • GREEN: libobs: Port the module load rules to obs-core. Tier 1 27/27. Tier 2: test_module_load_steps 17/17 (with ASan and UBSan) and test_core_module_load against the C backend libobs, the hybrid libobs and libobs-c-reference; test_module_type_rules_steps and test_source_registration on the C backend.
    • In the hybrid libobs, the thirteen obs_module_load_rules_* symbols are the Rust shims (local), and no obs-module-load-rules object is linked. libobs-c-reference and the C backend still compile the C.
    • The exported sets are identical on all three builds (1766), before and after.
    • The shims take codes as int, types, states and route bits as uint32_t, lengths and counts as size_t; the list enum crosses as a u32 (32-bit on every target).
  • Tier 3: obs-core: Add Tier 3 parity for module load rules (module_load_rules_parity.rs, 12 tests). The oracle is the unmodified C file with its entry points renamed. Compared: the constants against the Rust ones and the C headers'; every function over every bool; open_route over every code from -64 to 64 plus the i32 ends, and the type checks over 24 types; the version rule and list answers at their edges; load_all_callback()'s whole decision as events, each side's functions in the C's order, for all 512 settings by 24 types and 9 codes; four 4096-case proptests. No proptest regression file: no case failed. Nothing here divides or traps on MSVC x64.
  • Mutation check (run on the Tier 3 commit, before the review fixes reshaped open_route and the open gate): 23 mutants, each reverted (not committed), 20 of the core and 3 of the shim. Every one fails Tier 3:
Mutant Tier 1 (of 27) Tier 3 (of 12)
open_args ignores the core 2 1
export_missing inverted 1 1
version word keeps the patch 5 2
version_ok refuses an equal version 1 1
an empty safe list allows none 4 3
an empty disabled list disables all 4 3
allow_disable always 1 1
is_core also matches plugins 5 3
is_legacy matches plugins 4 2
missing exports counted 3 3
a core module that fails to open is counted 5 5
a core module that fails to open keeps no type 4 3
an incompatible version is not disabled 3 3
an error is not counted 3 3
an unknown code stops before init 4 5
a failed init is not freed 4 4
a failed init is recorded as failed to open 4 3
a loaded module gets no type 4 4
a failure is counted without a failure list 4 2
core modules loaded with one failure 2 1
shim: list codes swapped 1 4
shim: state not written 0 3
shim: keep-type and set-type bits swapped 3 5

Four more after the review fixes, for the reshaped rules: arg_missing inverted (Tier 1 2, Tier 3 1), a failed open without CORE_CONTINUES (4, 3), an incompatible version that continues for a core module (3, 3), and the CORE_CONTINUES bit dropped from the route bits (2, 3).

  • port_comparison: module_load_rules (the list answers, the type checks, the version rule and the routes of one plugin that loads); its allocation check passes.
  • Real app (UI, protocol output or logging changes): N/A, no change in behaviour.

Runs were on 529cc02 (the head, rebased on current master), with RED rechecked on its RED commit (24 of 27 fail on todo!()): Tier 1 27/27, Tier 3 12/12, test_module_load_steps 17/17 (ASan and UBSan) and test_core_module_load on the C backend libobs, the hybrid libobs and libobs-c-reference, test_module_type_rules_steps and test_source_registration on the C backend, 0 skipped; the exported sets identical on all three (1766). Local checks: ./unittest's Rust lanes ok; --lane cross ok; Windows MSVC clippy --all-targets clean; port_comparison ok; the lint lane's formatting, ruff, ratchets, rustfmt, clippy and Dylint passes clean, and the build-group, ported-source, oracle, sorted-list, test-graph, cmocka and naming checks pass. The head is not stamped: the local gate needs a Docker it could not reach here, so PR CI runs the full suite.

No upstream issue.

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 (not applicable: no user-visible change)
  • (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)

Moves the pure decisions of the module loader from obs-module.c.h to
libobs/obs-module-load-rules.c.h, ahead of their port to obs-core.
Behaviour-neutral: no public function, header or signature changes.

Thirteen hidden entry points, declared in the new
obs-module-load-rules.h without EXPORT:
- arg_missing(): an argument obs_open_module() needs is missing,
  asked for each in its || chain, so the core is still read only with
  a module pointer and a path;
- export_missing(): a required export was not found, asked after each
  of the three lookups in load_module_exports(), as before;
- version_word() and version_ok(): the reported version without its
  patch number, and not above LIBOBS_API_VER;
- safe_list() and disabled_list(): from the list length alone, every
  module is listed, none is, or the name decides;
- allow_disable(), is_core() and is_legacy();
- open_route() and init_route(): what load_all_callback() does with
  obs_open_module()'s code and obs_init_module()'s result, as route
  bits and the state of the disabled module it makes. The open route
  does not take the module type: a failed open returns CORE_CONTINUES,
  and the C reads the type and asks is_core() only then, after making
  the disabled module, as before;
- count_failure() and core_loaded().

obs-module.c.h keeps get_plugin_info(), obs_get_module(),
obs_host_skip_module(), os_dlopen(), os_dlsym(), the ver() call, the
module set-up, obs_create_disabled_module(), obs_init_module(),
free_module(), the failure list, the module walks and every log
message, in the same order and under the same conditions: a list's
array, length and name lookup only when it is not empty, the
disabled list only for a module that is not core, the core list only
for a legacy plugin, the module type after obs_open_module() only for
a module that failed to open. A harness ran master's functions and
the moved ones over a logging stand-in (gcc and clang, -O0, -O2 and
ASan/UBSan): 300,000 random worlds, identical logs; 8 planted mutants
caught. The copied constants are checked against obs-defs.h and obs.h
with _Static_assert. The file joins libobs.core for now.

The exported symbol sets are unchanged (1766 on the C, hybrid and
c-reference builds).

Refs #2801.
Adds test_module_load_steps, a characterization of the module load
rules moved to libobs/obs-module-load-rules.c.h, ahead of their port
to obs-core.

The steps, compiled into the test from the moved file:
- the open gates, the required exports, the version word and rule
  (same major and minor with any patch, older, one minor and one major
  above, 0xFFFF0000, and the patch of the libobs version);
- the safe and disabled list rules at every list length, and the core
  and legacy types, out-of-range types included;
- the open route for every code: an unknown code goes on to
  obs_init_module(), as the C's switch has no default (characterized,
  not endorsed); the init route; the failure count and core result;
- load_all_callback()'s whole decision built on the steps, against
  the decisions read off the C before the move, for all 512 settings
  of what it reads, by 7 types and 8 codes: what is skipped, the
  disabled state, which module gets the type, what is freed and
  counted, and which lookups run;
- obs_load_core_modules() twice, after a success and after a failure.

The callers, on the real libobs: obs_open_module() before obs_startup()
and with no module pointer or path (MODULE_ERROR, no log), a missing
file (MODULE_FAILED_TO_OPEN and its warning),
obs_get_module_allow_disable() for a name that is no core module's,
and obs_is_core_module()/obs_is_legacy_module() on NULL.

Registered in test-graph.json like test_module_type_rules_steps, under
xvfb-run where a display is needed, with ASan and UBSan (no _rust
variant: the shims' archive member does not link on its own, as for
test_canvas_rules_steps). 17 of 17 on the C backend libobs,
the hybrid libobs and libobs-c-reference.

Refs #2801.
The safe core of libobs/obs-module-load-rules.c.h (#2801) as todo!()
stubs in rust/obs-core (module_load_rules), and its Tier 1 tests:
- arg_missing(), export_missing(), version_word(), version_ok(),
  safe_list() and disabled_list() (with List), allow_disable(),
  is_core(), is_legacy(), open_route() and init_route() (with Route),
  count_failure() and core_loaded();
- the seventeen cases of test_module_load_steps one to one, in the
  same order: load_all_callback()'s decision through the rules as
  obs-module.c calls them, against the decisions read off the C before
  the move, for all 512 settings of what it reads by 7 types and 8
  codes, which lookups run included; obs_load_core_modules() twice;
  and the callers through a model of obs_open_module() and the
  allow-disable, core and legacy queries;
- the edges, and six 2048-case proptests over any code, type, version
  word, libobs version and list length.

24 of the 27 fail on todo!(). Route::bits(), Route::state(),
List::code() and the constants are not stubs.

Refs #2801.
The module load rules of libobs/obs-module-load-rules.c.h (#2801) now
run in Rust: arg_missing(), export_missing(), version_word(),
version_ok(), safe_list() and disabled_list(), allow_disable(),
is_core(), is_legacy(), open_route() and init_route(),
count_failure() and core_loaded() in obs_core::module_load_rules,
behind thirteen C ABI shims in src/ffi/module_load_rules.rs.

The list enum crosses as a u32 (32-bit on every target), the route as
its OBS_MODULE_LOAD_RULES_* bits and the disabled state through the
caller's pointer, which the shims write only when it is not NULL
(obs-module.c always passes a local).

obs-module-load-rules.c.h moves to the ported unity group
libobs.ported-module-load-rules, whose PCH is only its own header:
libobs-c-reference and the C backend still compile it, the hybrid
libobs links the shims instead. The thirteen symbols are hidden
through rust-exports.map, rust-hidden.txt and
rust-unexports-macos.txt; the exported sets stay at 1766 on the C,
hybrid and c-reference builds.

Tier 1: 27 of 27. Tier 2: test_module_load_steps 17/17 and
test_core_module_load against the C backend libobs, the hybrid libobs
and libobs-c-reference.

Refs #2801.
module_load_rules_parity.rs compares the thirteen shims with the
original libobs/obs-module-load-rules.c.h, built unmodified as an
oracle with its entry points renamed (obs-c-oracle/oracle/
module_load_rules.c), which also gives the constants of
obs-module-load-rules.h, obs-defs.h and obs.h, and LIBOBS_API_VER:
- the constants, against the Rust ones and the C headers';
- every function over every bool it takes, and both init routes;
- open_route() over every code from -64 to 64 and the i32 ends, the
  state through the pointer included, and the type checks over 24
  module types;
- the version word and rule at the edges of LIBOBS_API_VER and the
  mask, the list answers and core result at the usize edges;
- load_all_callback()'s whole decision as events, each side's
  functions in the C's order, for all 512 settings of what it reads
  by 24 types and 9 codes;
- four 4096-case proptests over any version word, libobs version,
  list length, failure count, type and code.

Intentional difference: the shims do not write the state through a
NULL pointer, where the C would; route_null_state pins it.

Mutation check: 27 mutants (24 of the core, 3 of the shim), each
reverted; every one fails 1 to 5 of the 12 parity tests.

port_comparison gains module_load_rules: the list answers, the type
checks, the version rule and the routes of one plugin that loads.

Refs #2801.
Adds the module load rules (#2801) to rust/README.md (the obs-core
row and the port table), to naming.md's rust/obs-core row among the
units extracted from obs-module.c.h, and to the obs-core Cargo.toml
description and lib.rs module docs.

Fixes #2801.
@rdoupe
rdoupe force-pushed the fix/1837-libobs-move-the-hotkey-binding-p branch from bedfc12 to 529cc02 Compare October 28, 2026 15:10
@rdoupe
rdoupe marked this pull request as ready for review October 28, 2026 15:55
@rdoupe
rdoupe requested a review from zackees as a code owner October 28, 2026 15:55
@rdoupe
rdoupe added this pull request to the merge queue Oct 28, 2026
Merged via the queue into master with commit 4f74ca8 Oct 28, 2026
74 of 76 checks passed
@rdoupe
rdoupe deleted the fix/1837-libobs-move-the-hotkey-binding-p branch October 28, 2026 16:21
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…bs-rust#2843)

The macOS Tier 2 lane does not compile on master: the `macos-ci` preset
sets CMAKE_COMPILE_WARNING_AS_ERROR, and clang rejects the deliberate
`(asked++, call())` chain in test_module_load_steps.c (added by obs-rust#2807)
with `-Werror,-Wcomma`:

  test/cmocka/test_module_load_steps.c:65:26: error: possible misuse of
  comma operator here [-Werror,-Wcomma]

The comma operator there is the expression under test: it counts how many
operands of the `||` chain the short circuit actually evaluated. Existing
C tests are never edited to satisfy a warning (obs-rust#516), so the class is
turned off for the test target, next to the existing -Wno-pedantic /
-Wno-missing-prototypes / -Wno-strict-prototypes exemptions, for C (the
same guard those use).

RED: run 40753946475, job 123054397646 (a clean master checkout of
0faa3c1 fails to build once the lane is selected; obs-rust#2807 skipped it, and
master pushes do not select macOS, so it reached master unseen).
GREEN: the lane configures and builds with warnings as errors, and the
cmocka suite runs. Linux Tier 2 does not show the break: its build does
not set CMAKE_COMPILE_WARNING_AS_ERROR.
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 load rules in obs-module.c to obs-core

1 participant