Skip to content

obs-core: swap obs_enum_sources and the source/canvas enumerators to Rust (Refs #5495) - #5496

Merged
rdoupe merged 2 commits into
masterfrom
port/enum-sources-swap
Nov 23, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/enum-sources-swap

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Swaps obs_enum_sources, obs_enum_all_sources, obs_enum_canvases and obs_canvas_enum_scenes (with their static helper obs_enum_uuid) from libobs/obs-enum-sources.c.h to obs-core in hybrid libobs. The public C API and ABI stay the same. Existing C tests and public headers are unchanged.

Refs #5495. This follows the C-only extraction (PR #5494, merged), the same way obs_set_audio_monitoring_device followed its extraction (#5490 → #5492).

What moved

The walks are now safe Rust (rust/obs-core/src/enum_sources.rs), and each one makes its reads and calls in the same order as the original:

  • obs_enum_sources: walks the uuid table from its head while holding sources_mutex. It takes a reference on each entry and passes over an entry with no reference left. It skips private sources. It calls back for an input. Unless that call answered false, it then calls back for a source whose id is the group's. This is the original's else if, so an input carrying the group id is called back twice. A false answer releases the reference and stops the walk. Each reference is released before the next link is read.
  • obs_enum_all_sources (the static obs_enum_uuid): visits every entry while holding the mutex, without taking a reference. It reads each next link before that entry's callback (HASH_ITER), so a callback can unlink the current entry.
  • obs_enum_canvases: the same walk over the named canvases. As in the original, the head is read before canvases_mutex is taken.
  • obs_canvas_enum_scenes: walks the canvas's own table in order while holding that canvas's sources_mutex. It references each entry, asks the type of the listed entry, calls back for scenes and releases every reference. A false answer releases and stops.
  • A NULL callback walks nothing. The original asserted it was non-NULL, or called it.

The mutexes, the table heads and links, obs_source_get_ref/obs_source_release, and the private flag, type and id all stay in C behind private adapters in libobs/obs-enum-sources-fields.c.h. That file takes the original's place in the core group and is also a Rust-static support member (test/cmocka/enum-sources-link-support.c). The original moves to libobs.ported-enum-sources, which only the C reference builds. rust-exports.d/obs-core-enum_sources.txt exports the four names. Before the swap, I checked every consumer: obs_enum_scenes's adapter, obs-canvas.c.h, obs-audio-monitoring-device.c.h, scripting, obs-mcp and the cmocka tests. test_ws_scene_count stubs obs_canvas_enum_scenes itself and links neither libobs nor the Rust staticlib. The Rust shims name only the new adapters, and the oracle defines those under their real names, so no *_links.c is needed.

Evidence

  • RED (obs-core: RED Tier 1 mirrors ...): Tier 1 mirrors every test_enum_sources case on a recording host table. It also checks what the C test cannot see: the order of every read and call, the next link read before each callback, the canvases' head read before locking, an input with the group id called back twice, and the scene type asked of each referenced canvas entry. Run against a todo!() core:
    soldr cargo test -p obs-data --test obs-tests-core -- enum_sources::
    test result: FAILED. 0 passed; 13 failed
    
  • GREEN, Tier 1 and Tier 3:
    soldr cargo test -p obs-data --test obs-tests-core -- enum_sources
    test result: ok. 18 passed; 0 failed
    
    Tier 3 (oracle/enum_sources.c) runs the original and the shims on the same recording fixture core, built from real struct obs_source and struct obs_canvas entries:
    • The uuid table is linked in order. Canvas 1's own table is linked in reverse. The main canvas is empty. A pool of canvases is named. With this layout, a walk of the wrong table shows up as a difference.
    • What it compares: the trace of every lock and unlock with its mutex, every get_ref with its answer, every release, and every callback with the entry's count at the call. The trace also marks any step taken outside the walk's lock, a canvases head read under the lock, and a wrong param. After the trace it compares the final entries, links and counts, and checks that every mutex was released.
    • Inputs: the C test's tables, every flag of one entry, early stops, a callback that unlinks the current entry or takes the next entry's last reference, and proptest tables.
    • Mutants: a walk that calls back every referenced source, a next link read after the callback, the canvases' head read under the lock, and a walk of the wrong table.
  • Rust-side mutation checks (each one applied to enum_sources.rs, run, then reverted):
    • (input || group) && !visit, a single call instead of the else if: caught by enum_sources_step_order, enum_sources_input_with_group_id, characterized_edges and any_walk_matches_original_c.
    • Next link read after the callback in iterate: caught by enum_uuid_reads_next_before_each_callback, enum_canvases_reads_head_before_locking, characterized_edges, any_walk_matches_original_c and mutants_are_caught.
    • Canvases mutex taken before the head read: caught by enum_canvases_reads_head_before_locking, characterized_edges, any_walk_matches_original_c and mutants_are_caught.
    • In obs_enum_sources, the release moved after the next read and applied to every listed entry: caught by enum_sources_step_order, enum_sources_skips_source_without_references, characterized_edges and any_walk_matches_original_c.
  • Tier 2, with test_enum_sources and test_enum_scenes unchanged:
    OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'test_enum_sources|test_enum_scenes'
    
    The full suite passed 1087/1087 on libobs-c-reference and 1087/1087 on hybrid libobs, then the two tests passed 2/2 again on each library. Exported symbols are identical between C and Rust (1769). The ported C objects excluded from production libobs went from 588 to 589.
  • ./lint passes.
  • Test cost: the 18 new tests run in 0.023 s at most (debug build, serial, 25 runs). The longest single test is characterized_edges at 0.013 s. Peak RSS is 22 MB. The tests start no threads of their own.

Tier 4 does not apply. docs/features.md is unchanged because there is no user-visible change (as for #5488).

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 23, 2026 02:22
…s enumerators (Refs #5495)

Safe mirrors of every test_enum_sources case (an empty core, public inputs
and groups only with one reference each, the early stops, a source with no
reference left skipped, every source visited by obs_enum_all_sources
without references, transitions skipped, the named canvases with their
stops and a destroyed one gone, and another canvas's scenes referenced for
each call) over a recording host table with a re-entrant mutex, per-entry
counts and a callback that can stop or unlink the current entry. Plus what
the C test cannot see: the order of every read and call (a reference
released before the next link is read; private flag, input type and group
id asked in that order), the uthash next read before each callback of the
unreferenced walks, the canvases' head read before their mutex is taken,
an input with the group id called back twice, and the scene type asked of
every referenced canvas entry. Against a todo!() core:

    soldr cargo test -p obs-data --test obs-tests-core -- enum_sources::
    test result: FAILED. 0 passed; 13 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Rust (Refs #5495)

obs_enum_sources, obs_enum_all_sources, obs_enum_canvases and
obs_canvas_enum_scenes now come from obs-core in hybrid libobs. The safe
core makes the walks in the original's order: obs_enum_sources takes a
reference on each uuid-table entry under sources_mutex (passing over one
with none left), skips a private source, calls back for an input and then,
unless that call answered false, for a source with the group id (the
original's else if), and releases each reference before the next link is
read; obs_enum_all_sources (the static obs_enum_uuid) and
obs_enum_canvases read each next link before the callback (HASH_ITER), the
canvases' head before canvases_mutex is taken; obs_canvas_enum_scenes
references each entry of the canvas's own table under its mutex and calls
back the scenes. A false answer releases and stops. A NULL callback walks
nothing.

The mutexes, table heads and links, obs_source_get_ref/obs_source_release
and the private flag, type and id stay C behind private adapters
(libobs/obs-enum-sources-fields.c.h, core group, also a Rust-static support
member). The original moves to libobs.ported-enum-sources for the C
reference; rust-exports.d/obs-core-enum_sources.txt exports the four names.

Tier 3 (oracle/enum_sources.c) runs the original and the shims on one
recording fixture core of real struct obs_source and struct obs_canvas
entries over the C test's tables, every flag of an entry, early stops, the
callback unlinking the current entry or taking the next one's last
reference and proptest tables, with mutants:

    soldr cargo test -p obs-data --test obs-tests-core -- enum_sources
    test result: ok. 18 passed; 0 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ci-Attestation: {"at":1795419512,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":93,"stamp":"64188d5c8d6f7625002ca816403c573a","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419512,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":93,"stamp":"227c6f4aaa4df16afd9ba7fb169f973a","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419512,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":93,"stamp":"2d513d1c8d60e3b298c5d38b6e9e4cf1","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419512,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":93,"stamp":"0deb0aeba4faae615ed3dbc7ab64026d","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"general/all/client-lint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"2fe57189bc0fbb9e59ab13dd0f1abe34","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419512,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":93,"stamp":"f6ba4f1abfda974331c0eec048f57b13","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"43945ff9c80c36218bd312e386e43d2b","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"0592e27cc8cf779e625d8a880eaf0d8d","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"df2537f049496c860276da1fa9e69860","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"8064e8680d63e2cacb5319f584161ed0","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"a4b0f20bf4eb460f34b94d5a1c5ff9d5","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"69e688838d6a56db4c70c3533b78e1c4","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"ffbdddc4ed366229ce58995bc9fc62b7","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"9423cca3e1d958ba2d40b03462369aa4","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"00cca968ef1f1ec150586338a5d04818","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"8e6fd50bf439d40de2ddfb4ce620c09c","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"1c20f4af1c06f1fdeb0646bc656d5235","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419418,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"4ce3a2d636f0de42f000570d4626309d8c7ab5eb6bb94dea44fb3887ace189bc","lane":"client-lint","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":110,"stamp":"9e3f399e7cbb2da1465cdff5401a4a5b","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}
Ci-Attestation: {"at":1795419752,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"f6eaf11c3c256c19e6a718bc5b942b6af30f2c8a5347f12fb37ff87cb1d668f5","lane":"client-test-x86_64-unknown-linux-gnu","parents":["98311a65435932a28b87d7b3517ca0c498d84704"],"secs":239,"stamp":"358787aaba6773b11189d204a5307a52","tree":"456fa12f2b27622cbcc8a770274621c123c48588","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"81d3adb7f37f05221f5e182c2b106f5122f344b0","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.ported-enum-sources+.h.c","libobs/build/ported-source-sets/enum-sources.json","libobs/cmake/rust-exports.d/obs-core-enum_sources.txt","libobs/obs-enum-sources-fields.c.h","rust/README.md","rust/obs-c-oracle/oracle/enum_sources.c","rust/obs-core/src/enum_sources.rs","rust/obs-core/src/ffi/enum_sources.rs","rust/obs-core/src/ffi/mod.rs","rust/obs-core/src/lib.rs","rust/obs-core/tests/obs_core/enum_sources.rs","rust/obs-core/tests/obs_core/enum_sources_parity.rs","rust/obs-core/tests/obs_core/main.rs","test/cmocka/build/rust-static-support.json","test/cmocka/enum-sources-link-support.c"],"head":"a355ae58b85c5214c5825b24930d1c340f02bf40","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"c75fc2018f97f5537839eb64d6f7d78b68ccefd6927f60dee4a77b7d9ec9bbff","tree":"456fa12f2b27622cbcc8a770274621c123c48588"}}
@rdoupe

rdoupe commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Reran the failed jobs: the macOS Tier 2 job failed during CMake configure while cloning corrosion from GitHub (fatal: could not read Username for 'https://github.com', 3 attempts), before any code from this PR was built. Every other lane passed.

@rdoupe
rdoupe added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit abba1b0 Nov 23, 2026
87 of 89 checks passed
@rdoupe
rdoupe deleted the port/enum-sources-swap branch November 23, 2026 09:27
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.

1 participant