Skip to content

obs-source: swap source weak-handle acquisition to safe Rust (Refs #5228) - #5238

Merged
rdoupe merged 2 commits into
masterfrom
port/5228-source-get-weak
Nov 19, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/5228-source-get-weak

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #5228

Swaps obs_source_get_weak_source() (libobs/obs-source-get-weak.c.h) to safe Rust in obs-source.

  • Safe core rust/obs-source/src/get_weak.rs: a NULL source returns NULL without reading or logging; otherwise the source's control is read, passed once to obs_weak_source_addref() (also when NULL, a no-op there, as in the C) and returned.
  • Shim rust/obs-source/src/ffi/source_get_weak.rs reads context.control through the new narrow private adapter libobs/obs-source-get-weak-fields.c.h and calls the C-owned public obs_weak_source_addref(). Release, the atomics and native C long counts stay in C.
  • The extracted C moves unchanged to the reference-only group libobs.ported-source-get-weak (ported-source-sets/source-get-weak.json); the hybrid libobs.core-source group includes the adapter instead. Export fragment obs-source-source_get_weak.txt, registration test canonical_source_get_weak_swap_is_registered, rust/README.md row.
  • No link-support archive was needed: the Windows and Darwin link check (hybrid libobs plus every configured cmocka *_rust fixture) and every Linux *_rust fixture in Tier 2 link as-is.
  • No edits to C tests, public headers, plugins/obs-websocket or workflows. Tier 4 does not apply (no protocol code). No intentional differences.

RED

d4ab503a7 adds Tier 1 mirrors of the four cases of the unchanged test/cmocka/test_source_get_weak.c (source::get_weak, in the existing obs-tests-core binary) against a todo!() core:

soldr cargo test -p obs-data --test obs-tests-core -- source::get_weak::
test result: FAILED. 0 passed; 4 failed  (panicked: not yet implemented: RED: source weak-handle acquisition)

GREEN

soldr cargo test -p obs-data --test obs-tests-core -- source::get_weak
test result: ok. 5 passed; 0 failed   (4 Tier 1 + Tier 3 parity)

Tier 3 (source::get_weak_parity, oracle rust/obs-c-oracle/oracle/source_get_weak.c) runs the original C and the Rust export over present/absent sources and controls, noise-filled real-header layouts, strong/weak counts and 0-15 repeated calls, comparing returns, addref calls and their arguments, counts and source bytes, and pins the outcome so a mutation on both sides still fails. Mutation evidence: each of these core mutants fails the parity test: skipping the addref of an absent control, a double addref, returning NULL, and dropping the addref.

  • ./lint: ok.
  • ./unittest: rust-test lane ok (9180 tests); tier2-linux ok, 1029/1029 on both hybrid libobs and the C reference (test_source_get_weak passes on both), exported symbols C vs Rust IDENTICAL (1769).
  • soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build: 320 passed.
  • uv run --no-project ci/windows_link_check.py: category binaries, Windows and Darwin hybrid libobs, and all cmocka *_rust executables link.

Test cost: new tests longest 0.02 s, peak RSS 8 MB over 5 runs (OBS_PARITY_CASES=reduced), no own threads.

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 19, 2026 06:59
…5228)

Tier 1 mirrors of the four cases of the unchanged test_source_get_weak.c,
in the existing obs-tests-core binary, against a todo!() core.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
)

A safe core in rust/obs-source/src/get_weak.rs returns NULL for a NULL
source without reading anything; otherwise it borrows the source's
control, passes it once to the C-owned obs_weak_source_addref (also
when it is NULL, a no-op there, as in the C) and returns it. The shim
reads context.control through the narrow private adapter
obs-source-get-weak-fields.c.h, so release, the atomics and the native
long counts stay in C. The extracted C moves unchanged to the
reference-only group libobs.ported-source-get-weak.

Tier 3 runs the original C and the Rust export over present and absent
sources and controls, noise-filled real-header layouts, strong and weak
counts and repeated calls, comparing returns, addref calls and
arguments, counts and source bytes, and pins the outcome so a mutation
on both sides still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ci-Attestation: {"at":1795093588,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":94,"stamp":"c611c604f58a409042d79abccee36d75","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093588,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":94,"stamp":"1b4c959837568078e13ef1b8902303a2","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093588,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":94,"stamp":"83bf029c08ec570a55de9280bb865a74","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093588,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":94,"stamp":"6e8513ca1fb582b1cb84bf5bd22e3779","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"general/all/client-lint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"f71038798343dd62c07abf3d675cb277","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093588,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":94,"stamp":"79cf446b41b1ff495404adbdde8cd276","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"7024c374b244655583038f6fe173678d","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"f7764fcb950d6991cfc6913d65242043","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"ad25898522020c184d1126b406c3c5d6","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"5c2341e3fd3fcdd7446febd4d6d7c1df","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"1cde4bacabc254a1b3d4a3523f99e922","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"dfad8beecd894215568dfa1e80d3edeb","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"8b1a83bd637610ceac9826983cee98cd","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"732be7d4db3ef890adab0809ff1c3ffe","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"7fcdfc7f618cda240d4701ae67e21684","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"5c729876393993bdfc8e4b0d23e359d0","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"5ae2afd06b72446eaa41e9bb99e17405","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093493,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"51ec27c4ab08162218f5a7eaa46058d107b5a5ec930188e33b0fc88d5ac7e05f","lane":"client-lint","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":89,"stamp":"b2295e1882891a9b0b050cff127581c1","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}
Ci-Attestation: {"at":1795093743,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"785c16051be4031af13f733929ec9153c6d579b7341d4aee29679e0ddc614c54","lane":"client-test-x86_64-unknown-linux-gnu","parents":["d4ab503a7b6215dcb1d58d10a7ed2787f2bd650e"],"secs":154,"stamp":"e53d0c18f7682b6b2fdb1d7ae5792db3","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"e6942badc9ef36cd7b63a6f4fced41d4aa090e55","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-output+.h.c","libobs/build/libobs.core-source+.h.c","libobs/build/libobs.graphics+.h.c","libobs/build/libobs.ported-graphics-planar-capability-queries+.h.c","libobs/build/libobs.ported-output-total-bytes+.h.c","libobs/build/libobs.ported-source-get-weak+.h.c","libobs/build/ported-source-sets/graphics-planar-capability-queries.json","libobs/build/ported-source-sets/output-total-bytes.json","libobs/build/ported-source-sets/source-get-weak.json","libobs/cmake/rust-exports.d/obs-graphics-planar_capability_queries.txt","libobs/cmake/rust-exports.d/obs-output-output_total_bytes.txt","libobs/cmake/rust-exports.d/obs-source-source_get_weak.txt","libobs/graphics/graphics-device-queries-fields.c.h","libobs/graphics/graphics-planar-capability-queries.c.h","libobs/obs-internal.h","libobs/obs-output-total-bytes-fields.c.h","libobs/obs-output-total-bytes-query-support.c.h","libobs/obs-source-get-weak-fields.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_output_total_bytes_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_source_get_weak_swap_is_registered.rs","rust/obs-c-oracle/legacy/graphics-planar-capability-queries.c","rust/obs-c-oracle/oracle.d/graphics-planar-capability-queries.list","rust/obs-c-oracle/oracle.d/source-get-weak.list","rust/obs-c-oracle/oracle/device_queries.c","rust/obs-c-oracle/oracle/output_total_bytes.c","rust/obs-c-oracle/oracle/source_get_weak.c","rust/obs-graphics/src/ffi/mod.rs","rust/obs-graphics/src/ffi/planar_capability_queries.rs","rust/obs-graphics/src/lib.rs","rust/obs-graphics/src/planar_capability_queries.rs","rust/obs-graphics/tests/render/main.rs","rust/obs-graphics/tests/render/planar_capability_queries.rs","rust/obs-graphics/tests/render/planar_capability_queries_parity.rs","rust/obs-output/src/ffi/mod.rs","rust/obs-output/src/ffi/output_total_bytes.rs","rust/obs-output/src/lib.rs","rust/obs-output/src/output_total_bytes.rs","rust/obs-output/tests/output/main.rs","rust/obs-output/tests/output/output_total_bytes.rs","rust/obs-output/tests/output/output_total_bytes_parity.rs","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_get_weak.rs","rust/obs-source/src/get_weak.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/get_weak.rs","rust/obs-source/tests/source/get_weak_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/output-total-bytes-link-support.c","test/cmocka/tests.d/output_total_bytes_link_support.cmake"],"head":"07d7e0cf000f3a547a24bee4ef8caf006d370700","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":"cea9e05c57acbff45b397aa6d6ce30dc2d8534529e2b486bec83129b675b3024","tree":"9aeb94c3213b41e262f7c975267596ec4a9ed362"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 19, 2026 13:09
@rdoupe
rdoupe added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 046aa39 Nov 19, 2026
44 checks passed
@rdoupe
rdoupe deleted the port/5228-source-get-weak branch November 19, 2026 14:20
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