Repository navigation
libobs: Move the context name helpers into obs-context-names.c - #1788
Merged
Merged
Conversation
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 22, 2026
zackees
enabled auto-merge
October 22, 2026 14:44
Characterization before the context name helpers of obs.c
(obs_context_deduplicate_name and dup_name) move to their own file and
are ported to obs-core. Many tests create sources, but none pins the
names they get.
test_context_names links the real libobs and uses the public API only,
so it also runs the hybrid libobs. Each case starts its own libobs (the
unnamed counter starts at 0) and needs no video; on Linux it runs under
xvfb-run with -noreset. 14 cases pin:
- insert: "A", "A" -> "A 2", "A 3"; the first free number from 2 up
(with "A 2" taken, "A" -> "A 3"; a gap is filled); a free name is
kept; the warning text;
- names are not parsed: "Cam 2" -> "Cam 2 2", "X (2)" -> "X (2) 2",
"Big 2147483647" -> "Big 2147483647 2", " " -> " 2";
- bytes: case, leading and trailing spaces, '%' sequences, bytes that
are not UTF-8 and Unicode normalization all make other names; a
64 KiB name; 300 copies of one name, and a released name is reused;
- unnamed names: NULL and "" -> "__unnamed0000", "__unnamed0001"; an
unnamed name that is taken is made unique on insert; at least four
digits ("__unnamed9999", "__unnamed10000");
- sources, encoders, outputs and canvases share the counter; encoders
refuse a NULL name before taking a number; encoder and output names
are not made unique, and obs_encoder_set_name() does not do it;
- private sources keep a NULL name without a number, and their names
(on create and rename) are not made unique;
- rename: to a free name, to its own name (no signal), to a taken name
(suffix, warning, the old name freed), and to an empty name;
- sources that need a canvas are made unique within the canvas, not
against inputs, and so are scenes; canvas names, "Main" included.
Characterized, not endorsed:
- The rename warning names the old name, not the requested one.
- "A 2" renamed to "A" while "A" is taken stays "A 2", with the warning
and a rename signal from "A 2" to "A 2".
- A rename to an empty name takes the next unnamed name without making
it unique, so two sources can have the same name.
Refs obs-rust#1787
Behavior-neutral extraction before the Rust port: the two context name
helpers of obs.c.h move into libobs/obs-context-names.c.h.
- dup_name() becomes obs_context_name_dup(name, private,
unnamed_index): NULL for a private context without a name,
"__unnamed%04lld" for a NULL or empty name, else a copy. The counter
stays obs->data.unnamed_index; obs.c passes its address, and the
helper increments it as before.
- obs_context_deduplicate_name() becomes
obs_context_name_deduplicate(name, exists, param): NULL when the name
is free, else "%s %d" from 2 up until a free one. The uthash lookup
stays in obs.c as context_name_exists(), which HASH_FIND_STRs the
same table, so the moved loop asks exactly the names it asked before,
in the same order.
dup_name() and obs_context_deduplicate_name() stay in obs.c.h as
one-line wrappers, so their callers (obs_context_data_init_wrap,
obs_context_data_insert_name, obs_context_data_setname and
obs_context_data_setname_ht), the locks, the rename cache and the
warnings are unchanged. Both entry points and the callback type are
declared in obs-internal.h without EXPORT, so they are hidden.
The new file joins libobs.core just before obs-hotkey-press.c.h, with
libobs.pch.h. No group, PCH or source-sets.json change, and the
exported symbols are unchanged (1766).
New test test_context_name_helpers compiles the moved file (ASan and
UBSan, no libobs core) and calls only the entry points, with an
exists() that logs what it is asked, so the port can link the same file
against the Rust staticlib. 12 cases pin: a free name (one question);
the first free number from 2 up, gaps, " 0" and " 1" never tried;
names ending in numbers and " (2)"; '%' sequences, bytes that are not
UTF-8, an empty name that is taken (" 2"); a 1 MiB name; 100000 taken
numbers, asked in order; a NULL name goes to exists() as it is; the
unnamed name and counter (private, empty, the four-digit minimum,
negative values and the ends of long long); and that every returned
name is a bmalloc'd copy. It is in the obs-build C test manifest.
test_context_names passes unchanged.
Refs obs-rust#1787
rdoupe
force-pushed
the
refactor/context-names-move
branch
from
October 22, 2026 15:21
9c2deac to
3b8ae13
Compare
This was referenced Oct 22, 2026
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
* libobs: Add Tier 1 tests for the context names port
RED for the port of libobs/obs-context-names.c.h to rust/obs-core,
module context_names. The safe core is a stub (todo!()): unnamed_name()
("__unnamed%04lld"), suffixed_name() ("%s %d"), name_dup()
(obs_context_name_dup) and deduplicate() (obs_context_name_deduplicate).
Names are bytes, Option for NULL. deduplicate() asks its exists closure
one Lookup at a time: Lookup::Name, the name as given (NULL included),
then each Lookup::Candidate, as the C asks exists().
tests/obs_core/context_names.rs ports test_context_name_helpers 1:1: its
12 cases under the same names, in the same order, with the same inputs
and expected values and the same scripted exists() with a log of every
question; dedup_many takes 200 numbers where the C takes 100000. The
"characterized, not endorsed" cases of #1788 stay pinned.
Edge cases: the four-digit width of the counter with the sign, both ends
of long long and the counter wrapping at LLONG_MAX, the candidate format
with any int suffix, a NULL name that exists() calls taken ("(null) 2",
as "%s" prints NULL), the kind of each question, and two proptests: the
dedup against the written-out rule over any bytes and taken sets, with
the full question log, and the dup over any name, private flag and
counter.
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::context_names
fails 19 of 19 with "not yet implemented".
Refs #1787
* libobs: Port the context names to obs-core
Ports libobs/obs-context-names.c.h to the context_names module of
rust/obs-core. Every source, scene, canvas, encoder, output and service
gets its name through obs_context_name_dup(), and the name tables of
obs.c make a taken name unique through obs_context_name_deduplicate().
dup_name(), obs_context_deduplicate_name() and context_name_exists() in
obs.c.h (still C) call them and keep the name tables, the locks, the
rename cache, the warnings and obs->data.unnamed_index. The hybrid
libobs drops the C file and links the Rust shims.
Safe core (src/context_names.rs), on bytes, Option for NULL:
unnamed_name() ("__unnamed%04lld": zero-padded to four characters, the
sign included), suffixed_name() ("%s %d"), name_dup() and deduplicate().
deduplicate() asks its exists closure Lookup::Name, the name as given,
then each Lookup::Candidate from 2 up, once each, until one is free: the
C's loop, question for question. Names are never parsed and never go
through a formatter, so '%' sequences and bytes that are not UTF-8 are
kept. A NULL name that exists() calls taken gets "(null) 2", as the C's
"%s" prints NULL. The counter wraps at LLONG_MAX, as the C oracle does
(signed overflow in C; libobs counts from 0). The names come from scene
collections, obs-websocket and scripts, so the module denies clippy's
indexing_slicing, arithmetic_side_effects, unwrap_used, expect_used,
panic, todo, unimplemented and unreachable.
Kept as the C has it, characterized and not endorsed (#1788): "A 2"
renamed to "A" while "A" is taken stays "A 2", a taken "" would become
" 2", and the counter is printed signed. obs.c.h keeps the rest: a
rename to "" takes the next unnamed name without the dedup, and the
counter is incremented without a lock.
Shim (src/ffi/context_names.rs): the two functions with the C
signatures. The counter crosses as the caller's long long *, read and
counted up only for an unnamed name. exists() is the caller's C
callback (context_name_exists(), HASH_FIND_STR), called as the C calls
it: first with the caller's own name pointer (NULL included), then with
each candidate as a NUL-terminated buffer valid for that call. The
names are bmalloc'd, as the C's bstrdup and dstr_printf strings, and
the caller bfrees them. Intentional differences, for pointers obs.c
never passes: a null exists returns NULL without a call, and a null
unnamed_index returns NULL where an unnamed name is needed (C calls
through and dereferences them).
C side: the file leaves libobs.core for its own group,
libobs.ported-context-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_context_names (15 of 15, under a private Xvfb) and
test_context_name_helpers (12 of 12) pass 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::context_names 19 of 19.
Refs #1787
* obs-c-oracle: Compare the context names port with the original C
The oracle, oracle/context_names.c, is libobs/obs-context-names.c.h,
unmodified, with its two functions renamed to oracle_* and dstr_printf
to the C-only oracle_dstr_printf. bmalloc, brealloc, bfree and bmemdup
keep their real names (obs-util's under cargo test), so the oracle's
names are bfree'd like the shims'.
Tier 3 (tests/obs_core/context_names_parity.rs), in obs-tests-core,
calls both through the C signatures with the same scripted exists(): a
set of taken names, or "taken for the first n questions", and whether
NULL is taken, with a log of every call. Compared: the result (NULL or
the bytes), the full exists() log (count, order, each name byte for
byte, NULL included), that the first call, and only the first, gets the
caller's own name pointer, and the counter after the dup.
- exhaustively, 36 names and NULL (empty, spaces, ASCII, '%' sequences,
bytes that are not UTF-8, decomposed and precomposed e-acute, names
ending in digits or " N", "(null)", unnamed names, a 64 KiB name), each
against 29 taken sets (the name, runs of candidates, gaps, " 0" and
" 1", candidates without the name, nested suffixes, "the first n taken"
for n up to 12), with NULL taken or not;
- the dup over those names and NULL, private on and off, at 122 counter
values: near 0 and near every power of ten with either sign (the
widths of %04lld), the int32 and uint32 ends, and both ends of long
long, LLONG_MAX included (it wraps in both);
- the counter through a run of 24 calls from four starting values;
- proptests (4096 cases each) over random names and taken sets, and over
any name, private flag and counter.
Excluded, the intentional differences, tested on the shims alone: a null
exists returns NULL without a call, and a null unnamed_index returns
NULL where an unnamed name is needed (C calls through and dereferences
them). 8 of 8 pass.
Deliberate breaks of the port, not committed, each caught by Tier 3
(and Tier 1, failures out of 19, except the last):
| Mutant | Tier 1 | Tier 3 |
| suffix from 3 | 9 | 3 of 8 |
| "%s%d" (no space) | 10 | 3 |
| an empty name copied, not unnamed | 2 | 4 |
| pre-increment of the counter | 4 | 3 |
| a private NULL name unnamed | 2 | 3 |
| one try only | 7 | 3 |
| %03lld | 3 | 3 |
| the counter not counted up | 4 | 4 |
| the name asked twice | 9 | 3 |
| one question past the free one | 7 | 3 |
| NULL printed as "" | 2 | 2 |
| the first question with a copy of name | 0 | 2 |
test_context_name_helpers stays the C characterization. A _rust
variant against libobs_rust-static does not link on its own: the
shims' archive member holds the rest of obs-core, which pulls in
obs-media-io and obs-util (libuuid, GIO, and libobs's hidden
base_default_log_handler). Its comments say so.
Refs #1787
* docs: Add the obs-core rows for the context names port
naming.md: obs-context-names.c.h joins the units of libobs/obs.c.h that
go in rust/obs-core. rust/README.md: the obs-core layout row names it,
and the obs-context-names.c.h row of the ported table: the swap, what
stays in obs.c.h, how exists() is called, the behaviour kept from #1788,
and the two intentional differences (a null exists and a null
unnamed_index, which obs.c never passes). obs-core's tests are already
in the core category binary, obs-tests-core.
Fixes #1787
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 22, 2026
…ields (obs-rust#1825) * test: Call the scene audio action core from the steps test Two cases for the core that the next commit splits out of apply_scene_item_audio_actions() and apply_scene_item_volume(), so the Rust port can take the item's fields without mirroring struct obs_scene_item: - obs_scene_audio_actions_apply() on a queue and a visibility of its own, with no item, no lock and no source: the same buffer, visibility and remaining queue as the item path, and the hide count returned, with no reference dropped and no child removed; a tick with nothing due; ts 0 with no buffer; an empty queue. - obs_scene_audio_action_due(): the volume window at 6 rates, and ts 0. The 15 existing cases are unchanged. This does not build yet: the core and obs-scene-audio-actions.h do not exist. Refs obs-rust#1814 * libobs: Apply scene item audio actions through a core on the item's fields The seam before the Rust port of the scene item visibility audio ramp: the core it ports takes the item's fields from the caller, as obs_context_name_dup() takes &obs->data.unnamed_index (obs-rust#1788), so Rust never mirrors struct obs_scene_item and reaches no source. libobs/obs-scene-audio-actions.c.h is now that core, declared in the new libobs/obs-scene-audio-actions.h: - obs_scene_audio_actions_apply(actions, visible, ts, sample_rate, buf) is the loop of apply_scene_item_audio_actions(): it consumes the due actions from the queue (da_erase in place), sets *visible, fills buf, and returns the hide count. It takes no lock and calls nothing in libobs. - obs_scene_audio_action_due(timestamp, ts, sample_rate) is the window of apply_scene_item_volume(). struct item_action moves into that header, and the queue's darray gets a named typedef, obs_scene_item_action_array_t (same layout), so the core can take a pointer to it; Rust can take it as obs_util::ffi::darray. The three item functions move to libobs/obs-scene-item-audio-actions.c.h, in the same unity group, under the same hidden names and signatures. apply_scene_item_audio_actions() takes actions_mutex, calls the core with &item->audio_actions and &item->visible, releases it, and drops one active reference per hide it returns, removing the active child at 0, as before. apply_scene_item_volume() peeks the first action under the lock as before and asks the core whether it is due. process_all_audio_actions() is unchanged. The one ordering change: the visibility the buffer starts from is read under actions_mutex, where it was read just before it. set_visibility() writes it under that lock, so this only closes a race window. test_scene_audio_action_steps now builds both files; its 15 cases are unchanged and the two core cases pass. It is in the obs-build manifest with both sources. The header joins libobs.pch.h and source-sets.json. No exported symbol changes. Refs obs-rust#1814
6 of 7 tasks
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 23, 2026
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
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 23, 2026
* test: Characterize the module search paths 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 * libobs: Move the module search paths into obs-module-paths.c 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 * libobs: Add Tier 1 tests for the module search paths port 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 * libobs: Port the module search paths to obs-core 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 * obs-c-oracle: Compare the module search paths port with the original C 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 * docs: Add the obs-core rows and port_comparison for the module search 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
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 #1787 (PR 1 of the plan: the characterization and the extraction. The port follows.)
What and why
This is a behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file. The two context name helpers move from
libobs/obs.c.hintolibobs/obs-context-names.c.h: the name that makes a duplicate unique ("<name> 2","<name> 3", …) and the"__unnamed%04lld"name for a NULL or empty one. Every source, scene, canvas, encoder, output and service gets its name through them, and the names come from scene collections, obs-websocket and scripts. The move comes with characterization tests, because nothing pinned these names. There is no Rust, no behaviour change and no public header change.dup_name()becomesobs_context_name_dup(name, private, &unnamed_index), verbatim except that the counter is a parameter:NULLfor a private context without a name,"__unnamed%04lld"with(*unnamed_index)++for a NULL or empty name, elsebstrdup.obs_context_deduplicate_name()becomesobs_context_name_deduplicate(name, exists, param):NULLwhen the name is free, else"%s %d"from 2 up until a free one. The twoHASH_FIND_STRcalls become calls ofexists().dup_name()andobs_context_deduplicate_name()stay inobs.c.has one-line wrappers, withcontext_name_exists(), which does the sameHASH_FIND_STRon the same table. So the loop asks exactly the names it asked before, in the same order, and the callers (obs_context_data_init_wrap(),obs_context_data_insert_name(),obs_context_data_setname(),obs_context_data_setname_ht()), the locks, the rename cache, the warnings andobs->data.unnamed_indexare unchanged.obs_context_name_exists_tare declared inobs-internal.hwithoutEXPORT, so-fvisibility=hiddenkeeps them local (tsymbols inlibobs.so). No uthash or darray crosses the new boundary, so the port needs neither; the results are bmalloc'd strings, as before.libobs.coregroup just beforeobs-hotkey-press.c.h, in alphabetical order, withlibobs.pch.h. The group, the PCH,source-sets.jsonand the CMake source lists are unchanged. The moved code has no platform conditional.test_context_names(its own commit before the move, on the unchanged C) links the real libobs and uses the public API only (obs_source_get_name()and friends), so it also runs the hybrid libobs. Each case starts its own libobs, so the unnamed counter starts at 0; it needs no video. On Linux it runs underxvfb-runwith-noreset(a reset after the last client left refused the next case's display, as fortest_audio_capture_mix_race); it skips without a display. 14 cases:"A","A","A"→"A 2","A 3", with the warning text; with"A 2"taken,"A"→"A 3"; a gap is filled ("B","B 3"→"B 2");"C 2"without"C"leaves"C"free;"Cam 2"→"Cam 2 2"(then"Cam 2 3"),"X (2)"→"X (2) 2","Y2","Z 0","N -1","9","Big 2147483647"," "→" 2","T ";"%s %d %n", bytes that are not UTF-8 ("\xff\xfe\x80"), precomposed and decomposed é, tab and newline; a 64 KiB name; 300 copies of one name (each found by name), and a released name is used again;""→"__unnamed0000","__unnamed0001"; a source loaded as"__unnamed0002"makes the next unnamed one"__unnamed0002 2"; at least four digits ("__unnamed9999", then"__unnamed10000");obs_encoder_set_name()ignores NULL, empty and the same name;""gets one, and names are not made unique on create or rename;obs_source_set_name()): to a free name (the old one is freed), to its own name (nothing happens, no signal), to a taken name (the suffix, the warning, therenamesignal's names), to an empty name;OBS_SOURCE_REQUIRES_CANVAS, as scenes) are made unique within the canvas, not against inputs, and so isobs_scene_create(); canvas names ("Main"→"Main 2"), private canvases, andobs_canvas_set_name().test_context_name_helpers(new, with the move) compiles the moved file (ASan and UBSan, no libobs core, no name tables) and calls only the entry points, with anexists()that logs every name it is asked. That is so the port can link the same file against the Rust staticlib (astest_scene_bounds_place_rustdoes). It is also in the obs-build C test manifest. 12 cases:NULLafter one question; case and spaces count;"A","A 2", …), the first free number from 2 up, gaps," 0"and" 1"never tried, only the name itself decides whether a suffix is needed;" (2)",%sequences, bytes that are not UTF-8, tab and newline;"M 100001");exists()as it is;"", private, the four-digit minimum, the counter in sequence, negative values and the ends oflong long;bnum_allocs()).Characterized, not endorsed (a comment in the tests, and in the issue). None is changed here:
Attempted to rename context to duplicate name "C"! New name has been changed to "A 2"for a rename of"C"to"A")."A 2"to"A"while"A"is taken leaves it"A 2", with the warning and arenamesignal from"A 2"to"A 2"." 2"(no table holds"", so libobs never asks).LLONG_MAXare not reached).obs_source_set_name()with NULL on a public source passes NULL toHASH_FIND_STRand crashes (API or script misuse), and the counter is incremented without a lock.RED → GREEN
81112ac23test: Characterize the context names, andtest_context_namespasses 14/14 there on the unchanged C. The move is3b8ae1348libobs: Move the context name helpers into obs-context-names.c.test_context_names14/14 andtest_context_name_helpers12/12 against libobs with the C backend, the hybrid libobs and libobs-c-reference, 4 runs each (once before and 3 times after the final rebase).test_context_namesalso passed 20 runs in a row on the C backend.dup_name()andobs_context_deduplicate_name()verbatim (over a uthash table) against the new entry points (with theHASH_FIND_STRcallback), over 300,000 random cases: names from random bytes and atoms (" 2"," (2)",%s,%n,\xff,é,__unnamed, digits, empty), taken sets with the name,"<name> <k>"and random names, and the unnamed name for random counters (also negative), private or not. It compared the names and the counter: 0 differences, 0 leaked allocations.obs-context-names.c.hfail both tests, each built into libobs (C backend) and the helper test:test_context_name_helperstest_context_names"%s%d"(no space)%03lldOBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds. Fullctest -j4, headless (private Xvfb, private D-Bus, fresh HOME):OBS_LIBOBS_BACKEND=CHYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONNothing was skipped or failed to run. The full suite ran on the pre-rebase head; the final rebase onto 7e11087 (#1761) brought in one commit that touches no libobs file (frontend updater, CI and docs). After it, libobs, libobs-c-reference and both tests were rebuilt, the two tests run 3 more times against each library, the symbol comparison repeated, and
ci/test_build_groups.pyandci/test_ported_sources.pypass.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.py,ci/test_ported_sources.py,ci/test_cmocka_includes.pyandci/test_naming.pypass;ci/platform_ifdef_ratchet.pyreports only the CrashHandler baseline that master reports too. clang-format 22.1.3 and gersemi are clean on the changed files.Windows/macOS: not built there. The moved code has no host conditional.
test_context_name_helpersis portable C (no cmocka range assertions, nofail_msg()) and builds everywhere.test_context_namesis registered on every platform liketest_encoder_group_null(no fork, no X11 calls of its own); it has run on Linux only.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 change)