Skip to content

obs-source: swap obs_weak_source_addref and obs_weak_source_release to Rust (Fixes #5665) - #5717

Merged
rdoupe merged 3 commits into
masterfrom
port/5665-source-weak-refs
Nov 25, 2026
Merged

rdoupe merged 3 commits into
masterfrom
port/5665-source-weak-refs

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Fixes #5665.

Ports obs_weak_source_addref and obs_weak_source_release (both exported) to Rust in obs-source. The C was already extracted to libobs/obs-source-weak-refs.c.h.

Commits

  1. 4c82acaa5 test: characterize the pair in a new cmocka test, test/cmocka/test_source_weak_refs.c, run unchanged against hybrid libobs and the C reference: NULL handles are silent no-ops; each addref/release moves only the weak count by one; the release that takes the weak count from 0 to -1 frees the control whatever the strong count is, and no earlier one does; a count already below zero is lowered further and never freed (characterized, not endorsed); on a live private scene the control outlives the source until its last weak reference is released.
  2. e1e910e63 test: RED. Tier 1 mirrors against a todo!() core.
  3. 0f78a4289 obs-source: GREEN. Safe core rust/obs-source/src/weak_refs.rs on a borrowed native-long atomic (release reports true only on the exact 0 → -1 step, as the C's os_atomic_dec_long(...) == -1); C ABI shims in ffi/source_weak_refs.rs reject NULL before reading, borrow the count through the private adapter obs-source-weak-refs-fields.c.h, and bfree the control on the final release. The extracted C moves unchanged to the reference-only group libobs.ported-source-weak-refs. Oracle refits for the new Rust symbols: source_get_weak.c renames its recording copy of the original addref, and hotkey_unregister_links.c drops its never-called obs_weak_source_release stand-in. Tier 3 parity runs the renamed original C and the Rust exports over noise-filled real-header controls: pinned edge sequences (including counts below zero) and generated sequences, comparing both counts, the source bytes and the adapter address after every step.

No public header, existing C test, frontend, plugin or obs-websocket change. Exports are unchanged (1769 symbols, identical between the C and Rust builds).

Evidence

RED (e1e910e63):

soldr cargo test -p obs-data --test obs-tests-core -- source::weak_refs
test source::weak_refs::below_zero_never_frees ... FAILED
test source::weak_refs::counts_only_the_weak_refs ... FAILED
test source::weak_refs::final_release_frees ... FAILED
test source::weak_refs::null_handles ... FAILED
panicked at rust/obs-source/src/weak_refs.rs:8:5 / :15:5
test result: FAILED. 0 passed; 4 failed; 0 ignored; 0 measured; 6740 filtered out

GREEN (head, on 8a1954247):

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

soldr cargo test -p obs-studio-rust --test obs-tests-app -- canonical_source_weak_refs
test result: ok. 1 passed; 0 failed

soldr cargo test -p obs-util --lib -- export_list
test result: ok. 4 passed; 0 failed

./lint
== lane lint: ok

OBS_CMOCKA_LINK=false uv run --no-project ci/windows_link_check.py
exit 0

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests '^(test_source_weak_refs|test_source_get_weak.*|test_hotkey_unregister.*)$'
== libobs exported symbols, C vs Rust: IDENTICAL (1769 symbols)
== [OFF] ctest: 100% tests passed, 0 tests failed out of 1112
== [OFF] repeat: 100% tests passed, 0 tests failed out of 4
== [ON] ctest: 100% tests passed, 0 tests failed out of 1112
== [ON] repeat: 100% tests passed, 0 tests failed out of 4

🤖 Generated with Claude Code

rdoupe and others added 3 commits November 25, 2026 08:40
… (Refs #5665)

New cmocka test_source_weak_refs, run unchanged against hybrid libobs and
the C reference: NULL handles are silent no-ops; each addref and release
moves only the weak count by one; the release that takes the weak count
from 0 to -1 frees the control whatever the strong count is, and no
earlier one does; a count already below zero is lowered further and never
freed (characterized, not endorsed); on a live private scene the control
outlives the source until its last weak reference is released.

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

Mirrors the four cases of test_source_weak_refs that need no live core in
the existing obs-tests-core binary. All four panic on the stub.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o Rust (Fixes #5665)

A safe core in rust/obs-source/src/weak_refs.rs adds or drops one weak
reference on a borrowed native-long atomic; release reports true only on
the exact step from 0 to -1, as the C's os_atomic_dec_long(...) == -1.
The shims in ffi/source_weak_refs.rs reject NULL before reading, borrow
the count through the private adapter obs-source-weak-refs-fields.c.h,
and bfree the control on the final release. The extracted C moves
unchanged to the reference-only group libobs.ported-source-weak-refs;
the rust-static link support now carries the adapter instead of the C.

Oracle refits for the new Rust symbols: source_get_weak.c renames its
recording copy of the original addref (the Rust side is compared on
returns and counts), and hotkey_unregister_links.c drops its never-called
obs_weak_source_release stand-in, which obs-source now provides.

Tier 3 runs the renamed original C and the Rust exports over
noise-filled real-header controls: pinned edge sequences (including
counts below zero) and generated addref/release sequences, comparing
both counts, the source bytes and the adapter address after every step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdoupe
rdoupe marked this pull request as ready for review November 25, 2026 18:45
@rdoupe
rdoupe requested a review from zackees as a code owner November 25, 2026 18:45
@rdoupe
rdoupe added this pull request to the merge queue Nov 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 25, 2026
Merged via the queue into master with commit fa6e0be Nov 25, 2026
47 checks passed
@rdoupe
rdoupe deleted the port/5665-source-weak-refs branch November 25, 2026 21:21
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 26, 2026
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.

rust: Port libobs/obs-source-weak-refs.c.h to obs-source

1 participant