Repository navigation
libobs: Port module names and files to obs-core - #1915
Merged
Merged
Conversation
…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
force-pushed
the
port/obs-module-slice2
branch
from
October 23, 2026 08:09
e8f953a to
2dd2ff2
Compare
This was referenced Oct 23, 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.
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.hmoves torust/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_moduleand 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 andget_module_extension(), which is passed in.obs_module_get_config_path()readsobs->module_config_pathandmodule->mod_name. C passes both, and the exported function stays inobs-module.c.has a one-line wrapper.obs_module_load_metadata()readsmod->data_path. Theos_file_exists()check and the JSON parse stay C.is_safe_module()andis_disabled_module()loop overobs->safe_modules/obs->disabled_modules. C passes the array and the count, and keeps the empty-list checks.find_core_module()reads only itsobs_runtime_module_info. Its lookup (binary plus extension,os_file_exists(), the data path from slice 1'sobs_module_paths_data_dir(), the callback) moves. The name,info->nameand the non-core warning stay.strrchr()file name ofobs_open_module(),obs_create_disabled_module()andfind_core_module()moves with them.No exported function moves, so there is no
rust-exports.dfragment, and the 1766 exported symbols are unchanged. Left inobs-module.c.hfor a later slice: the decision chain ofload_all_callback(), theobs_register_*_s()size checks and the locale file names ofobs_module_load_locale(). Overlap: no open PR touchesobs-module.c.h(#1906 touchedobs_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 intest_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, throughobs_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()frommanifest.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 tolibobs/obs-module-names.c.has six hidden entry points:obs_module_names_file_name,_module_name,_config_path,_manifest_path,_listedand_find_core.port_comparison.Safe core (
rust/obs-core/src/module_names.rs):file_name,module_name,config_path,manifest_path,listedandfind_core. Paths and names are bytes, withOptionfor NULL, and the C'sdstrsteps are followed exactly, NULL against empty included.find_coreuses slice 1'sModuleFsandmodule_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 privatedstrand shim helpers becomepub(crate), and nothing else in slice 1 changes.Shim (
src/ffi/module_names.rs): the six C signatures.obs_module_names_file_namereturns a pointer into its argument. The others returnbmalloc'd strings, and the core module callback gets astruct obs_module_info2that is valid for the call, with the type passed through.libobs/obs-module-names.c.hmoves tolibobs.ported-module-names(PCHobs-internal.h), and the six symbols are hidden throughrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt.Kept, characterized, not endorsed:
noextisno, andx.dllisx...so,abc) has a NULL name, so its config path is<config>//<file>.manifest.json.Intentional differences (also in the parity test header, the core's docs and
rust/README.md):obs_create_disabled_module(&m, "/x/ab", ...)aborts atobs_shutdown()with the C backend, the hybridlibobsbefore the port, andlibobs-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.cnever 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
test_core_module_load18/18 (13 existing + 5 new) on the C backendlibobs, hybridlibobsandlibobs-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.libobs: Add Tier 1 tests for the module names and files port.obs_core::module_nameshas 24 tests: the five C cases 1:1, edge cases, and six proptests. All 24 fail ontodo!().libobs: Port module names and files to obs-core. Tier 1 24/24. Tier 2:test_core_module_load19/19 against hybridlibobsandlibobs-c-reference.module_names_parity.rs, 16 tests). The oracle is the unmodified C file with its entry points renamed. Itsobs_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_coreover 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_pathover 9 × 11 × 6 inputs, NULL and empty included;manifest_path,module_name(15 files × 3 extensions), thefile_nameoffset, andlisted(7 lists × 8 names);"", not NULLTier 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.OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON), headless, with a private Xvfb (-noreset), a private D-Bus and a fresh HOME, at the rebased head:test_core_module_loadlibobslibobslibobs-c-referenceIn hybrid
libobs, the sixobs_module_names_*symbols are the Rust shims. The production link has noobs-module-names.c.hobject, and the C reference still has one.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 lintand--lane cross: passed.ci/test_build_groups.py,ci/test_ported_sources.pyandci/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.strrchr()andstrcmp()do not need. That cost is the gap onfile_nameandlisted, a few tens of nanoseconds.os_file_exists(), which both sides call the same way.Windows/macOS: the shims use obs-util's
os_file_existson both, and the cross lane compiles and links them, but they were not run locally.test_core_module_loadis Linux-only. On Windows and macOS, PR CI's Rust lanes run Tier 1 and Tier 3.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 changes)