Skip to content

obs-output: swap service info-table and plugin-data accessors to safe Rust (Refs #3840) - #5379

Merged
rdoupe merged 2 commits into
masterfrom
port/3840-service-info-accessors
Nov 21, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/3840-service-info-accessors

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3840

Step 2 of my #3840 claim: swaps the four hidden service accessors that #5367 extracted and characterized (obs_service_set_info, obs_service_set_plugin_data, obs_service_get_info_table, obs_service_get_plugin_data, declared in obs-internal.h without EXPORT) into safe Rust in obs-output.

  • set_info reads the caller's table whole, then writes it over the service's own copy. A later change to the source never reaches the service, and a table copied onto itself stays as it was (the C struct assignment).
  • get_info_table returns the borrowed address of the service's own copy, never the source.
  • The plugin data is stored and returned as it is, NULL included, and is never dereferenced.
  • Nothing else in the service changes and nothing is logged. The service is never NULL, which is the C precondition and is kept.

struct obs_service stays in C behind one private field adapter, obs_service_info_accessors_fields() (libobs/obs-service-info-accessors-fields.c.h, declared in obs-internal.h, no EXPORT), which returns the addresses of info and context.data. The original moves to libobs.ported-service-info-accessors, which only the C reference builds. The four names go in rust-hidden.d, so they stay hidden as before. No intentional behavior differences. No public header, existing C test, obs-websocket code or workflow is changed. Not user-visible, so there is no features-ledger line.

Consumers checked

  • libobs C callers (obs-service-getters.c.h's service_info()/service_data() macros and the reference lifecycle) now resolve to the hidden Rust exports.
  • The Rust service code (rust/obs-output/src/ffi/service.rs) already called these names through extern declarations. They now resolve to the same crate's definitions. Its imports are unchanged; only a doc comment changed.
  • rust/obs-c-oracle/oracle/service_getters.c had its own copies of all four names. They would collide with the Rust exports in obs-tests-core, so they are gone. The service parity fixtures now go through the Rust shims and the real adapter, which oracle/service_info_accessors.c defines once. Its set_info/set_data trace events go with them. The lifecycle parity is unaffected because both sides call the same shim.
  • test/cmocka/service-info-accessors-link-support.c (in the shared Rust-static support manifest) included the original. It now includes the field adapter, so a standalone Rust-static consumer that pulls the shims links the real C adapter.
  • No link cycle, and nothing blocked the swap.

RED (0dd0a09)

Tier 1 (tests/output/service_info_accessors.rs) mirrors every assertion of test_service_info_accessors.c on the safe core:

  • the whole table copied by value, with nothing else changed;
  • source independence;
  • the borrowed, stable address;
  • second and all-NULL overwrites;
  • the plugin-data round trip with NULL and repeated reads, with tokens never read.

Tier 3 (tests/output/service_info_accessors_parity.rs) runs the extracted original and the shims on two services built from the same byte pattern, through the real adapter. It covers the characterized sequence and random set/get sequences (up to 24 operations, self-copy included). After every step it compares:

  • the results, as offsets into each service;
  • both whole services, byte for byte;
  • the source tables, which must never be written.

It also checks the real-header layout (the adapter struct, struct obs_service_info vs ObsServiceInfo, the member addresses) and catches four mutants: a partial table copy, a dropped NULL, a wrong table address, and a NULL data read.

The setters were stubs that wrote nothing:

soldr cargo test -p obs-data --test obs-tests-core -- output::service_info_accessors
test result: FAILED. 2 passed; 4 failed

The 2 passes are the layout/adapter check and the mutant check.

GREEN (42419a6)

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

soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build::canonical_service native_build::rust_static
test result: ok. 5 passed; 0 failed

The full obs-tests-core run under plain cargo test (one process, many threads) shows obs_core::canvas_valid_video_info_parity failing with "8: it allocated". This happens with this PR's modules skipped too. That probe counts process-wide allocations, so other threads trip it. It passes alone (4/4) and under nextest's one-process-per-test, so it is not caused by this change.

Tier 2

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests service:

  • Exported symbols C vs Rust: IDENTICAL (1769).
  • OFF/C reference: 1066/1066 passed, repeat 12/12.
  • ON/hybrid: 1066/1066 passed, repeat 12/12.

To prove the cases ran rather than skipped, I ran the binaries from the kept build volume. On both libobs and libobs-c-reference, test_service_info_accessors and its new twin test_service_info_accessors_rust each ran 2 tests, and both passed. The hybrid libobs.so exports none of the four names or the adapter. The twin defines all five itself: the shims come from the Rust archive and the adapter from the support source.

The unchanged test_service_info_accessors keeps testing the C source. The twin compiles the same fixture with OBS_SERVICE_INFO_ACCESSORS_RUST, so it takes the Rust shims instead. A registration test (canonical_service_info_accessors_swap_is_registered) pins:

  • the graph selection on Linux, macOS and Windows;
  • the hidden list, and that the names are in no export list;
  • the adapter without EXPORT;
  • the ported and hybrid groups and the support member.

Other checks

  • uv run --no-project ci/windows_link_check.py: exit 0. All category binaries linked, and so did the Windows MSVC (win-x64) and Darwin (mac-arm64) hybrid libobs and every *_rust fixture, including test_service_info_accessors_rust. This only links; nothing was executed.

  • ./lint: ok.

  • ./push: client-lint (clippy and Dylint on all six targets) ok, client-test ok. The optional Swift lane is not available here, and the head is unsigned, so the regular PR checks run.

Test cost: the 6 new tests take under 0.01 s together at OBS_PARITY_CASES=reduced in the debug build. Peak memory for the module is 8 MB over 21 runs. They start no threads of their own.

Tier 4 does not apply (no protocol). Not verified locally: native macOS and Windows runs (CI covers those).

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 21, 2026 00:54
…3840)

Tier 1 mirrors every assertion of the unchanged
test_service_info_accessors.c on a safe core: the table is copied whole,
by value, into the service and nothing else changes; a later change to
the source does not reach the service; the table getter borrows the
service's own copy and returns the same address every time; a second set
and an all-NULL table overwrite it in place; the plugin data round-trips
as it is, NULL included, and reading it changes nothing.

Tier 3 runs the extracted original (oracle/service_info_accessors.c) and
the Rust shims on two services built from the same byte pattern, through
the real field adapter: the characterized sequence plus random sequences
of sets (including a table copied onto itself) and gets, comparing each
result as an offset into its service, both services byte for byte and
the source tables, with real-header layout checks and four mutants.

The plumbing for the swap is in place: the private field adapter
obs_service_info_accessors_fields() (obs-internal.h), the hidden list,
the C-reference-only ported group, the refit Rust-static support member,
the oracle's own copies of the four names dropped from service_getters.c,
and the test_service_info_accessors_rust twin with its registration test.

The safe setters are stubs that write nothing:

    soldr cargo test -p obs-data --test obs-tests-core -- output::service_info_accessors
    test result: FAILED. 2 passed; 4 failed

(The 2 passes are the layout/adapter check and the mutant check.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Rust (Refs #3840)

The hidden obs_service_set_info, obs_service_set_plugin_data,
obs_service_get_info_table and obs_service_get_plugin_data are now
safe Rust in obs-output. set_info reads the caller's table whole and
then writes it over the service's own copy, so a later change to the
source never reaches the service and a table copied onto itself stays
as it was; get_info_table hands back the borrowed address of that copy;
the plugin data is stored and returned as it is, NULL included. Nothing
else in the service changes and nothing is logged. The private field
adapter obs_service_info_accessors_fields() keeps struct obs_service in
C, and the original moves to libobs.ported-service-info-accessors for
the C reference.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ci-Attestation: {"at":1795242605,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":94,"stamp":"1444ef8f34b9fbadbad11b20ecc03002","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242605,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":94,"stamp":"7af7d503f9cd1374c179ac361caa697a","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242605,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":94,"stamp":"e812f00bb81fa06aaa4e4fe9df065fbb","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242605,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":94,"stamp":"381d7935a79c166a091450704ccf21ca","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242509,"gate":"general/all/client-lint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"38fb3a4b0d065d19e62a1e026723295e","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242605,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":94,"stamp":"fc22a0cfc1c86ef268bbc922cc07d411","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"d737ae2b249cae7effd07b02c81a5d66","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"e0cb786feb676fbd7821c20eea4b16db","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"6b039949d9a38d245b4c18a6fe9471eb","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"2d33406fe35a74d783311a0f2ae80a99","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242509,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"3d01dadf43fbf9e6579fcd365f474c8b","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"4b01efa9ffeeb9c676d6c5f795f8c807","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"db04188d32d565fec65c0b826ac4f885","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"b2c1c9251e7abfdf6e6cc1c4ae99571b","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"ddd24bddc8dbe0ae4e26870d5c477313","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242510,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"f8ccd3a3293cc9544760e24a537506f5","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242509,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"8b9a41530d2526a338a12795edaecf0f","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242509,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"972616a69fa8eb969354ddbc85bffcd8bb53622b8792d209eb6f96c697bbede9","lane":"client-lint","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":79,"stamp":"73c567186e63376ce49f3fb5c21680b7","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}
Ci-Attestation: {"at":1795242831,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"1da07565b70582fe1946ce26dfb0542da34f362c818ab2930812c2fb2c4a09ca","lane":"client-test-x86_64-unknown-linux-gnu","parents":["0dd0a09cf02db94a07fbb4ece749de848fd3902d"],"secs":226,"stamp":"2c057a7b0dfaeb50e7abfd3426a6253f","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"0419d4a268c3fb3bcdbe3fbe3908b3f4d75e380c","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-output+.h.c","libobs/build/libobs.ported-service-info-accessors+.h.c","libobs/build/ported-source-sets/service-info-accessors.json","libobs/cmake/rust-hidden.d/obs-output-service_info_accessors.txt","libobs/obs-internal.h","libobs/obs-service-info-accessors-fields.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_service_info_accessors_swap_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_service_info_accessors_rust.json","rust/obs-c-oracle/oracle/service_getters.c","rust/obs-c-oracle/oracle/service_info_accessors.c","rust/obs-output/src/ffi/mod.rs","rust/obs-output/src/ffi/service.rs","rust/obs-output/src/ffi/service_info_accessors.rs","rust/obs-output/src/lib.rs","rust/obs-output/src/service_info_accessors.rs","rust/obs-output/tests/output/main.rs","rust/obs-output/tests/output/service_info_accessors.rs","rust/obs-output/tests/output/service_info_accessors_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/service-info-accessors-link-support.c"],"head":"b6836b083a0c0580d8b61f1299df82adc729abcb","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":"2ce93df4c3f0bacfe28ef4668d6453f74d3cacefa040757dbc4730018d4b0017","tree":"d2d75da3e018bba593063f9c8bf479e2dbdd9e64"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 21, 2026 06:34
@rdoupe
rdoupe added this pull request to the merge queue Nov 21, 2026
Merged via the queue into master with commit 8468738 Nov 21, 2026
87 of 89 checks passed
@rdoupe
rdoupe deleted the port/3840-service-info-accessors branch November 21, 2026 07:57
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