Repository navigation
libobs: Port the module load rules to obs-core - #2807
Merged
Merged
Conversation
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.
rdoupe
force-pushed
the
fix/1837-libobs-move-the-hotkey-binding-p
branch
from
October 28, 2026 15:10
bedfc12 to
529cc02
Compare
rdoupe
marked this pull request as ready for review
October 28, 2026 15:55
This was referenced Oct 28, 2026
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.
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2801
What and why
The next slice of
libobs/obs-module.c.hmoves torust/obs-core(module_load_rules): the pure decisions of the module loader. Those are the open gates ofobs_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 thatload_all_callback(),find_core_module(),obs_is_core_module()andobs_is_legacy_module()ask about, whatload_all_callback()does with eachobs_open_module()code andobs_init_module()result, whether a failure is counted, and theobs_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 thever()call;obs_create_disabled_module(),obs_init_module()andfree_module();load_core_modules(),obs_module_paths_find()andobs_module_names_find_core();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 asksobs_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 afterobs_open_module()only for a module that failed to open (the open route returnsCORE_CONTINUESand the C then asksobs_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.dfragment, 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 sixMODULE_*codes, the core and legacy module types and three load states, and defines the route bits;obs-module.c.hchecks the copies againstobs-defs.handobs.hwith_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 andblog). It built both with gcc and clang at -O0 and -O2 and under ASan/UBSan, and ran 300,000 random worlds throughobs_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 intest-graph.jsonin sorted order, underxvfb-runwhere a display is needed, with libm off MSVC.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.obs_open_module()beforeobs_startup()and without a module pointer or path, a missing file and its warning,obs_get_module_allow_disable(), andobs_is_core_module()/obs_is_legacy_module()on NULL.test_core_module_load(Linux) already loads real stub modules throughobs_load_core_modules(): one that can't be opened, one built for a newer libobs, and a retry after a failure._rustvariant of the characterization, as fortest_canvas_rules_stepsandtest_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 hybridlibobs.Kept, characterized, not endorsed: an open code
obs_open_module()never returns goes on toobs_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.calways passes a local.route_null_statepins it.RED → GREEN
obs-core: Add Tier 1 tests for module load rules.obs_core::module_load_ruleshas 27 tests: the seventeen C cases 1:1, the edges, and six 2048-case proptests. 24 of them fail ontodo!()(Route::bits(),Route::state(),List::code()and the constants are not stubs).libobs: Port the module load rules to obs-core. Tier 1 27/27. Tier 2:test_module_load_steps17/17 (with ASan and UBSan) andtest_core_module_loadagainst the C backendlibobs, the hybridlibobsandlibobs-c-reference;test_module_type_rules_stepsandtest_source_registrationon the C backend.libobs, the thirteenobs_module_load_rules_*symbols are the Rust shims (local), and noobs-module-load-rulesobject is linked.libobs-c-referenceand the C backend still compile the C.int, types, states and route bits asuint32_t, lengths and counts assize_t; the list enum crosses as au32(32-bit on every target).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_routeover every code from -64 to 64 plus thei32ends, 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.open_routeand the open gate): 23 mutants, each reverted (not committed), 20 of the core and 3 of the shim. Every one fails Tier 3:open_argsignores the coreexport_missinginvertedversion_okrefuses an equal versionallow_disablealwaysis_corealso matches pluginsis_legacymatches pluginsFour more after the review fixes, for the reshaped rules:
arg_missinginverted (Tier 1 2, Tier 3 1), a failed open withoutCORE_CONTINUES(4, 3), an incompatible version that continues for a core module (3, 3), and theCORE_CONTINUESbit 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.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_steps17/17 (ASan and UBSan) andtest_core_module_loadon the C backendlibobs, the hybridlibobsandlibobs-c-reference,test_module_type_rules_stepsandtest_source_registrationon the C backend, 0 skipped; the exported sets identical on all three (1766). Local checks:./unittest's Rust lanes ok;--lane crossok; Windows MSVC clippy--all-targetsclean;port_comparisonok; 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
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)