Repository navigation
libobs: Port the module search paths to obs-core - #1894
Merged
Merged
Conversation
10 tasks done
Characterization before the module search paths of obs-module.c move to their own file and are ported to obs-core. Nothing tested how modules are found: test_core_module_load only loads core modules by name. Nine cases join test_core_module_load, the module test binary, and use the public API only, so they also run against the hybrid libobs. Each starts its own libobs in this process and lays out empty files and directories under a new root (in TMPDIR, else next to the binary). They pin: - a binary directory without %module%: every *.so file in glob order; directories (one named dir.so too) and other files are skipped; the data path with %module% replaced by the name; - %module% in the binary directory: every directory where the path up to %module% ends, <name>.so, then lib<name>.so; a directory without a binary is skipped; - the "lib" fallback of the data path, in any case; - every %module% of the data path, and of the binary directory after the first, and a data path without %module%; - one '/' added to a binary directory, one trailing '/' taken off a data path; - a binary directory that does not exist, NULL paths (not added), an empty data path and "/"; - a path added twice, and obs_find_modules() next to obs_find_modules2(); - obs_find_module_file() and obs_get_module_data_path(): a file, a missing file, a directory, NULL and empty files, a leading '/', a NULL module, a trailing '/' on the data path, a data path that does not exist, an empty and a NULL data path; - the data path obs_load_plugins() gives a plugin it loads, "lib" fallback included. Characterized, not endorsed: - A data path is reported whether or not it exists, and for a "lib" name whose data directory does not exist, the one without "lib" is reported whether or not it exists. - A module directory with a '.' in its name is looked up under the name up to its last '.', so it is never found. - A directory passes for a module binary. - An empty data path, or "/", reports no module at all, and only one trailing '/' is taken off a data path. - obs_find_module_file() with a NULL or empty file returns the data path itself; with an empty or NULL data path it looks in the working directory. 13 of 13 pass against the C-backend libobs, the hybrid libobs and libobs-c-reference, under a private Xvfb. Refs obs-rust#1876
Behavior-neutral extraction before the Rust port: the path logic of obs-module.c.h moves into libobs/obs-module-paths.c.h and takes what it needs from its caller, as obs_context_name_dup() takes &obs->data.unnamed_index (obs-rust#1788), so the port never mirrors struct obs_module or reads obs->module_paths. - make_data_directory() becomes obs_module_paths_data_dir(name, data_dir), with make_data_dir() beside it. - find_modules_in_path(omp, callback, param) becomes obs_module_paths_find(bin, data, type, ext, add_extension, callback, param): the fields of the search path, the module file extension and the host's binary extension hook. parse_binary_from_directory() and process_found_module() move with it and take the same fields; their get_module_extension() and obs_host_add_module_extension() calls become ext and add_extension(). - The body of obs_find_module_file() becomes obs_module_paths_find_file(data_path, file). - The two pointer differences that dstr_resize() takes get a (size_t) cast, as both are non-negative: the oracle compiles the file under -Wsign-conversion. obs-module.c.h keeps the search path list, the module list and the loading. obs_find_modules2() walks obs->module_paths as before and passes each path's bin, data and type with get_module_extension() and obs_host_add_module_extension; obs_load_plugins() passes its obs_runtime_module_info the same way (no obs_module_path on the stack); find_core_module() calls obs_module_paths_data_dir(); and obs_find_module_file() keeps its NULL module check and passes module->data_path. The three entry points and the hook's type, obs_module_add_extension_t, 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: 13 of 13 against the C-backend libobs, the hybrid libobs and libobs-c-reference. Refs obs-rust#1876
RED for the port of libobs/obs-module-paths.c.h to rust/obs-core,
module module_paths. The safe core is a stub (todo!()): data_dir()
(obs_module_paths_data_dir), find_file() (obs_module_paths_find_file),
find() (obs_module_paths_find) and search_pattern(), the glob pattern
find() builds. Paths are bytes, Option for NULL. The file system is the
caller's ModuleFs (os_file_exists, os_glob), and the host's extension
hook a closure on the path being built.
tests/obs_core/module_paths.rs ports the nine module search path cases
of test_core_module_load 1:1, under the same names, in the same order,
with the same layouts and expected values, on a fake file system: find()
for obs_find_modules2() over each added path, find_file() for
obs_find_module_file() on a module with that data path. The
"characterized, not endorsed" cases stay pinned.
Edge cases: the glob pattern for every form of binary directory, one
glob per path, a failed glob, "." and ".." entries, the glob's directory
flag, names cut at the last '.', a file name that is only an extension
(a NULL name), names and directories that hold %module% (not replaced
again), the hook's calls and a hook that empties the path, the macOS
extension ("") with the Cocoa hook, the Windows extension without the
".so" fallback, NULL against empty data paths and files, the "lib"
prefix (ASCII, once), and what data_dir() asks the file system. Three
proptests: data_dir() and find_file() against the written-out rule over
any bytes, and a flat search over any set of names. One intentional
difference is pinned: an empty binary directory searches nothing (the C
passes a NULL dstr to strstr()).
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_paths
fails 30 of 31 with "not yet implemented"; the 31st checks the two
constants.
Refs obs-rust#1876
Ports libobs/obs-module-paths.c.h to the module_paths module of rust/obs-core. Every module obs_find_modules2() and obs_load_plugins() find, the data path of every core module and every obs_find_module_file() (so every module's locale lookup) go through it. The hybrid libobs drops the C file and links the Rust shims; obs-module.c.h keeps the search path list, the module list and all of the loading. Safe core (src/module_paths.rs), on bytes, Option for NULL: - data_dir(): every %module% of the data path replaced by the name, one trailing '/' taken off, and for a "lib" name (ASCII, any case) whose path does not exist, the path for the name without "lib"; - find_file(): the data path, one '/' when it has none and the file is not empty, the file; None when that does not exist; - search_pattern(): the glob of a binary directory: "<dir>/*<ext>", or, with %module%, "<dir up to the first %module%>/*" for directories; - find(): every match of that glob of the right kind, the name up to its last '.', "." and ".." skipped; for a module directory the binary is <name> plus the host's extension, else lib<name><ext>; reported with its data path. The file system is the caller's ModuleFs and the host's extension hook a closure. The C's dstr steps are followed exactly, NULL against empty included (a copy of "" is NULL, a path cut to nothing is NULL). Nothing panics, indexes or overflows; the module denies clippy's indexing, arithmetic, unwrap and panic lints. Kept as the C has it, characterized and not endorsed (obs-rust#1876): data paths are reported whether or not they exist, and so is the "lib" fallback; only one trailing '/' is taken off, and an empty or "/" data path reports no module; a module directory with a '.' in its name is never found; a directory passes for a binary; the C's ".so" "legacy fallback" is overwritten before it is tried; find_file() with an empty file is the data path, and with an empty data path a relative path. The "lib" prefix is matched in ASCII, where the C's toupper() follows the C locale. Shim (src/ffi/module_paths.rs): the three functions with the C signatures. The file system is libobs's own os_file_exists() and os_glob() (obs-util's ports). The hook is the caller's obs_host_add_module_extension(), called with a bmalloc'd struct dstr it may grow; the callback gets a struct obs_module_info2 whose strings are valid for the call, with the type passed through. The paths are bmalloc'd and the caller bfrees them. Intentional differences, for arguments obs-module.c never passes: an empty or NULL binary directory searches nothing (the C hands a NULL dstr to strstr() and crashes, as obs_add_module_path("", ...) did), a NULL callback searches nothing, and a NULL hook leaves the path as it is. C side: the file leaves libobs.core for its own group, libobs.ported-module-paths (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, and obs-core now depends on obs-util for the file system, bmem and dstr. Results: test_core_module_load (13 of 13, 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_paths 31 of 31. Refs obs-rust#1876
The oracle, oracle/module_paths.c, is libobs/obs-module-paths.c.h,
unmodified, with its three functions renamed to oracle_*. The rest
keeps its real names: os_file_exists, os_glob, os_globfree, the dstr
helpers, astrcmpi_n, bmalloc and bfree are obs-util's under cargo test,
so both sides search the same file system and their paths are bfree'd
alike. It also measures struct obs_module_info2 for the layout test.
Tier 3 (tests/obs_core/module_paths_parity.rs), in obs-tests-core,
builds a real tree under a new directory in the temporary directory
(flat plugins with .so, .dll, lib and LIB names, no extension, dotted,
spaced, non-ASCII and, on Linux, non-UTF-8 names, a directory named
dir.so; module directories with and without binaries, lib binaries, a
dotted one, a v.so directory, a bundle directory, a legacy .so, one
named %module%; data directories) and calls both through the C
signatures with the same hooks and callbacks, which log every call.
Compared:
- obs_module_paths_find(): every module reported (binary path, data
path, name, NULL included, the type passed through), in order, and
every hook call with the path it got, over 13 binary directories x 16
data paths (NULL, "", "/", "//", trailing separators, repeated and
missing %module%, relative ones) x 4 extensions (".so", ".dll", "",
NULL) x 4 hooks (".so", ".dll", none, the Cocoa one): 3328 searches;
- obs_module_paths_data_dir() over 20 names x 16 data paths, and
obs_module_paths_find_file() over 10 data paths x 13 files;
- proptests (2048 cases each) over paths built from the tree's names,
separators, dots and %module% pieces, for all three;
- the obs_module_info2 layout: size, alignment and every offset.
Excluded, the intentional differences, tested on the shims alone: an
empty or NULL binary directory, a NULL callback and a NULL hook. 11 of
11 pass.
Deliberate breaks of the safe core, not committed, each caught (failed
tests of Tier 1, 31, and Tier 3, 11):
| Mutant | Tier 1 | Tier 3 |
| one trailing '/' not taken off | 6 | 4 |
| every trailing '/' taken off | 2 | 3 |
| "lib" case-sensitive | 3 | 4 |
| no "lib" data fallback | 10 | 4 |
| "lib" fallback only if it exists | 9 | 4 |
| first %module% only | 2 | 4 |
| the replacement searched again | 2 | 4 |
| a copy of "" is "", not NULL | 5 | 3 |
| '/' before an empty file | 1 | 1 |
| '/' after a trailing '/' | 3 | 2 |
| the extension on a directory search | 10 | 4 |
| cut at the last %module% | 2 | 2 |
| no lib<name> binary | 5 | 2 |
| the ".so" fallback tried | 1 | 2 |
| the name cut at the first '.' | 1 | 2 |
| "." and ".." not skipped | 1 | 0 |
| the directory flag inverted | 18 | 4 |
| the hook not called | 8 | 3 |
Tier 3 cannot see the "." and ".." mutant: a real glob never returns
them. Tier 1's fake one does.
Refs obs-rust#1876
… paths
naming.md: obs-module-paths.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-paths.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 ASCII "lib" match, 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_paths/{data_dir, data_dir_lib, find_file/hit,
find_file/miss, find/flat, find/module_dirs} on a small real tree (16
plugins, 16 lib plugins, 16 module directories), shim against oracle,
in benches/port_comparison/core.rs (obs-c-oracle now dev-depends on
obs-core). Both sides make the same os_file_exists() and os_glob()
calls, which dominate.
Refs obs-rust#1876
zackees
force-pushed
the
port/obs-module-paths
branch
from
October 23, 2026 05:43
4eb3d88 to
959c4ef
Compare
zackees
enabled auto-merge
October 23, 2026 05:43
4 of 7 tasks
This was referenced Oct 23, 2026
Closed
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 1 of
obs-module.c.h; the next slice gets filed on #1846 when this one closes). Unit 9 of #1846.What and why
The first slice of
libobs/obs-module.c.hmoves torust/obs-core: how modules are found on a search path, the data path each one gets, and the lookup behindobs_find_module_file(). Loading (os_dlopen,obs_open_module,obs_init_module, post-load), the module list and the search path list stay C.Feasibility (checked before any code). Of the target functions, only two touch private state, and neither needs a seam.
obs_find_module_file()reads one field,module->data_path, andobs_find_modules2()walksobs->module_paths. Everything else is pure path logic: string building,%module%substitution,os_glob()andos_file_exists(), both already ported to obs-util. The platform-specific parts (get_module_extension()and the macOS bundle hookobs_host_add_module_extension()) are passed in. So C passes the fields in, as #1788 and #1825 did, and keeps the walk:obs_add_module_path,obs_find_modules2/obs_find_modules(the walk overobs->module_paths),obs_get_module_data_path(a field read),find_core_module,obs_module_get_config_pathand all of the loading stay inobs-module.c.h. No exported function moves, so there is norust-exports.dfragment, and the 1766 exported symbols are unchanged.obs_find_data_fileis inobs.c.h, notobs-module.c.h, and goes through the platform'sfind_libobs_data_file, so it is not part of this slice.Commits:
test: Characterize the module search paths: nine cases intest_core_module_load, the existing module test binary, on the unchanged C. They cover the flat and%module%searches, the "lib" fallbacks,%module%substitution (repeated, missing), trailing separators, missing directories, NULL and empty paths, duplicate paths,obs_find_modulesnext toobs_find_modules2,obs_find_module_file/obs_get_module_data_path(files, directories, NULL/empty files, a leading '/', NULL module, empty/NULL/missing data paths), and the data pathobs_load_plugins()gives a plugin.libobs: Move the module search paths into obs-module-paths.c: a behaviour-neutral extraction that changes nothing in the public API.make_data_directory,parse_binary_from_directory,process_found_module,find_modules_in_pathand the body ofobs_find_module_filemove tolibobs/obs-module-paths.c.h. There they become three hidden entry points that take the search path's fields, the extension and the hook:obs_module_paths_data_dir,obs_module_paths_findandobs_module_paths_find_file. Two(size_t)casts on non-negative pointer differences let the oracle build under-Wsign-conversion.port_comparison.Safe core (
rust/obs-core/src/module_paths.rs):data_dir,find_file,search_patternandfind. Paths are bytes, withOptionfor NULL. The C'sdstrsteps are followed exactly, NULL against empty included: a copy of""is NULL, and a path cut to nothing is NULL. The file system is aModuleFstrait (realos_file_exists/os_globin the shim, a fake in Tier 1), and the host hook is a closure. The module denies clippy's indexing, arithmetic, unwrap and panic lints.Shim (
src/ffi/module_paths.rs): the three C signatures. The hook gets abmalloc'dstruct dstrthat it may grow. The callback'sstruct obs_module_info2strings are valid for the call, the type is passed through, and returned paths arebmalloc'd.libobs/obs-module-paths.c.hmoves tolibobs.ported-module-paths(PCHobs-internal.h), and the three symbols are hidden throughrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt. obs-core now depends on obs-util.Kept, characterized, not endorsed:
"/"data path reports no module.obs_find_module_filewith a NULL or empty file returns the data path itself, and with an empty or NULL data path it looks in the working directory.The "lib" prefix is matched in ASCII, where the C's
toupperfollows the C locale.Intentional differences (also in the parity test header, the core's docs and
rust/README.md):dstrand passes that tostrstr(). Checked on the unchanged C:obs_add_module_path("", ...)followed byobs_find_modules2()segfaults with the C backend andlibobs-c-reference, and returns no modules with the hybridlibobs.obs-module.cnever passes either.RED → GREEN
test_core_module_load13/13 (4 existing + 9 new) on the C backendlibobs, hybridlibobsandlibobs-c-reference, before and after the extraction (7d4212b).libobs: Add Tier 1 tests for the module search paths port.obs_core::module_paths(31 tests: the nine C cases 1:1 on a fake file system, plus edge cases and three proptests) fails 30 of 31 ontodo!(). The 31st checks the two constants.libobs: Port the module search paths to obs-core. Tier 1 31/31; Tier 2test_core_module_load13/13 against hybridlibobsandlibobs-c-reference.module_paths_parity.rs, 11 tests). The oracle is the unmodified C file with its entry points renamed. Both sides run on one real tree, with hooks and callbacks that log every call:findover 13 binary directories × 16 data paths × 4 extensions (.so,.dll,"", NULL) × 4 hooks (.so,.dll, none, the Cocoa one): 3328 searches. Every module (binary path, data path, name, type) is compared in order, along with every hook call and its path;data_dirover 20 names × 16 data paths, andfind_fileover 10 data paths × 13 files;obs_module_info2layout.%module%only""is"", not NULL%module%lib<name>binaryTier 3 cannot see the "." and ".." mutant, because a real glob never returns those entries. Tier 1's fake glob does.
OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON), headless, with a private Xvfb (-noreset), a private D-Bus and a fresh HOME:test_core_module_loadlibobslibobstest_pulse_monitor_devicefailed once under-j4, a default-sink race, and passed 3/3 on its own)libobs-c-referenceIn hybrid
libobs, the threeobs_module_paths_*symbols are the Rust shims. The production link has noobs-module-paths.c.hobject, and the C reference still has one.soldr cargo test -p obs-data --test obs-tests-core obs_core::(obs-tests-core, the core category binary): 98/98; the whole binary 829/829.export_list(every shim exported or hidden) 3/3.ci/local_gate.py --lane lint: passed, at the rebased head too. It covers clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, build groups, the test-binary cap and the ifdef ratchet.--lane cross: passed (Windows and macOS clippy/Dylints, and a link of every test binary forx86_64-pc-windows-msvcandaarch64-apple-darwin).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_paths, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Both sides make the sameos_file_exists/os_globcalls, which dominate the times. The rest of the gap is the shim's NUL-terminated copy for each file-system call. This code runs once per module search at startup.Windows/macOS: the shims use obs-util's
os_glob/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)