Skip to content

libobs: Port the module locale files to obs-core - #1926

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

zackees merged 8 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-slice3

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

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

What and why

The third slice of libobs/obs-module.c.h moves to rust/obs-core: the two file names obs_module_load_locale() looks up in a module's data path, and its "same locale" decision. Before that, a small C fix: obs_module_get_config_path() returns NULL for a NULL module instead of crashing.

NULL module fix (first two commits). obs_module_get_config_path(NULL, file) read module->mod_name and crashed. It now returns NULL, as obs_find_module_file() does for a NULL module and as docs/sphinx/reference-modules.rst already says ("Path string, or NULL"). This follows the documented contract and has no downside, so it needs no design decision.

  • A NULL file was already safe: dstr_cat skips it, so the result is <config>/<name>/. A NULL or empty config path gives a relative path. libobs: Port module names and files to obs-core #1915 characterized both, and neither changes.
  • Callers: every in-tree caller passes obs_current_module(), through the obs_module_config_path() macro, aja-output-ui and decklink-output-ui. That is never NULL in a loaded module, so none of them sees a change.
  • Scripting: the Lua and Python bindings both %include "obs.h" and do not %ignore the function, so it is wrapped, and a script passing nil crashed OBS before this. SWIG was not run locally; this is read from obslua.i and obspython.i.

Feasibility. No seam is needed. obs_module_load_locale() passes the two locales in, and its parameter checks, the module, obs_find_module_file(), text_lookup_create(), text_lookup_add() and the logging stay C. The "same locale" decision is a pure astrcmpi(), so it moves too.

No exported function moves, so there is no rust-exports.d fragment, and the 1766 exported symbols are unchanged. The unit is its own file, obs-module-locale.c.h (Rust obs_core::module_locale), rather than an addition to obs-module-names.c.h. The hybrid build drops that file, so moving new C into it would break the hybrid link at the extraction commit. Left in obs-module.c.h for a later slice: the decision chain of load_all_callback() and the size checks of obs_register_*_s(). Overlap: no open PR touches obs-module.c.h.

Commits:

  • test: Expect NULL from obs_module_get_config_path for a NULL module: adds a NULL module, with and without a file, to module_config_path in test_core_module_load. It crashes on the unchanged C.
  • libobs: Return NULL from obs_module_get_config_path for a NULL module: the fix.
  • test: Characterize the module locale files: a new module_locale case in test_core_module_load, through obs_module_load_locale() and text_lookup_getstr(). The module's data path has locale/en-US.ini, de-DE.ini and EN-us.ini. Covered:
    • the default only;
    • another locale on top of the default;
    • the default in another case (EN-us), both ways;
    • a missing or empty locale;
    • a missing or empty default, and a missing data path;
    • NULL module, default and locale;
    • the two names as obs_find_module_file() resolves them, with and without a trailing '/' on the data path;
    • an empty data path.
  • libobs: Move the module locale files into obs-module-locale.c: a behaviour-neutral extraction that changes no public function, header or signature. Three hidden entry points: obs_module_locale_default_file, _is_default and _file.
  • RED, GREEN, Tier 3, then docs and port_comparison.

The double '/'. The second name is /locale/<locale>.ini, and obs_module_paths_find_file() adds a '/' after a data path that has none at the end. So the locale's file is <data>//locale/<locale>.ini. It still resolves: de-DE text is loaded on top of en-US, with or without a trailing '/' on the data path. It is not a bug that makes the locale miss, so it is kept as it is.

Safe core (rust/obs-core/src/module_locale.rs): default_file, locale_file and is_default.

  • Locales are bytes, with Option for NULL, and NULL is empty, as for the C's dstr_cat and astrcmpi.
  • is_default is obs-util's astrcmpi, so the case rule has one implementation.
  • The module denies clippy's indexing, arithmetic, unwrap and panic lints.

Shim (src/ffi/module_locale.rs): the three C signatures. The names are bmalloc'd strings the caller bfrees. libobs/obs-module-locale.c.h moves to libobs.ported-module-locale (PCH obs-internal.h), and the three symbols are hidden through rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt.

Kept, characterized, not endorsed:

  • The locale's name starts with '/' and the default's does not. After a data path the locale's file is <data>//locale/<locale>.ini, which resolves.
  • With an empty data path the default's file is relative to the working directory, and the locale's is absolute: /locale/<locale>.ini.
  • A locale that differs from the default only in case is never added, even when its own file exists.
  • A missing locale file keeps the default text, and a missing default gives NULL even when the locale's file exists.
  • The locales are not checked, so '/' and .. pass through.

Intentional differences: none.

RED → GREEN

  • NULL module: RED is b827294 test: Expect NULL from obs_module_get_config_path for a NULL module. test_core_module_load gives 18/19 on the C backend libobs: module_config_path fails with "Test failed with exception: Segmentation fault(11)". After 881feda it is 19/19.

  • Characterization: aebf0c3. test_core_module_load is 20/20 (19 + module_locale) on the C backend libobs, before and after the extraction (bd1bf3a).

  • RED commit: bf854c3 libobs: Add Tier 1 tests for the module locale files port. obs_core::module_locale has 9 tests: the C case 1:1, the lookup order, edge cases and four 2048-case proptests. All 9 fail on todo!(). With the todo!() core linked into the swapped hybrid libobs, test_core_module_load aborts (exit 134, "not yet implemented" in module_locale.rs).

  • GREEN: 41d4415 libobs: Port the module locale files to obs-core. Tier 1 9/9. Tier 2: test_core_module_load 20/20 against hybrid libobs and libobs-c-reference.

    • In hybrid libobs the three obs_module_locale_* symbols are the Rust shims, and no obs-module-locale object is linked.
    • libobs-c-reference and the C backend still compile the C.
  • Tier 3: 2949bcc (module_locale_parity.rs, 7 tests). The oracle is the unmodified C file with its entry points renamed, and its astrcmpi is the original util/dstr.c, through the dstr oracle. Compared:

    • the two names over 29 locales (NULL, empty, case, bytes outside ASCII, '/', .., %module%) and in 2048-case proptests;
    • is_default over every pair of those locales and in a 2048-case proptest, half of whose pairs are one locale in two cases;
    • what obs_module_load_locale() reads. Each side uses its own names, decision and obs_module_paths_find_file() (shim or oracle) on one real tree, for 6 data paths × 11 × 11 locales and in a 2048-case proptest, the double '/' included.

    The tree is a new directory in the temporary directory. Every data path is inside it, and the locales of the lookups have no '/', so nothing is looked up outside it (test: module_paths_parity find_matches_c_for_any_path can list the system temp dir and flake #1917).

  • Mutation check: 14 mutants of the safe core, each reverted (not committed). Each cell is the number of failing tests:

Mutant Tier 1 (of 9) Tier 3 (of 7)
default name starts with '/' 4 5
locale name without its leading '/' 4 5
extension .json 4 5
no extension 5 5
locale before the prefix 6 5
a NULL locale is "(null)" 3 2
locale name with the default's prefix 4 5
is_default case-sensitive 5 4
is_default prefix match 5 5
is_default never 5 5
is_default negated 5 5
is_default with Unicode case folding 1 1
is_default false for NULL 2 2
is_default with padding trimmed 2 2

The case-sensitive mutant also fails Tier 2 against hybrid libobs: test_core_module_load 19/20, with module_locale failing on "EN-us A" != "en A".

  • Rebased onto c9a6cce13 (obs-core: Port util/source-profiler.c #1887). The conflicts were only in the obs-core Cargo.toml description, the lib.rs docs and the rust/README.md row. After the rebase, ci/test_build_groups.py, ci/test_ported_sources.py, obs_core::module* in obs-tests-core (99/99) and the lint lane were re-run and pass.
  • 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, on 62ce80a88 (the head before the rebase onto c9a6cce13, obs-core: Port util/source-profiler.c #1887):
Library test_core_module_load Full ctest Exported symbols
C backend libobs 20/20 388/388, 0 skipped IDENTICAL (1766)
hybrid libobs 20/20 390/390, 0 skipped IDENTICAL (1766)
libobs-c-reference 20/20 390/390, 0 skipped IDENTICAL (1766)
  • Other local checks:
    • soldr cargo test -p obs-data --test obs-tests-core: 927/927 (obs_core::module_locale* 16/16).
    • soldr cargo test -p obs-core: passed.
    • 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_locale, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Each of these runs once per module at startup.
Benchmark Rust C Rust / C (run range)
module_locale/default_file 34.41 ns 61.37 ns 0.561 (0.547-0.570)
module_locale/locale_file 34.04 ns 38.21 ns 0.927 (0.889-0.941)
module_locale/is_default/same 10.47 ns 6.91 ns 1.515 (1.512-1.544)
module_locale/is_default/other 6.26 ns 4.10 ns 1.527 (1.523-1.528)
  • Real app: not applicable (no user-visible change; the NULL fix only affects a caller that passes no module).

Windows/macOS: the cross lane compiles and links the shims, 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. There, EN-us.ini and en-US.ini are one file in the parity tree, and both sides see the same file system.

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 10:21
obs_module_get_config_path() reads module->mod_name without checking
module, so a NULL module crashes, while obs_find_module_file() returns
NULL for one. module_config_path now expects NULL for a NULL module,
with a file and with a NULL file. This fails on the unchanged C: the
test crashes.

Refs obs-rust#1876
obs_module_get_config_path() read module->mod_name without checking
module, so a NULL module crashed the process. It now returns NULL, as
obs_find_module_file() does for a NULL module and as the reference
documentation says ("Path string, or NULL"). A NULL file still gives
"<config>/<name>/", and a NULL or empty config path a relative path.

In-tree callers all pass obs_current_module() (the
obs_module_config_path() macro, aja-output-ui and decklink-output-ui),
which is never NULL in a loaded module, so none of them sees a change.
The Lua and Python bindings wrap the function (both %include obs.h and
do not %ignore it), so a script passing nil no longer crashes OBS.

test_core_module_load: 19 of 19 on the C backend libobs (the
module_config_path case crashed before).

Refs obs-rust#1876
Characterization before the locale file names of
obs_module_load_locale() move to their own file and are ported to
obs-core (obs-rust#1876). A new case joins test_core_module_load, the module
test binary: module_locale, through obs_module_load_locale() and
text_lookup_getstr(), for a module whose data path holds
locale/en-US.ini, locale/de-DE.ini and locale/EN-us.ini:
- the default only, another locale on top of the default, and a locale
  that is the default in another case (not loaded, though its file
  exists);
- a missing locale (and an empty one), which keeps the default;
- a missing default (and an empty one, and a missing data path), which
  gives NULL even when the locale exists;
- NULL module, default locale and locale;
- the two names as obs_find_module_file() resolves them: the second
  starts with '/', so it is "<data>//locale/<locale>.ini", which still
  resolves, with or without a trailing '/' on the data path;
- an empty data path: the default from the working directory, the
  locale from the root ("/locale/<locale>.ini"), so the working
  directory's locale file is not read (skipped where the root has one).

test_core_module_load: 20 of 20 on the C backend libobs.

Refs obs-rust#1876
Moves the locale file names of obs_module_load_locale() from
obs-module.c.h to libobs/obs-module-locale.c.h, ahead of its port to
obs-core (obs-rust#1876). Behaviour-neutral: no public function, header or
signature changes.

Three hidden entry points, declared in obs-internal.h without EXPORT:
- obs_module_locale_default_file(): a bmalloc'd
  "locale/<default_locale>.ini";
- obs_module_locale_is_default(): astrcmpi(locale, default_locale) == 0;
- obs_module_locale_file(): a bmalloc'd "/locale/<locale>.ini".
Their dstr steps are the C's, unchanged: the names are built as before
and bfree'd after use instead of reusing one dstr. obs_module_load_locale()
keeps the parameter checks, the module, obs_find_module_file(),
text_lookup_create(), text_lookup_add() and the logging. The file joins
libobs.core for now, as obs-module-names.c.h did before its port.

test_core_module_load: 20 of 20 on the C backend libobs, as before the
move.

Refs obs-rust#1876
The safe core of libobs/obs-module-locale.c.h (obs-rust#1876) as todo!() stubs
in rust/obs-core/src/module_locale.rs, and its Tier 1 tests in the
obs-core module of the core test binary (obs-tests-core):
- module_locale: the module_locale case of test_core_module_load one to
  one (same files, same order, same expected text), with
  obs_module_load_locale() as module_paths::find_file() plus the core on
  a fake file system that resolves paths as a real one does (relative
  to the working directory, repeated '/' as one);
- load_asks_for_the_two_names_in_order: the paths asked for, the double
  '/' and the absolute name of an empty data path included;
- default_file, locale_file and is_default edges: NULL against empty,
  '/' and ".." passed through, bytes outside ASCII, ASCII-only case
  folding, prefixes;
- four 2048-case proptests over any bytes.

All 9 fail on todo!().

Refs obs-rust#1876
Ports libobs/obs-module-locale.c.h to the module_locale module of
rust/obs-core. Every obs_module_load_locale() (each module's
obs_module_set_locale()) takes the two locale file names and the "same
locale" decision from it. The hybrid libobs drops the C file and links
the Rust shims; obs-module.c.h keeps the parameter checks, the module,
obs_find_module_file(), the text lookups and the logging.

Safe core (src/module_locale.rs), on bytes, Option for NULL:
- default_file(): "locale/", the default locale, ".ini";
- locale_file(): "/locale/", the locale, ".ini";
- is_default(): obs-util's astrcmpi() of the two is 0 (ASCII case
  folded, NULL as empty), so the case rule has one implementation.
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): the
locale's name starts with '/', so after a data path it has two
("<data>//locale/<locale>.ini", which still resolves) and with an empty
data path it is absolute; a locale that differs from the default only
in case is never added; the locales are not checked, so '/' and ".."
pass through. No intentional differences.

Shim (src/ffi/module_locale.rs): the three C signatures. The names are
bmalloc'd strings the caller bfrees.

C side: the file leaves libobs.core for its own group,
libobs.ported-module-locale (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. ci/test_ported_sources.py expects the object in the ported
inventory on Linux, Windows and macOS.

Results: Tier 1 9 of 9. test_core_module_load (20 of 20, under a
private Xvfb) passes against the C-backend libobs, the hybrid libobs
(the three symbols are the Rust shims, and no obs-module-locale object
is linked) and libobs-c-reference (which still compiles the C).

Refs obs-rust#1876
Tier 3 for libobs/obs-module-locale.c.h (obs-rust#1876). The oracle
(oracle/module_locale.c) is the unmodified C file with its three entry
points renamed to oracle_*, and its astrcmpi renamed to the dstr
oracle's, so the "same locale" decision is the original util/dstr.c.

module_locale_parity.rs (7 tests) compares the shims with it:
- the default and locale file names for 29 locales (NULL, empty, case,
  bytes outside ASCII, '/', "..", %module%) and in 2048-case proptests
  over any bytes;
- is_default for every pair of those locales and in a 2048-case
  proptest, half of whose pairs are one locale in two cases;
- what obs_module_load_locale() reads, each side with its own names,
  decision and obs_module_paths_find_file() (the shim and the oracle's),
  on one real tree, for 6 data paths x 11 x 11 locales and in a
  2048-case proptest, the double '/' of the locale's name included.
The tree is a new directory in the temporary directory, removed on
drop; every data path is inside it, and the locales of the lookups have
no '/', so nothing is looked up outside it (obs-rust#1917). No intentional
differences.

obs-tests-core: obs_core::module_locale* 16 of 16 (9 Tier 1, 7 Tier 3).

Refs obs-rust#1876
… files

rust/README.md gets the libobs/obs-module-locale.c.h row (the third
slice of obs-module.c.h, obs-rust#1876): the swapped group, the three hidden
entry points, what obs-module.c.h keeps, the behaviour kept and not
endorsed, and the Tier 2 and Tier 3 coverage; the obs-core crate row and
docs/rust-port/naming.md list the new file.

port_comparison gets module_locale/default_file, /locale_file and
/is_default (same and other locale). Three passes pinned to one CPU,
Linux x86_64, rustc 1.98.1 (Rust / C): default_file 0.561, locale_file
0.927, is_default 1.515 (same) and 1.527 (other). The shims take each C
string's length before they compare, which astrcmpi does not need; that
is the few nanoseconds of is_default.

Refs obs-rust#1876
@rdoupe
rdoupe force-pushed the port/obs-module-slice3 branch from 62ce80a to d290282 Compare October 23, 2026 10:54
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into obs-rust:master with commit 452bd96 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