Repository navigation
libobs: Port the module locale files to obs-core - #1926
Merged
Merged
Conversation
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
force-pushed
the
port/obs-module-slice3
branch
from
October 23, 2026 10:54
62ce80a to
d290282
Compare
6 of 7 tasks
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 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.hmoves torust/obs-core: the two file namesobs_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)readmodule->mod_nameand crashed. It now returns NULL, asobs_find_module_file()does for a NULL module and asdocs/sphinx/reference-modules.rstalready says ("Path string, or NULL"). This follows the documented contract and has no downside, so it needs no design decision.filewas already safe:dstr_catskips 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.obs_current_module(), through theobs_module_config_path()macro,aja-output-uianddecklink-output-ui. That is never NULL in a loaded module, so none of them sees a change.%include "obs.h"and do not%ignorethe function, so it is wrapped, and a script passingnilcrashed OBS before this. SWIG was not run locally; this is read fromobslua.iandobspython.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 pureastrcmpi(), so it moves too.No exported function moves, so there is no
rust-exports.dfragment, and the 1766 exported symbols are unchanged. The unit is its own file,obs-module-locale.c.h(Rustobs_core::module_locale), rather than an addition toobs-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 inobs-module.c.hfor a later slice: the decision chain ofload_all_callback()and the size checks ofobs_register_*_s(). Overlap: no open PR touchesobs-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, tomodule_config_pathintest_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 newmodule_localecase intest_core_module_load, throughobs_module_load_locale()andtext_lookup_getstr(). The module's data path haslocale/en-US.ini,de-DE.iniandEN-us.ini. Covered:EN-us), both ways;obs_find_module_file()resolves them, with and without a trailing '/' on the 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_defaultand_file.port_comparison.The double '/'. The second name is
/locale/<locale>.ini, andobs_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-DEtext is loaded on top ofen-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_fileandis_default.Optionfor NULL, and NULL is empty, as for the C'sdstr_catandastrcmpi.is_defaultis obs-util'sastrcmpi, so the case rule has one implementation.Shim (
src/ffi/module_locale.rs): the three C signatures. The names arebmalloc'd strings the callerbfrees.libobs/obs-module-locale.c.hmoves tolibobs.ported-module-locale(PCHobs-internal.h), and the three symbols are hidden throughrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt.Kept, characterized, not endorsed:
<data>//locale/<locale>.ini, which resolves./locale/<locale>.ini...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_loadgives 18/19 on the C backendlibobs:module_config_pathfails with "Test failed with exception: Segmentation fault(11)". After 881feda it is 19/19.Characterization: aebf0c3.
test_core_module_loadis 20/20 (19 +module_locale) on the C backendlibobs, before and after the extraction (bd1bf3a).RED commit: bf854c3
libobs: Add Tier 1 tests for the module locale files port.obs_core::module_localehas 9 tests: the C case 1:1, the lookup order, edge cases and four 2048-case proptests. All 9 fail ontodo!(). With thetodo!()core linked into the swapped hybridlibobs,test_core_module_loadaborts (exit 134, "not yet implemented" inmodule_locale.rs).GREEN: 41d4415
libobs: Port the module locale files to obs-core. Tier 1 9/9. Tier 2:test_core_module_load20/20 against hybridlibobsandlibobs-c-reference.libobsthe threeobs_module_locale_*symbols are the Rust shims, and noobs-module-localeobject is linked.libobs-c-referenceand 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 itsastrcmpiis the originalutil/dstr.c, through the dstr oracle. Compared:..,%module%) and in 2048-case proptests;is_defaultover every pair of those locales and in a 2048-case proptest, half of whose pairs are one locale in two cases;obs_module_load_locale()reads. Each side uses its own names, decision andobs_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:
.json"(null)"is_defaultcase-sensitiveis_defaultprefix matchis_defaultneveris_defaultnegatedis_defaultwith Unicode case foldingis_defaultfalse for NULLis_defaultwith padding trimmedThe case-sensitive mutant also fails Tier 2 against hybrid
libobs:test_core_module_load19/20, withmodule_localefailing on"EN-us A" != "en A".c9a6cce13(obs-core: Port util/source-profiler.c #1887). The conflicts were only in the obs-coreCargo.tomldescription, thelib.rsdocs and therust/README.mdrow. 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.OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON), headless, with a private Xvfb (-noreset), a private D-Bus and a fresh HOME, on62ce80a88(the head before the rebase ontoc9a6cce13, obs-core: Port util/source-profiler.c #1887):test_core_module_loadlibobslibobslibobs-c-referencesoldr 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 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_locale, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Each of these runs once per module at startup.astrcmpidoes not need. That is the few nanoseconds ofis_default.cargo testthe oracle'sdstrhelpers are obs-util's, as in libobs: Port module names and files to obs-core #1915.Windows/macOS: the cross lane compiles and links the shims, 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. There,EN-us.inianden-US.iniare one file in the parity tree, and both sides see the same file system.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)