Skip to content

libobs: Release slot A in obs_transition_load - #2584

Merged
rdoupe merged 2 commits into
masterfrom
fix/bug-obs-transition-load-drops-th-199
Oct 27, 2026
Merged

rdoupe merged 2 commits into
masterfrom
fix/bug-obs-transition-load-drops-th-199

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2582

What and why

obs_transition_load() wrote the loaded source into the transition's slot A without taking back what was already there. obs_load_sources() creates every source first, then loads each transition and calls its callback for each source in order, so a source set into a transition before that transition's load (by the callback for an earlier source, or by a plugin) was dropped: the transition's reference on it was lost, so it was never destroyed, and while the transition was shown it stayed an active child, still active and showing after the transition moved on. Loading the source already in the slot counted it as an active child twice.

The load now takes the old slot-A source and its active flag under the transition lock and, after unlocking, removes it from the active children if the slot was active and releases it, as obs_transition_clear() does. Every other step of the load (the lookup, the recursion refusal, the stored fields, the size and matrix updates) is unchanged and in its original order.

No upstream issue; upstream obs-studio has the same code.

RED → GREEN

  • RED commit: 0dd09e6 (test: Check obs_transition_load drops slot A). The new test_transition_load_release (graphics suite, Linux, under xvfb) fails 3 of 4 cases on master's libobs: load_releases_shown_source (the old source is never deactivated or hidden, activate=1 deactivate=0 show=1 hide=0, and "is still referenced after its last owner let go"), load_releases_hidden_source (still referenced) and load_of_same_source_counts_once (activate_refs=2 show_refs=2, expected 1/1). The control load_onto_empty_slot passes.
  • GREEN: libobs: Release slot A in obs_transition_load. test_transition_load_release 4/4 (5 repeated runs). Graphics suite 36/36 against the C build, 36/36 against hybrid libobs and 36/36 against libobs-c-reference (Linux, xvfb, 0 skipped); every test_transition_* test 16/16 against the C reference; full ctest against hybrid libobs 588/588 (3 skipped: two v4l2 vivid tests and the PulseAudio default-follow test, which need host devices). Exported symbol sets identical on the C, hybrid and C-reference builds. ./lint, the Rust tests, --test-diff origin/master, the cross lane and Windows clippy on --all-targets pass. Runs were on a2adfc8; the full hybrid ctest ran on the same fix before a rebase that brought in no transition change. The local gate's Tier 2 lane could not run on this machine (no Docker access), so the head is not stamped and PR CI runs the full suite.
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

Load a transition with obs_load_sources() while its slot A already
holds a source, set there by the callback for an earlier source, and
check that the load takes the old source back: it leaves the
transition's active children (deactivated and hidden while the
transition is shown) and is destroyed once the test lets go of it.
obs_transition_load() writes the loaded source over the old one, so
the old source stays active and is never destroyed, and a load of
the source already in the slot counts it as an active child twice.
Controls: a load onto an empty slot.

Refs #2582.
obs_transition_load() wrote the loaded source into slot A without
taking back the source already there. obs_load_sources() loads each
transition after every source is created and after the callback ran
for the sources before it, so a source set into the transition before
its load lost the transition's reference (it was never destroyed) and,
while the transition was shown, stayed an active child of it. Take the
old source and its active flag under the lock and, after unlocking,
remove it from the active children if the slot was active and release
it, as obs_transition_clear() does.

Fixes #2582.
@rdoupe
rdoupe force-pushed the fix/bug-obs-transition-load-drops-th-199 branch from 6162d7f to a2adfc8 Compare October 27, 2026 09:26
@rdoupe
rdoupe marked this pull request as ready for review October 27, 2026 09:36
@rdoupe
rdoupe requested a review from zackees as a code owner October 27, 2026 09:36
@rdoupe
rdoupe added this pull request to the merge queue Oct 27, 2026

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: the fix and the claim both hold up.

Correctness

  • libobs: Release slot A in obs_transition_load mirrors obs_transition_clear() step for step: read slot A and its active flag under lock_transition(), overwrite, unlock_transition(), then obs_source_remove_active_child() if the slot was active and obs_source_release(). No lock is held across the release, so the source cannot be destroyed while the transition lock is taken.
  • Refcount arithmetic checks out for the hard case, a load of the source already in the slot: obs_get_source_by_name() (+1) and obs_source_add_active_child() (+1 active) then remove_active_child(old) (-1 active) and obs_source_release(old) (-1, the slot's old reference). Slot holds one reference and one active-child count afterwards — which is exactly what load_of_same_source_counts_once asserts (1/1).
  • The old == NULL and old_active == false paths are benign: obs_source_release(NULL) returns early (libobs/obs-source.c.h:881), and an inactive slot gets no remove_active_child() call, so the count is not decremented for a child that was never added.
  • The recursion refusal path (add_active_child fails, source = NULL) now also takes back the old slot instead of leaking it, which is the same outcome obs_transition_clear() would give. That is a behaviour change but the intended one.
  • Slot 1 is not touched, correctly: obs_transition_load() only ever writes slot 0, and it runs at scene-collection load, not mid-transition.

Test

  • test/cmocka/test_transition_load_release.c is a real fixture-level characterization test, not a smoke test: it drives the actual path (obs_load_sources() → load callback → obs_transition_load()), reads the raw activate/show counters on a leaf source, checks that the old source is destroyed once the test drops its own reference, and keeps the two controls the claim needs (load_onto_empty_slot, load_of_same_source_counts_once). Both the shown and the hidden case are covered, which is what separates "leaked a reference" from "left an active child".
  • Registered in both test/cmocka/build/test-graph.json (entry, graphics suite, OS_LINUX + HAVE_OBS_OPENGL) and test/cmocka/tests.d/test_transition_load_release.cmake, with the reason for the Linux-only requirement stated in the header comment.
  • RED commit 0dd09e647 precedes the fix and the description gives the exact failure text for each of the 3 failing cases (activate=1 deactivate=0 show=1 hide=0), so the RED is credible and not retro-fitted.

Ledger: docs/features.md gets the line in the right section, names the issue, no user-visible UI/protocol claim beyond what the fix does. Good.

Notes, nothing blocking: the test asserts through obs-internal.h counters rather than the public API, which is right for this invariant, but it does mean the test will need a touch if those fields are ever renamed. And as the description says, the local Tier 2 lane could not run without Docker, so PR CI is the gate — which is what the queue runs anyway.

No changes requested.

Merged via the queue into master with commit f3d3edc Oct 27, 2026
36 checks passed
@rdoupe
rdoupe deleted the fix/bug-obs-transition-load-drops-th-199 branch October 27, 2026 10:07
rdoupe added a commit that referenced this pull request Oct 27, 2026
Behaviour-neutral extraction before the Rust port. The decisions of
transition_valid(), valid_scale_type(), obs_transition_load(),
copy_source_state(), obs_transition_swap_begin() and
obs_transition_swap_end() in obs-source-transition.c.h move to
libobs/obs-source-transition-load.c.h, as six functions on plain values
declared in the new libobs/obs-source-transition-load.h without EXPORT
(hidden, as -fvisibility=hidden keeps them):

- _is_transition(): the type check of transition_valid(), after
  obs_ptr_valid();
- _scale_type(): valid_scale_type(), used by
  obs_transition_set_scale_type() and obs_transition_load(): 0, 1 and 2
  as they are, any other int64_t Max Only;
- _looks_up(): obs_transition_load() looks its saved source up only
  with a name;
- _source() -> KEEP | NOT_FOUND | REFUSE: what the load does with the
  looked-up source after the add (the add only for a found source);
- _swaps(): the swap of a transition with itself does nothing, in both
  swap_begin() and swap_end();
- _copy_stores(): copy_source_state() stores the new child unless it
  was to be added as an active child and the add failed.

obs_transition_load()'s release of the old source A (#2584) asks
obs_source_transition_start_child_active(), the rule
copy_source_state() and obs_transition_set() already ask.

Split per step, as #2153 did, so every call and read stays where it was
and under its condition: obs_ptr_valid(), the locks and their order,
the pointer comparisons, the obs_data reads at the top, the lookup, the
add only for a found source or an active new child (the C's own &&),
every obs_source_get_ref() and obs_source_release(), the active child
calls, the (uint32_t) truncations of the loaded alignment and size, the
mode taken as is, the fields the swap hands over, the texrender swap,
recalculate_transition_size() and _matrices(), and the logs. The
getters' answers for an invalid transition (Max Only, 0, 0x0 and
false) stay C as the literals they are. The source type and the scale
type cross as int; the header copies OBS_SOURCE_TYPE_TRANSITION and the
three scale types, and obs-source-transition.c.h checks them and that
enum obs_source_type is int-sized with _Static_assert (the scale type
enum is already checked there).

Checked in a scratch harness (not committed). It compiles
origin/master's transition_valid(), valid_scale_type(),
obs_transition_set_scale_type(), obs_transition_get_scale_type(),
obs_transition_get_alignment(), obs_transition_get_size(),
obs_transition_fixed(), obs_transition_load(), copy_source_state(),
obs_transition_swap_begin() and obs_transition_swap_end() verbatim next
to this branch's and the moved file, as C++, over stand-in sources whose
fields log every read and write with its value. Every call is logged in
order with its arguments: both mutexes of both transitions (lock and
unlock), obs_ptr_valid(), the obs_data reads, obs_get_source_by_name()
(which may find nothing), obs_source_add_active_child() (which may
fail), obs_source_remove_active_child(), obs_source_get_ref() (which
may return NULL), obs_source_release(), obs_source_get_name(), blog(),
obs_transition_clear() and the size and matrix recalculation. Another
thread may write a source, a slot flag, the scale type, the fixed flag,
the width or the video flag at any lock, unlock or call. Inputs: two
transitions and four children of any source type (including values out
of the enum), every slot empty or any child and active or not, no
source, the transition swapped with itself or the other, names that are
missing, unknown, a child or a transition, and loaded and set values at
0, 1, 2, 3, -1, 7, 255, 2^31, around 2^32, the ends of int64_t and
random; one to four operations each.

5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each
at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0,
Clang -O2) and 200,000 with gcov. All 149,390,395 logged events match,
as does the final state (every field, reference and active reference).
Every branch of origin/master's functions is taken both ways.

24 deliberately broken moves were planted, and all 24 fail it: each
function's rule inverted, widened or made constant (the type at >= 2,
STRETCH dropped, the default ASPECT, the value's low bit, the lookup
always or never, NOT_FOUND and REFUSE swapped or made KEEP, the swap
always or for the same transition, the store rule as add_ok, !adds &&
add_ok, adds || add_ok and !adds), and at the call sites the add for a
source not found, the add for an inactive or missing new child, the old
source A removed when inactive, the type check on a constant, the scale
type taken mod 3 and the lookup without a name.

git blame on the moved lines shows the upstream commits 6839ff7 and
a1fbf10, and the fork's #2080 (the scale type rule), #2513 (the swap
refusal) and #2584 (the release of the old source A); they move as they
are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol set is unchanged (1766 on the C backend); the six functions are
local.

Refs #2595.
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
* libobs: Move the transition load decisions

Behaviour-neutral extraction before the Rust port. The decisions of
transition_valid(), valid_scale_type(), obs_transition_load(),
copy_source_state(), obs_transition_swap_begin() and
obs_transition_swap_end() in obs-source-transition.c.h move to
libobs/obs-source-transition-load.c.h, as six functions on plain values
declared in the new libobs/obs-source-transition-load.h without EXPORT
(hidden, as -fvisibility=hidden keeps them):

- _is_transition(): the type check of transition_valid(), after
  obs_ptr_valid();
- _scale_type(): valid_scale_type(), used by
  obs_transition_set_scale_type() and obs_transition_load(): 0, 1 and 2
  as they are, any other int64_t Max Only;
- _looks_up(): obs_transition_load() looks its saved source up only
  with a name;
- _source() -> KEEP | NOT_FOUND | REFUSE: what the load does with the
  looked-up source after the add (the add only for a found source);
- _swaps(): the swap of a transition with itself does nothing, in both
  swap_begin() and swap_end();
- _copy_stores(): copy_source_state() stores the new child unless it
  was to be added as an active child and the add failed.

obs_transition_load()'s release of the old source A (obs-rust#2584) asks
obs_source_transition_start_child_active(), the rule
copy_source_state() and obs_transition_set() already ask.

Split per step, as obs-rust#2153 did, so every call and read stays where it was
and under its condition: obs_ptr_valid(), the locks and their order,
the pointer comparisons, the obs_data reads at the top, the lookup, the
add only for a found source or an active new child (the C's own &&),
every obs_source_get_ref() and obs_source_release(), the active child
calls, the (uint32_t) truncations of the loaded alignment and size, the
mode taken as is, the fields the swap hands over, the texrender swap,
recalculate_transition_size() and _matrices(), and the logs. The
getters' answers for an invalid transition (Max Only, 0, 0x0 and
false) stay C as the literals they are. The source type and the scale
type cross as int; the header copies OBS_SOURCE_TYPE_TRANSITION and the
three scale types, and obs-source-transition.c.h checks them and that
enum obs_source_type is int-sized with _Static_assert (the scale type
enum is already checked there).

Checked in a scratch harness (not committed). It compiles
origin/master's transition_valid(), valid_scale_type(),
obs_transition_set_scale_type(), obs_transition_get_scale_type(),
obs_transition_get_alignment(), obs_transition_get_size(),
obs_transition_fixed(), obs_transition_load(), copy_source_state(),
obs_transition_swap_begin() and obs_transition_swap_end() verbatim next
to this branch's and the moved file, as C++, over stand-in sources whose
fields log every read and write with its value. Every call is logged in
order with its arguments: both mutexes of both transitions (lock and
unlock), obs_ptr_valid(), the obs_data reads, obs_get_source_by_name()
(which may find nothing), obs_source_add_active_child() (which may
fail), obs_source_remove_active_child(), obs_source_get_ref() (which
may return NULL), obs_source_release(), obs_source_get_name(), blog(),
obs_transition_clear() and the size and matrix recalculation. Another
thread may write a source, a slot flag, the scale type, the fixed flag,
the width or the video flag at any lock, unlock or call. Inputs: two
transitions and four children of any source type (including values out
of the enum), every slot empty or any child and active or not, no
source, the transition swapped with itself or the other, names that are
missing, unknown, a child or a transition, and loaded and set values at
0, 1, 2, 3, -1, 7, 255, 2^31, around 2^32, the ends of int64_t and
random; one to four operations each.

5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each
at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0,
Clang -O2) and 200,000 with gcov. All 149,390,395 logged events match,
as does the final state (every field, reference and active reference).
Every branch of origin/master's functions is taken both ways.

24 deliberately broken moves were planted, and all 24 fail it: each
function's rule inverted, widened or made constant (the type at >= 2,
STRETCH dropped, the default ASPECT, the value's low bit, the lookup
always or never, NOT_FOUND and REFUSE swapped or made KEEP, the swap
always or for the same transition, the store rule as add_ok, !adds &&
add_ok, adds || add_ok and !adds), and at the call sites the add for a
source not found, the add for an inactive or missing new child, the old
source A removed when inactive, the type check on a constant, the scale
type taken mod 3 and the lookup without a name.

git blame on the moved lines shows the upstream commits 6839ff7 and
a1fbf10, and the fork's obs-rust#2080 (the scale type rule), obs-rust#2513 (the swap
refusal) and obs-rust#2584 (the release of the old source A); they move as they
are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol set is unchanged (1766 on the C backend); the six functions are
local.

Refs obs-rust#2595.

* test: Characterize the transition load checks

test_transition_load_steps compiles
libobs/obs-source-transition-load.c.h and
libobs/obs-source-transition-start.c.h (ASan and UBSan) and calls only
their functions through the two headers. 10 cases:

- the header's copies of OBS_SOURCE_TYPE_TRANSITION and the three scale
  types, the enums' sizes and the source outcome values;
- the type check: only 2, over -1000..1000 and the ends of int;
- the scale type: 0, 1 and 2 as they are, anything else Max Only (3,
  -1, the ends of int32_t and int64_t, -1000..1000), compared in 64
  bits (2^32 + 1 and 2^32 + 2 are Max Only, not Aspect or Stretch);
- the load's lookup and source outcome, the swap gate and
  copy_source_state()'s store rule over every combination.

obs_transition_load(), copy_source_state() with the swap, the getters
and obs_transition_set_scale_type() are also copied onto a stand-in
transition whose children count their references and active
references and refuse an add to a transition they contain, to pin end
to end: the loaded fields; a missing name (no lookup, no warning), an
unknown or empty name (none and a warning), a known source (kept, one
reference and one active reference), a source that contains the
transition (released, none and a warning, and the old source A still
goes out); a load onto a slot A that holds a source (taken back), the
same source again and an inactive slot A (released without a removal);
the swap with itself (nothing); all 32 slot states of the swap (old
child present and active or not, new child present, active and
contained or not), each child left with the right references and the
refusal storing none, inactive; and the getters and the setter on a
source of every type and on none.

Characterized, not endorsed:
- the loaded alignment, width and height are truncated to their low 32
  bits: 2^32 + 5 loads as 5, -1 as UINT32_MAX, INT64_MIN as 0;
- the loaded mode is kept as is: 7 stays 7.

It is in the native test graph, in name order, with both headers as
watch inputs. No assert_in_range or fail_msg, so it builds with cmocka
1.x and 2.x, and no two enum types are compared. The real-libobs tests
test_transition_load_release, test_transition_scale_type,
test_transition_swap, test_transition_swap_active and
test_transition_swap_cycle cover the callers.

Refs obs-rust#2595.

* obs-source: Test the transition_load port

RED for the port of libobs/obs-source-transition-load.c.h to a new
transition_load module of rust/obs-source, next to transition_clock,
transition_render and transition_start. The safe core is a stub
(todo!()): is_transition(), scale_type(), looks_up(), source() ->
Source (Keep, NotFound, Refuse), swaps() and copy_stores(), with
TYPE_TRANSITION and the scale types (taken from transition_clock).

The plan sketched wider steps: load_fields() for the five loaded
values, load_source(has_name, found, add_ok), release_old(), swap()
and copy_slot(has_old, old_active, child_active, add_ok). The
truncations and the mode stay C casts, so load_fields() comes down to
scale_type(). load_source() and copy_slot() would take the add's
result before the C knows whether it adds at all; so the lookup, the
outcome after the add and the store rule are their own functions, and
the C keeps its && before each add. release_old() is
transition_start::child_active(), already ported, and the getters'
defaults stay C literals.

tests/source/transition_load.rs ports test_transition_load_steps 1:1:
its 10 cases under the same names (steps_*), in the same order, with
the same values and expectations, the characterized-not-endorsed cases
and the stand-in transition's copies of the callers included.

Edge cases (edge_*) check the core against models of the original C:
- every decision over every combination of its flags;
- the type check over -100,000..100,000, the ends of i32 and 2 with any
  other bit set;
- the scale type at every power of two with its neighbours and
  negations, a stride over i64 and the ends, against origin/master's
  valid_scale_type();
- proptests (4,096 cases each): every decision over full-range values,
  and sequences of up to eleven loads (any name, any int64_t values),
  swaps, swap_begin()s and swap_end()s alone, scale type sets and
  getter reads on three transitions of any source type with children
  that may contain them, through the stand-in against a copy of the
  callers with origin/master's expressions inline; both end in the same
  state, and every child's references match the slots that hold it.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_load passes 1 of 15 (the constants) and fails 14
with "not yet implemented".

Refs obs-rust#2595.

* obs-source: Port the transition load checks

Ports libobs/obs-source-transition-load.c.h, the load, scale type and
swap checks of obs-source-transition.c, to the transition_load module
of rust/obs-source. obs-source-transition.c.h stays C around it:
obs_ptr_valid(), the locks and the texture locks in their order, the
pointer comparisons, the obs_data reads, obs_get_source_by_name(), the
add only for a found source or an active new child, every
obs_source_get_ref() and obs_source_release(), the active child calls,
the (uint32_t) truncations and the mode taken as is, the fields the
swap hands over, the texrender swap, the size and matrix
recalculation, the getters' literals and the logs. The hybrid libobs
drops the C file and links the Rust shims in its place.

Safe core (src/transition_load.rs), six functions:
- is_transition(): type == TYPE_TRANSITION (2);
- scale_type(): 1 and 2 as Aspect and Stretch, any other i64 Max Only,
  matched on the whole i64 (2^32 + 1 is not Aspect);
- looks_up(): has_name; swaps(): !same;
- source() -> Source: NotFound without a source, Refuse when the add
  failed, else Keep;
- copy_stores(): !adds || add_ok.
TYPE_TRANSITION is the header's; the scale types are transition_clock's.
The module denies clippy's arithmetic, indexing, as, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state and
takes no lock.

Shims (src/ffi/source_transition_load.rs): the six C signatures by
value; the source type and the scale type result as int, the loaded
scale type as int64_t, the outcome as the C's enum (u32, as
source_transition_start returns its admission). No pointer crosses and
no struct is mirrored. No intentional difference from the C.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-transition-load (LIBOBS_PORTED_SOURCES), whose PCH
is only obs-source-transition-load.h; libobs.pch.h keeps the header for
obs-source-transition.c. The functions are not EXPORT, so the shims are
hidden: rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. libobs-rust already links the crate's ffi.
The exported symbol sets are unchanged and equal: 1766 on the C
backend, the hybrid and libobs-c-reference; the six functions are local
in all three, and the hybrid's come from the Rust archive (the group's
object is built only for libobs-c-reference). ci/test_ported_sources.py
checks the group on every host.

test_transition_load_steps still compiles the C file into itself,
unchanged. The new test_transition_load_steps_rust builds the same test
source against libobs_rust-static instead, as
test_transition_start_steps_rust does, and links: the test includes the
two headers and obs.h and calls only hidden functions. The 28
transition tests (test_transition_*, test_studio_mode_swap,
test_studio_mode_exit, test_saved_transition, test_tbar_position,
test_fade_to_color_mix, test_visibility_transition,
test_stinger_media_duration, test_item_transition_empty_source,
test_group_hide_transition_audio and test_slideshow_manual_end, with
the _rust variants) pass on the C backend, the hybrid and
libobs-c-reference.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_load:: passes 15 of 15.

No user-visible change, so no docs/features.md line.

Refs obs-rust#2595.

* obs-source: Check transition_load against the C

Tier 3 for the transition_load port. oracle/source_transition_load.c
compiles the unmodified libobs/obs-source-transition-load.c.h with its
six functions renamed to oracle_*, and exports the header's values and
sizes by index. tests/source/transition_load_parity.rs gives each input
to the oracle, the shim (the extern "C" function the hybrid links) and
the core, and compares each bool as the C's byte (0 or 1, the same on
both sides), the outcome as the C's enum value and each number
exactly:

- the header's values and the sizes of the outcome enum, bool and int;
- every function of flags over every combination of them;
- the type check over every int from -1,000,000 to 1,000,000, every
  65,521st int, 2 with each other bit set and the ends;
- the scale type over every value from -1,000,000 to 1,000,000, every
  power of two with its neighbours and negations, the 65,536 values
  either side of 2^32 and -2^32, the 65,536 at each end of int64_t and
  a stride over int64_t;
- proptests (20,000 cases each) over any int type, any int64_t scale
  type and any flags.

Nothing is excluded: the C has no undefined or host-dependent result
here, and the port has no intentional difference.

Mutation check: 23 mutants, all killed. 16 in the core (the type check
at >= and !=, each scale type mapped wrong, the default Aspect, the
value's low 32 bits matched, the lookup always or never, each source
outcome inverted or swapped, the swap gate inverted or constant, and
the store rule as add_ok, !adds && add_ok and adds || add_ok): Tier 1
and Tier 3 each kill all 16. 7 in the shims (a constant type, the
scale type's low 32 bits, a constant lookup, the source and store
arguments swapped, KEEP returned as REFUSE, the swap gate inverted):
Tier 3 kills all 7 (Tier 1 calls only the core).

Refs obs-rust#2595.

* docs: Record the transition load port

rust/README.md gets the row for libobs/obs-source-transition-load.c.h
(obs-source::transition_load), in sorted place: what moved, what stays
C and why (every read and call at its point and under its condition,
the add only under the C's own &&, the truncating casts, the swap's
handover and the getters' literals), the characterized-not-endorsed
behaviours, the tests that see the swap and what Tier 3 covers. The
obs-source crate row, its Cargo description and the lib.rs crate docs
name the new module. docs/rust-port/naming.md already maps
libobs/obs-source*.c.h to rust/obs-source.

rust/obs-c-oracle/benches/port_comparison/source_transition_load.rs
runs 1024 loads over every combination of the flags the C reads,
source types in and out of the enum and saved scale types at 0, 1, 2,
3, -1 and past 32 bits, each through the type check, the lookup, the
source outcome and the scale type, then a swap's gate and the store
rule of both slots, on the shims and on the oracle, and checks both
checksums match. Release, x86_64 Linux, GCC, a loaded host, median per
1024 loads: Rust 16.99 us, C 16.72 us (1.02x), about 17 ns a load.

The port changes nothing a user can see, so docs/features.md has no
line.

Fixes obs-rust#2595.
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.

bug: libobs: obs_transition_load leaks the source already in slot A

2 participants