Skip to content

libobs: Leave swapped slot empty on cycle - #2513

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/transition-swap-cycle
Oct 26, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/transition-swap-cycle

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2499

What and why

Stand-in models left as they are (please confirm): the stand-in model of the swap in test/cmocka/test_transition_start_steps.c (copy_state() / tr_swap()) and the one in rust/obs-source/tests/source/transition_start.rs (swap()) copy the old copy_source_state(): they have no notion of a cycle, so they still store the slot's source. They do not call the real function and still pass, but on a cycle they no longer describe it. No existing C test assertion is changed (AGENTS.md). test_transition_swap_active (#2497) checks only the activate/show counts after such a swap, not what the slot holds, and passes unchanged.

obs_transition_swap_begin() (the frontend calls it when the transition is changed) copies each slot of the old transition into the new one through copy_source_state(). When the slot's source contains the new transition (a scene that holds it as an item, a scene holding that scene, or the new transition itself), obs_source_add_active_child() fails. #2497 keeps the slot inactive in that case, but the slot still held the source. While it does, the source's tree goes through the transition back to the source, so any walk of its active tree (showing or activating the scene, or the audio thread's walk of an output channel) enters the transition a second time and locks its non-recursive mutex twice: OBS hangs. Upstream OBS Studio master has the same copy_source_state() (it ignores the add's result entirely); there is no upstream issue or fix.

The fix: when that add fails, copy_source_state() logs a warning, releases the reference it took and leaves the slot empty and inactive, as obs_transition_set() refuses such a source since #2498 (and obs_transition_load() always has). The old transition still holds its own reference until obs_transition_swap_end() clears it, so the release under the transition locks never destroys the source. The add is now made before the slot is written instead of after; it reads only the new transition's show and activate counts, not its slots, so the order does not change what it does. Everything else the swap hands over (the other slot, the running transition's flags and clock) is unchanged. For a running transition towards such a scene, slot A is handed over and slot B is left empty, so the transition ends on nothing.

Why the add's result rather than a second recursion walk (walks() and check_transition_recursion(), as #2498 does): the swap holds both transitions' mutexes, and a walk with the public obs_source_enum_full_tree() would lock the new transition again on exactly the cycle it looks for. obs_source_add_active_child() already walks the source's tree and stops at the new transition, and every way it can fail here is a cycle (a null source never reaches it; the source being the transition itself is its parent == child check). The Rust child_active() step still decides whether the add runs; no Rust code changes.

Left as before: an inactive slot is copied without an add, so it is not checked. A transition has a source in an inactive slot only when its own add of that source failed, that is, when it already holds a cycle; obs_transition_set() (#2498), obs_transition_load() and now the swap no longer leave one behind.

New test test_transition_swap_cycle (real libobs, core video, Linux under xvfb-run, graphics suite in test-graph.json): a scene holds a leaf source and the transition, and an outer scene holds that scene. Each cycle case sets the transition to an unrelated source, makes the scene output channel 0's source, sets a second transition outside the scene to the cycle, swaps it in, and checks that the slot is empty, that showing the scene again returns, and the activate/show counts and the leaf's callbacks. The walk runs under a watchdog thread: if it has not returned after 5 seconds, the test prints HANG: ... and exits with a failure, so a hang fails instead of stalling CI.

  • swap_acyclic_source_is_stored (control): a source outside the cycle is handed over, held, and released by the next set.
  • swap_containing_scene_is_not_stored: the scene that holds the transition.
  • swap_outer_scene_is_not_stored: the outer scene (the cycle is two levels deep).
  • swap_itself_is_not_stored: the second transition holds the destination transition itself.
  • swap_running_keeps_slot_a_only: the second transition runs from the unrelated source towards the scene; slot A is handed over, slot B is left empty.

RED → GREEN

  • RED commit: d54c337 (test: Check transition swap does not store cycle; the same failure was seen on its earlier base, before the rebase onto current master). On the C build, hybrid libobs and libobs-c-reference, the control passes, then swap_containing_scene_is_not_stored reports slot A holds 'cycle scene', expected '(none)' and HANG: showing the scene after swapping in the scene that holds the transition did not return within 5000 ms, and the watchdog ends the test binary (about 6 s) with a failure. Run with each other case first (C build), each fails the same way: the outer scene (slot A holds 'outer scene'), the transition itself (slot A holds 'transition') and the running transition (slot B holds 'cycle scene'), each followed by the HANG line.
  • GREEN: 432d12f. test_transition_swap_cycle 5/5 on all three lanes, each refused slot logged once (4 warnings); all cases skip without a display. The affected ctest set (transition|scene|studio_mode|fade|stinger|group|source_active|swap) passes with no skips: 52/52 on the C build, 61/61 on hybrid libobs, 61/61 against libobs-c-reference (rebuilt first). Exported symbols are the same on all three. Local gate: --lane lint, --test-diff origin/master and --lane cross pass.
  • Real app (UI, protocol output or logging changes): N/A. The UI cannot put a transition into a scene; plugins and scripts can. The new warning is obs_transition_swap_begin: cannot give transition '<name>' source '<name>' due to infinite recursion.

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)

Swap a transition that holds a scene (a scene holding that scene, or
the destination transition itself) into a transition inside that
scene, and check that the destination slot is left empty and that
showing the scene again returns, under a 5-second watchdog. The swap
stores the source although the destination could not add it, so the
walk enters the transition again and hangs on its mutex.

Refs obs-rust#2499
copy_source_state() stored the old transition's slot source in the
new transition even when the add of that source failed because it
contains the new transition (or is that transition). obs-rust#2497 cleared
the slot flag, but the slot still held the cycle, so showing the scene
walked into the transition again and locked its mutex twice. Release
the source and leave the slot empty, with a warning, as
obs_transition_set() refuses such a source.

Fixes obs-rust#2499
@rdoupe
rdoupe requested a review from zackees as a code owner October 26, 2026 17:41
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: this tightens #2497. When the active-child add fails in copy_source_state() (a cycle), the swapped slot is left empty, its reference released, with a warning that matches obs_transition_set()'s refusal (#2498), instead of keeping an inactive slot whose tree walk would lock tr_dest twice. A new test is added, no existing test changes, and the ledger line is in. Queuing.

@zackees
zackees enabled auto-merge October 26, 2026 17:42
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit 1df5f73 Oct 26, 2026
36 checks passed
@rdoupe rdoupe mentioned this pull request Oct 27, 2026
6 of 7 tasks
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: transition swap can still store a cycle (hang)

2 participants