Skip to content

libobs: Port module names and files to obs-core - #1915

Merged
zackees merged 7 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-slice2
Oct 23, 2026
Merged

zackees merged 7 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-slice2

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1876 (slice 2 of obs-module.c.h; more slices may follow, filed on #1846). Unit 9 of #1846.

What and why

The second slice of libobs/obs-module.c.h moves to rust/obs-core: how a module is named from its binary, where its config file and manifest are, how the safe and disabled module lists match a name, and how a core module is found. The module lists, the config path, struct obs_module and all of the loading stay C.

Feasibility (checked before any code). No candidate needs a seam. Each reads at most a field or two, and C passes them in, as #1894 did:

  • get_module_name() reads nothing but its argument and get_module_extension(), which is passed in.
  • obs_module_get_config_path() reads obs->module_config_path and module->mod_name. C passes both, and the exported function stays in obs-module.c.h as a one-line wrapper.
  • The manifest path of obs_module_load_metadata() reads mod->data_path. The os_file_exists() check and the JSON parse stay C.
  • is_safe_module() and is_disabled_module() loop over obs->safe_modules / obs->disabled_modules. C passes the array and the count, and keeps the empty-list checks.
  • find_core_module() reads only its obs_runtime_module_info. Its lookup (binary plus extension, os_file_exists(), the data path from slice 1's obs_module_paths_data_dir(), the callback) moves. The name, info->name and the non-core warning stay.
  • The strrchr() file name of obs_open_module(), obs_create_disabled_module() and find_core_module() moves with them.

No exported function moves, so there is no rust-exports.d fragment, and the 1766 exported symbols are unchanged. Left in obs-module.c.h for a later slice: the decision chain of load_all_callback(), the obs_register_*_s() size checks and the locale file names of obs_module_load_locale(). Overlap: no open PR touches obs-module.c.h (#1906 touched obs_add_module_path() and merged before this rebase), and #1907 (image-file) and #1903 (obs-audio) are other files.

Commits:

  • test: Characterize module names, config paths, manifests and module lists: five cases in test_core_module_load, the existing module test binary, on the unchanged C:
    • core_module_paths: the child also reports each core module's file name, binary path and data path, the disabled one included;
    • module_names: the file name (a pointer into the binary path) and the name, through obs_create_disabled_module(), obs_open_module(), obs_get_module(), obs_get_disabled_module() and the config path;
    • module_config_path: config paths with one or two trailing '/', "/", relative, empty and NULL, and NULL, empty and absolute files;
    • module_manifest: obs_get_module_id(), _version() and _name() from manifest.json, for a trailing '/', a directory without one, a missing data path, and empty and NULL data paths;
    • safe_and_disabled_modules: obs_load_plugins() with safe and disabled lists, for plugins and core modules.
  • libobs: Move module names and files into obs-module-names.c: a behaviour-neutral extraction that changes nothing in the public API. The logic above moves to libobs/obs-module-names.c.h as six hidden entry points: obs_module_names_file_name, _module_name, _config_path, _manifest_path, _listed and _find_core.
  • RED, GREEN, Tier 3, then docs and port_comparison.

Safe core (rust/obs-core/src/module_names.rs): file_name, module_name, config_path, manifest_path, listed and find_core. Paths and names are bytes, with Option for NULL, and the C's dstr steps are followed exactly, NULL against empty included. find_core uses slice 1's ModuleFs and module_paths::data_dir, so the data path rules have one implementation. The module denies clippy's indexing, arithmetic, unwrap and panic lints. Slice 1's private dstr and shim helpers become pub(crate), and nothing else in slice 1 changes.

Shim (src/ffi/module_names.rs): the six C signatures. obs_module_names_file_name returns a pointer into its argument. The others return bmalloc'd strings, and the core module callback gets a struct obs_module_info2 that is valid for the call, with the type passed through. libobs/obs-module-names.c.h moves to libobs.ported-module-names (PCH obs-internal.h), and the six symbols are hidden through rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt.

Kept, characterized, not endorsed:

  • A module's name is its file name without the last three bytes (the length of ".so"), whatever they are: noext is no, and x.dll is x..
  • A file name that is exactly as long as the extension (.so, abc) has a NULL name, so its config path is <config>//<file>.
  • The config and manifest paths check only the last byte for '/'. An empty or NULL directory makes them relative, so a module without a data path reads the working directory's manifest.json.
  • The safe and disabled lists match whole names, case-sensitively. The disabled list does not apply to core modules, and the safe list does.
  • A core module's data path is reported whether or not it exists.

Intentional differences (also in the parity test header, the core's docs and rust/README.md):

  • A file name shorter than the extension has a NULL name. The C's length underflows there and the process crashes. Checked on the unchanged C: obs_create_disabled_module(&m, "/x/ab", ...) aborts at obs_shutdown() with the C backend, the hybrid libobs before the port, and libobs-c-reference. Nothing in libobs makes such a name, because the module search and the core loader always add the extension, so only a direct caller of the API can reach it.
  • obs-module.c never passes the following arguments, and the C dereferences or calls each: a NULL path has a NULL file name, a NULL extension is empty, a NULL name or list entry is on no list, and a NULL callback finds no core module.

RED → GREEN

  • Characterization: 2dc3860. test_core_module_load 18/18 (13 existing + 5 new) on the C backend libobs, hybrid libobs and libobs-c-reference, before and after the extraction (94373ea). It is 19/19 after the rebase onto libobs: Set the module type of obs_add_module_path() paths #1906, which added one case.
  • RED commit: 9bed2a0 libobs: Add Tier 1 tests for the module names and files port. obs_core::module_names has 24 tests: the five C cases 1:1, edge cases, and six proptests. All 24 fail on todo!().
  • GREEN: cd778d8 libobs: Port module names and files to obs-core. Tier 1 24/24. Tier 2: test_core_module_load 19/19 against hybrid libobs and libobs-c-reference.
  • Tier 3: 519d8be (module_names_parity.rs, 16 tests). The oracle is the unmodified C file with its entry points renamed. Its obs_module_paths_data_dir() is the oracle's own, so the core lookup is the original C all the way down. Both sides run on one real tree, with a callback that logs every call:
    • find_core over 12 binaries × 11 names × 11 data paths × 3 extensions (.so, .dll, ""): 4356 lookups. The result and every module (binary path, data path, name, type) are compared;
    • config_path over 9 × 11 × 6 inputs, NULL and empty included;
    • manifest_path, module_name (15 files × 3 extensions), the file_name offset, and listed (7 lists × 8 names);
    • 2048-case proptests for all six.
    • The intentional differences are tested on the shims alone.
  • Mutation check: 22 mutants of the safe core, each reverted (not committed). Each cell is the number of failing tests:
Mutant Tier 1 (of 24) Tier 3 (of 16)
file name after the first '/' 5 2
file name is the whole path 5 2
name cut at the last '.' 4 4
name cut only when it ends with the extension 4 3
a name cut to nothing is "", not NULL 3 3
one byte less cut 3 3
config: '/' after a trailing '/' 2 2
config: '/' for an empty config path 3 2
config: every trailing '/' taken off 2 2
config: no '/' before the file 4 2
config: no '/' before an empty file 3 2
manifest: no '/' 3 2
manifest: '/' for an empty data path 2 2
listed: case-insensitive 2 1
listed: prefix match 3 2
listed: the empty name never listed 2 2
core: no extension 8 2
core: the data path as given 6 2
core: data path only if it exists 7 2
core: reported without the binary 6 2
core: binary looked for first 4 0
core: name taken from the binary 5 2

Tier 3 cannot see "binary looked for first", because the order of the os_file_exists() calls changes nothing on a real file system. Tier 1's fake file system logs that order.

  • Local runs used two build trees (OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON), headless, with a private Xvfb (-noreset), a private D-Bus and a fresh HOME, at the rebased head:
Library test_core_module_load Full ctest Exported symbols
C backend libobs 19/19 not run IDENTICAL (1766)
hybrid libobs 19/19 386/386, 0 skipped IDENTICAL (1766)
libobs-c-reference 19/19 386/386, 0 skipped IDENTICAL (1766)

In hybrid libobs, the six obs_module_names_* symbols are the Rust shims. The production link has no obs-module-names.c.h object, and the C reference still has one.

  • Other local checks:
    • soldr cargo test -p obs-data --test obs-tests-core: 870/870 (obs_core::module_names* 40/40).
    • export_list (every shim exported or hidden): 3/3.
    • cargo test -p obs-studio-rust --test obs-tests-app native_build::: 35/35.
    • ci/local_gate.py --lane lint and --lane cross: passed.
    • ci/test_build_groups.py, ci/test_ported_sources.py and ci/test_oracle_standins.py: passed.
  • port_comparison: soldr cargo bench -p obs-c-oracle --bench port_comparison -- module_names, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Each of these runs once per module at startup.
    • The shims take each C string's length before they use it, which strrchr() and strcmp() do not need. That cost is the gap on file_name and listed, a few tens of nanoseconds.
    • The core lookups are dominated by os_file_exists(), which both sides call the same way.
Benchmark Rust C Rust / C (run range)
module_names/file_name 8.95 ns 4.37 ns 2.051 (2.043-2.061)
module_names/module_name 30.51 ns 30.31 ns 1.007 (1.006-1.012)
module_names/config_path 73.18 ns 65.23 ns 1.122 (1.090-1.253)
module_names/manifest_path 71.72 ns 57.54 ns 1.246 (0.982-1.279)
module_names/listed/last (16 names) 74.91 ns 41.44 ns 1.808 (1.772-1.835)
module_names/listed/miss (16 names) 74.02 ns 42.16 ns 1.756 (1.754-1.762)
module_names/find_core/hit 2.79 µs 2.69 µs 1.040 (1.032-1.041)
module_names/find_core/miss 2.57 µs 2.47 µs 1.040 (1.021-1.045)
  • Real app: not applicable (no user-visible change).

Windows/macOS: the shims use obs-util's os_file_exists on both, and the cross lane compiles and links them, but they were not run locally. test_core_module_load is Linux-only. On Windows and macOS, PR CI's Rust lanes run Tier 1 and Tier 3.

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 changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 07:36
…ists

Characterization before the next slice of obs-module.c (obs-rust#1876) moves to
its own file and is ported to obs-core: how a module is named from its
binary, where its config file and manifest are, how the safe and
disabled module lists match names, and the paths each core module gets.

Five cases join test_core_module_load, the module test binary:
- core_module_paths: the child also reports each core module's file
  name, binary path and data path ("<exe dir>/../" OBS_PLUGIN_PATH
  "/<name>.so" and "<exe dir>/../" OBS_DATA_PATH
  "/obs-modules/core/<name>"), a disabled one (its dependency missing)
  too;
- module_names: obs_create_disabled_module() and obs_open_module():
  the file name after the last '/' (a pointer into the binary path, the
  whole path without one), and the name obs_get_module() and
  obs_get_disabled_module() look up, as obs_module_get_config_path()
  shows it;
- module_config_path: the config path, one '/' when it has none at the
  end, the name, '/', the file, for config paths with one and two
  trailing '/', "/", relative, empty and NULL, and NULL, empty and
  absolute files;
- module_manifest: "manifest.json" in the data path (obs_get_module_id,
  obs_get_module_version, obs_get_module_name), with a trailing '/', a
  directory without one, a missing data path, and empty and NULL data
  paths;
- safe_and_disabled_modules: obs_load_plugins() with safe and disabled
  module lists, for plugins and core modules.

Characterized, not endorsed:
- The name is the file name without its last three bytes (the length
  of ".so"), whatever they are: "noext" is "no", "x.dll" is "x.".
- A file name of three bytes, or ".so", has a NULL name, and its config
  path is "<config>//<file>".
- A module without a config path, or with an empty one, gets a relative
  config path; only the last byte of the config path is checked for '/'.
- A module without a data path, or with an empty one, reads
  "manifest.json" in the working directory.
- The safe and disabled lists match whole names, case-sensitively; the
  disabled list does not apply to core modules, the safe list does.

Not characterized: a file name shorter than the extension. The C's
length underflows there and the process crashes.

18 of 18 pass against the C-backend libobs, under a private Xvfb.

Refs obs-rust#1876
Behavior-neutral extraction before the Rust port, the second slice of
obs-module.c (obs-rust#1876): its pure name and path logic moves into
libobs/obs-module-names.c.h and takes what it needs from its caller, as
obs-module-paths.c did, so the port never mirrors struct obs_module or
reads obs->module_config_path or the module lists.

- The strrchr() of obs_open_module(), obs_create_disabled_module() and
  find_core_module() becomes obs_module_names_file_name(path).
- get_module_name(file) becomes obs_module_names_module_name(file, ext),
  with get_module_extension() passed in (the C cached its length; the
  extension is a constant, so nothing changes).
- The body of obs_module_get_config_path() becomes
  obs_module_names_config_path(config_path, module_name, file), with
  obs->module_config_path and module->mod_name passed in.
- The manifest path of obs_module_load_metadata() becomes
  obs_module_names_manifest_path(data_path); the os_file_exists() check
  and the parse stay.
- The loops of is_safe_module() and is_disabled_module() become
  obs_module_names_listed(names, count, name); the empty-list checks
  stay.
- The lookup of find_core_module() becomes
  obs_module_names_find_core(binary, name, data, type, ext, callback,
  param); the name, info->name and the non-core warning stay.

obs-module.c.h keeps the module lists, the config path, struct
obs_module and all of the loading. The six functions are declared in
obs-internal.h without EXPORT, so they are hidden. The new file joins
libobs.core just before obs-module.c.h, with libobs.pch.h. No group, PCH
or source-sets.json change, and the exported symbols are unchanged
(1766). test_core_module_load: 18 of 18 against the C-backend libobs,
the hybrid libobs and libobs-c-reference.

Refs obs-rust#1876
RED for the port of libobs/obs-module-names.c.h to rust/obs-core,
module module_names. The safe core is a stub (todo!()): file_name()
(obs_module_names_file_name), module_name()
(obs_module_names_module_name), config_path()
(obs_module_names_config_path), manifest_path()
(obs_module_names_manifest_path), listed() (obs_module_names_listed) and
find_core() (obs_module_names_find_core). Paths and names are bytes,
Option for NULL; the file system is module_paths' ModuleFs.

tests/obs_core/module_names.rs ports the five module name and file cases
of test_core_module_load 1:1, under the same names, in the same order,
with the same paths and expected values: find_core() for the paths the
core module loader gives each core module, file_name() and module_name()
for the names a module gets, config_path() for
obs_module_get_config_path(), manifest_path() for the manifest a module
reads, and listed() under the safe and disabled list checks of
obs_load_plugins(). The "characterized, not endorsed" cases stay pinned.

Edge cases: file names of empty paths, trailing and repeated '/',
backslashes (not separators) and non-UTF-8 bytes, and that the file
name points into the path; module names for the macOS ("") and Windows
(".dll") extensions, names cut to nothing, NULL and empty files; config
and manifest paths of NULL and empty parts; list matches (case, prefix,
duplicates, the empty name, the first match ends the walk); and
find_core(): what it asks the file system and in which order, the data
path rules of obs_module_paths_data_dir() ("lib" fallback, NULL data
paths reported as NULL), the extensions, an empty or NULL binary and a
NULL name. Six proptests check each function against the written-out
rule over any bytes. One intentional difference is pinned: a file name
shorter than the extension has no name (the C's length underflows).

The tests are a module of the existing core category binary,
obs-tests-core.

soldr cargo test -p obs-data --test obs-tests-core obs_core::module_names
fails 24 of 24 with "not yet implemented".

Refs obs-rust#1876
Ports libobs/obs-module-names.c.h to the module_names module of
rust/obs-core. Every module obs_open_module() opens and
obs_create_disabled_module() records gets its file name and name from
it, every obs_module_get_config_path() and every manifest path go
through it, the safe and disabled module lists of obs_load_plugins() are
matched by it, and every core module is found by it. The hybrid libobs
drops the C file and links the Rust shims; obs-module.c.h keeps the
module lists, the config path, struct obs_module and all of the loading.

Safe core (src/module_names.rs), on bytes, Option for NULL:
- file_name(): the bytes after the last '/', or the whole path;
- module_name(): the file name without the length of the extension at
  its end, NULL when that leaves nothing;
- config_path(): the config path, one '/' when it is not empty and has
  none at the end, the name, '/', the file;
- manifest_path(): the data path, the same '/', "manifest.json";
- listed(): the name is one of the names, byte for byte;
- find_core(): when the binary plus the extension exists, reports it
  with module_paths::data_dir() of the name and data path (made first,
  and reported whether or not it exists) and the name.
The C's dstr steps are followed exactly, NULL against empty included.
Nothing panics, indexes or overflows; the module denies clippy's
indexing, arithmetic, unwrap and panic lints. module_paths' dstr helpers
and its shim helpers become pub(crate) for it; nothing else changes
there.

Kept as the C has it, characterized and not endorsed (obs-rust#1876): the name
is the file name without the length of the extension, whatever those
bytes are; a file name as long as the extension has no name; the config
and manifest paths check only the last byte for '/', and an empty or
NULL directory makes them relative; find_core() reports the data path
whether or not it exists.

Shim (src/ffi/module_names.rs): the six functions with the C
signatures. obs_module_names_file_name() returns a pointer into its
argument; the others return bmalloc'd strings the caller bfrees. The
file system is libobs's own os_file_exists(), and the core module
callback gets a struct obs_module_info2 whose strings are valid for the
call, with the type passed through. Intentional differences: a file name
shorter than the extension has no name (the C's length underflows and
the process crashes); for arguments obs-module.c never passes, a NULL
path has a NULL file name, a NULL extension is empty, a NULL name or
list entry is on no list, and a NULL callback finds no core module.

C side: the file leaves libobs.core for its own group,
libobs.ported-module-names (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h, so the C reference and the C backend keep compiling it.
The functions are declared in obs-internal.h without EXPORT, so the
shims are hidden: rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. libobs-rust already re-exports obs-core's
ffi.

Results: test_core_module_load (18 of 18, under a private Xvfb) passes
against the C-backend libobs, the hybrid libobs and
libobs-c-reference. The exported symbol sets are identical, 1766 in
each. Tier 1: obs_core::module_names 24 of 24; obs-tests-core 854 of
854.

Refs obs-rust#1876
…al C

The oracle, oracle/module_names.c, is libobs/obs-module-names.c.h,
unmodified, with its six functions renamed to oracle_*, and its
obs_module_paths_data_dir() the oracle's own (oracle/module_paths.c), so
the core module lookup is the original C all the way down. The rest
keeps its real names: os_file_exists, the dstr helpers, bmalloc and
bfree are obs-util's under cargo test, so both sides look at the same
file system and their strings are bfree'd alike.

Tier 3 (tests/obs_core/module_names_parity.rs), in obs-tests-core,
builds a real tree under a new directory in the temporary directory
(core module binaries with .so and .dll, a "lib" one, a bundle
directory, dotted, spaced and non-ASCII names, data directories with and
without a "lib" name, a relative ".so") and calls both through the C
signatures, with a callback that logs every call. Compared:

- obs_module_names_find_core(): the result and every module reported
  (binary path, data path, name, NULL included, the type passed
  through), over 12 binaries (NULL, "", missing, a directory) x 11 names
  (NULL, "", "lib", "%module%", '/' in them) x 11 data paths (NULL, "",
  "/", trailing separators, %module%, the "lib" fallback, relative) x 3
  extensions (".so", ".dll", ""): 4356 lookups;
- obs_module_names_config_path() over 9 config paths x 11 names x 6
  files (NULL and empty included), obs_module_names_manifest_path(),
  obs_module_names_module_name() over 15 files x 3 extensions,
  obs_module_names_file_name() (the offset into the path) and
  obs_module_names_listed() over 7 lists x 8 names;
- proptests (2048 cases each) over paths and names built from the
  tree's names, separators, dots and %module% pieces, for all six.

Excluded, the intentional differences, tested on the shims alone: a file
name shorter than the extension, a NULL path or extension, NULL names
and list entries, and a NULL callback. 16 of 16 pass.

Deliberate breaks of the safe core, not committed, each caught (failed
tests of Tier 1, 24, and Tier 3, 16):

| Mutant                                   | Tier 1 | Tier 3 |
| file name after the first '/'            | 5      | 2      |
| file name is the whole path              | 5      | 2      |
| name cut at the last '.'                 | 4      | 4      |
| name cut only when it ends with ext      | 4      | 3      |
| a name cut to nothing is "", not NULL    | 3      | 3      |
| one byte less cut                        | 3      | 3      |
| config: '/' after a trailing '/'         | 2      | 2      |
| config: '/' for an empty config path     | 3      | 2      |
| config: every trailing '/' taken off     | 2      | 2      |
| config: no '/' before the file           | 4      | 2      |
| config: no '/' before an empty file      | 3      | 2      |
| manifest: no '/'                         | 3      | 2      |
| manifest: '/' for an empty data path     | 2      | 2      |
| listed: case-insensitive                 | 2      | 1      |
| listed: prefix match                     | 3      | 2      |
| listed: the empty name never listed      | 2      | 2      |
| core: no extension                       | 8      | 2      |
| core: the data path as given             | 6      | 2      |
| core: data path only if it exists        | 7      | 2      |
| core: reported without the binary        | 6      | 2      |
| core: binary looked for first            | 4      | 0      |
| core: name from the binary               | 5      | 2      |

Tier 3 cannot see "binary looked for first": the order of the
os_file_exists() calls changes nothing on a real file system. Tier 1's
fake one logs it.

Refs obs-rust#1876
…files

naming.md: obs-module-names.c.h, extracted from obs-module.c.h, goes in
rust/obs-core. rust/README.md: the obs-core layout row names it, and the
obs-module-names.c.h row of the ported table: the swap, what stays in
obs-module.c.h, what C passes in, the behavior kept from the
characterization, the intentional differences and what Tier 3 compares.
obs-core's tests are already in the core category binary,
obs-tests-core.

port_comparison: module_names/{file_name, module_name, config_path,
manifest_path, listed/last, listed/miss, find_core/hit, find_core/miss},
shim against oracle, in benches/port_comparison/core.rs, the core
lookups on the small real tree of the module_paths benchmarks (now with
16 core module binaries). The shims measure each C string before they
use it, which strrchr() and strcmp() do not need; the lookups are
dominated by os_file_exists(). Each runs once per module at startup.

Refs obs-rust#1876
find_core_matches_c_over_every_core_module required more than 1000 of
its 4356 lookups to find a binary. Windows finds 968 (its extensions
match fewer of the tree's files), so the run failed although every
lookup matched the C. The check is now a share of the lookups (more
than a fifth), which still fails on a broken tree.

Refs obs-rust#1876
@rdoupe
rdoupe force-pushed the port/obs-module-slice2 branch from e8f953a to 2dd2ff2 Compare October 23, 2026 08:09
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into obs-rust:master with commit 28a561a Oct 23, 2026
33 checks passed
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.

2 participants