Repository navigation
Description
Port the two context name helpers of libobs/obs.c.h to rust/obs-core (#1773) as a new module, context_names. They decide the name every source, scene, canvas, encoder, output and service gets: a duplicate name on insert or rename becomes "<name> 2", "<name> 3", … (the first free number from 2 up), and a NULL or empty name becomes "__unnamed%04lld" from a global counter. If they are wrong, a scene collection loads with its sources renamed, and hotkeys, filters and obs-websocket clients that find sources by name stop finding them. The video output plan in the same file was ported in #1773.
The unit, about 30 lines:
obs_context_deduplicate_name()(masterobs.c.h2749-2766):NULLwhen the name is free in the given uthash table, elsedstr_printf("%s %d", name, suffix++)from 2 untilHASH_FIND_STRfinds nothing. The suffix is a Cint.dup_name()(2646-2659):NULLfor a private context without a name;"__unnamed%04lld"withobs->data.unnamed_index++for a NULL or empty name; elsebstrdup.
These stay C: the callers obs_context_data_init_wrap(), obs_context_data_insert_name() (2768-2797), obs_context_data_setname() (2876) and obs_context_data_setname_ht() (2887-2915), the uthash tables and their locks, the rename cache, the two warnings, and the counter field itself.
Phase and position
Phase 6 (#444), libobs core through opaque seams. It joins rust/obs-core, which holds the video output plan (#1773); it is the second unit extracted from obs.c.h. It is part of a large file, so it goes in through function extraction (testing-policy.md, "Extracting a function before porting it"), as the video plan did (#1714). Its Rust tests join the crate's existing tests/obs_core/ binary. No new test binary.
Dependencies and existing tests
- The moved code needs no libobs state. The lookup becomes a callback,
bool (*exists)(void *param, const char *name), whichobs.cimplements with the sameHASH_FIND_STRon the same table, so the loop asks the same names in the same order. The counter staysobs->data.unnamed_index;obs.cpasses its address and the helper increments it. Both helpers return a bmalloc'd string, so the port returns it throughobs-util::bmem(or C copies it withbstrdup); no darray or uthash crosses the boundary. - Today: many tests create sources, but none pins the names. PR 1 adds tests (below).
- Input: names come from scene collections (importable), obs-websocket (
CreateInput,SetInputName,CreateScene, which refuse an existing or empty name but take any other bytes), scripts and plugins. They are untrusted bytes: any byte but NUL, not necessarily UTF-8, any length. The port must keep the"%s %d"formatting byte-exact, never use a name as a format, never go throughstr, and never panic.
Plan
- Characterization and extraction PR (behaviour-neutral, two commits):
test_context_names(real libobs, public API only, so it also runs the hybrid libobs; each case starts its own libobs and needs no video). It pins insert and rename dedup, the first free number and gaps, names already ending in a number or" (2)",%sequences, bytes that are not UTF-8, Unicode normalization, a 64 KiB name, 300 copies of one name, the unnamed names and their four-digit minimum, the counter shared by sources, encoders, outputs and canvases, private sources, canvas-bound sources (scenes) made unique within their canvas, canvas names, the warnings and the rename signal.- The move: both helpers go into
libobs/obs-context-names.c.has hidden entry points (declared inobs-internal.hwithoutEXPORT),obs_context_name_dup(name, private, &unnamed_index)andobs_context_name_deduplicate(name, exists, param).dup_name()andobs_context_deduplicate_name()stay as one-line wrappers, so the callers do not change. The file joinslibobs.corewithlibobs.pch.h. test_context_name_helpers, which compiles the moved file (no libobs core) and calls only the entry points with a scriptedexists(): the questions asked and their order, 100000 taken numbers, a 1 MiB name, an empty name that is taken, a NULL name, and the counter at its edges.
- Fix PR, if wanted (spec-following, RED then GREEN): the rename warning names the requested name (below). Possibly also the NULL rename crash, through the unnamed path
dup_name()already has. - Port PR (RED, then GREEN):
obs_core::context_names, a safe core over&CStrwith anexists(&CStr) -> boolclosure, andsrc/ffi/context_names.rsfor the two entry points. The C file moves to a ported group,libobs.ported-context-names, with its.pch.h,source-sets.jsonentry and export fragment (hidden, asobs-video-plan.cis inrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt);ci/test_ported_sources.pygets the object.- The suffix is a C
int. Reaching its end needs 2^31 taken names, which is not reachable, but the Rust core must not panic or wrap there: it saturates and stops (a documented intentional difference). The same for the counter atLLONG_MAX(C overflows a signed integer there). - Tests:
- Tier 1 ports every
test_context_name_helpersexpectation 1:1. - Tier 3 checks parity against the moved C through
obs-c-oracle(oracle/context_names.c): a proptest over names (arbitrary bytes,%, trailing digits," (2)", empty, long) and random taken sets (the name,"<name> <k>"for random k, other names), comparing the result and every nameexists()was asked, in order; and the unnamed name for random counters, private or not. - Tier 2:
test_context_name_helpers_rust, the unchangedtest_context_name_helpers.clinked againstlibobs_rust-static, astest_scene_bounds_place_rustdoes;test_context_namesruns the hybrid libobs unchanged. - Tier 4 does not apply (no protocol change).
- Tier 1 ports every
- Docs: the
rust/README.mdrow, and thedocs/rust-port/naming.mdrow forrust/obs-core(addobs-context-names.c.h).
For the reviewer to decide
- Seam shape. The lookup is a callback and the counter a pointer, so C keeps the tables, the locks and the counter, and the Rust core is pure. The alternative, passing the table, would need uthash across the boundary for no gain.
- What reaches the hybrid build. The entry points are hidden, so a test linking
libobs.socannot call them.test_context_name_helperscalls nothing else, so the port can link the same file against the Rust staticlib.test_context_namesdrives the callers through the public API, so it covers the swap end to end. - Behaviours the characterization pins, not endorses (none is changed by the move):
- The rename warning (
obs_context_data_setname_ht) prints the old name as the "duplicate name", not the requested one (round 3 N4). - Renaming
"A 2"to"A"while"A"is taken leaves it"A 2"(its own name is free during the rename), with the warning and arenamesignal from"A 2"to"A 2". - A rename to an empty name takes the next unnamed name without making it unique, so a source can get the name another source already has (a source loaded as
"__unnamed0001"from a collection, for example). obs-websocket refuses an empty name; scripts and plugins can pass one. obs_source_set_name(source, NULL)on a public source passes NULL toHASH_FIND_STR, which crashes (API or script misuse only; N4).- Names are not made unique for encoders, outputs and services, and
obs_encoder_set_name()does not do it. A scene and an input may share a name (the scene is unique only within its canvas). unnamed_indexis read and incremented without a lock by every thread that creates a context.- A taken empty name would become
" 2"(no table holds"", so libobs never asks).
- The rename warning (
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 22, 2026
Claiming: #1787
dup_nameandobs_context_deduplicate_namemoved intolibobs/obs-context-names.c.hbehind hidden entry points, withtest_context_names(real libobs, 14 cases) andtest_context_name_helpers(pure, 12 cases). No behaviour change.rust/obs-core(modulecontext_names) with oracle parity tests.test: Characterize the context names
libobs: Move the context name helpers into obs-context-names.c
libobs: Move the context name helpers into obs-context-names.c (obs-r…
libobs: Name the requested name in the rename warning, and take a NUL…
libobs: Name the requested name in the rename warning, and take a NUL…
rdoupe commentedon Oct 22, 2026
Port is up in #1813. Intentional differences from C, both for null pointers obs.c never passes (listed in the parity test header and rust/README.md): a null
existscallback returns NULL without a call, and a nullunnamed_indexreturns NULL where an unnamed name is needed. The behaviours pinned as not endorsed in #1788 are kept, and theexists()call sequence matches C one to one.libobs: Port the context names to obs-core (#1813)