Repository navigation
obs-core: Port the canvas flag rules - #2546
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/rust-port-canvas-flag-rules-and-187
branch
from
October 27, 2026 03:03
bf99545 to
45e4a43
Compare
rdoupe
marked this pull request as ready for review
October 27, 2026 03:54
Behaviour-neutral extraction before the Rust port. The flag rules and setter checks of obs-canvas.c.h move to libobs/obs-canvas-rules.c.h, as seventeen functions on plain values declared in the new libobs/obs-canvas-rules.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - _main_flags() and _public_flags(): MAIN | PROGRAM for obs_create_main_canvas(), and the public mask of obs_canvas_create(), obs_canvas_create_private() and obs_load_canvas(), which still casts the saved int64 to uint32_t itself; - _main_view() and _mix_audio(): the view type and the mix's mix_audio, in obs_canvas_create_internal() and obs_canvas_reset_video_internal(); - _public(): a canvas that is not private is named, unnamed, renamed through the hash table and signalled on obs->signals (canvas_dosignal(), obs_canvas_create_internal(), obs_canvas_destroy(), obs_canvas_set_name()); - _holds_scenes(): SCENE_REF, in obs_canvas_destroy(), obs_canvas_insert_source() and obs_canvas_remove_source(); - _saves(): neither EPHEMERAL nor REMOVED; - _size_set() and _format_set(): obs_canvas_has_valid_video_info(); - _resets(), _global_signals(), _channel_ok(), _name_empty(), _renames(), _removable(), _mark_removed() and _removed(): the checks of obs_canvas_reset_video(), obs_canvas_rename_source(), obs_canvas_set_channel(), obs_canvas_set_name(), obs_canvas_remove() and obs_canvas_removed(). Split per read, as #2153 did. canvas->flags is read without a lock and obs_canvas_remove() writes it from any thread, so each check gets the value of its own read, at its point. Every check behind a || or && is still asked only where the C reached it: obs_source_is_scene() only on a SCENE_REF canvas, obs_video_active() only for a canvas that may reset, strcmp() only for a canvas that may be renamed, and each video info field only after the one before it was set. The rest stays C at its point: the allocations and frees, the context data calls, the signal handler setup, the mutexes, obs_view_init() and _free(), the mix and its list under mixes_mutex, HASH_CLEAR and the walk that takes next before each release (the #2038 and #2049 order), every reference and weak reference, the pointer checks (source, previous source, canvas, mix, the "already in a canvas" step), the group walk, the calldata, every signal, obs_source_activate() and _deactivate(), strcmp() and the logs. The flag values, REMOVED, the public mask, VIDEO_FORMAT_NONE and MAX_CHANNELS are copied into the header, so it needs only stdbool.h and stdint.h; obs-canvas.c.h checks them with _Static_assert. REMOVED and PUBLIC_CANVAS_FLAGS leave obs-canvas.c.h. Checked in a scratch harness (not committed). It compiles origin/master's obs-canvas.c.h verbatim, and this branch's with obs-canvas-rules.c.h, over a stand-in libobs.pch.h whose functions log every call in order with its arguments: the context data calls (init may fail), signal_handler_add_array() (may fail), the mutex init (may fail), every lock and unlock, obs_view_init() and _free(), the mix create (may fail) and free, the mix list, HASH_CLEAR, every signal with its calldata, the strong and weak references (a weak get may fail), obs_source_get_ref() (may return NULL), _release(), _is_scene(), _is_group(), _activate(), _deactivate(), obs_video_active(), the scene walks, the obs_data reads and writes, and blog(). A channel_change handler may replace the source in the calldata. A concurrent writer may flip any flag bit (MAIN, ACTIVATE, MIX_AUDIO, SCENE_REF, EPHEMERAL, REMOVED, an unknown bit), the private flag or a video info field of any live canvas at any call. Each run makes up to sixteen random calls of the whole canvas API (every constructor with random flags, names and video info; obs_load_canvas() with saved flags of 0, -1, INT64_MIN, INT64_MAX, above 32 bits and random; save, the video info check, both resets, insert, remove and rename of scene, group and plain sources, set_channel at 0 to 3, 63, 64, 65 and UINT32_MAX with the same, another or no source, set_name with NULL, "", "Main", the same and other names, remove, the getters, scene create, remove and move, refs taken and released, the mix clears and render), then releases everything and removes the sources left alive, as obs_free_data() does. The C++ build also logs every read and write of the flags, the private flag and the video info fields. 6,600,000 runs: 1,000,000 each with GCC and Clang at -O0 and -O2 as C (67,558,889 logged lines each side), 1,000,000 each with G++ at -O0 and -O2 as C++ with the logged reads (95,351,694 each side), and 200,000 each under ASan and UBSan with no recovery (GCC -O0 and Clang -O2 as C, G++ -O1 as C++). The two logs are identical in every configuration. gcov over 100,000 runs takes every branch of the moved decisions both ways, but the two no caller reaches: canvas_dosignal() with no core signal name, and obs_canvas_remove() failing to take a reference to a canvas its caller holds. 34 deliberately broken moves were planted, and the C++ build fails all 34: each rule changed (each operand dropped or swapped, a bound off by one, an inverted result, the REMOVED write dropped), the destroy walk reading the flags once before it, obs_video_active() asked before the flags and the flags read without video info, obs_source_is_scene() asked before the flags, a video info field read early, strcmp() before the MAIN check, the flags read before the canvas's own signal in set_channel(), remove_source() and rename_source(), the remove check after the reference, the private flag read once in set_name(), the create's mix_audio read from the canvas instead of its argument, and a second read of the flags in save. The C builds, which see reads only through the writer, fail 29 of them. git blame on the moved lines shows upstream commits (3d57b1f introducing canvases, 66f4792, 1ecea56, 0fd1261) and the fork's fe75932 (the public mask, #2151); 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. The exported symbol sets are unchanged: 1766 on the C backend, the hybrid and libobs-c-reference, the same set on all three, with the seventeen functions local. Refs #2544.
test_canvas_rules_steps compiles libobs/obs-canvas-rules.c.h (ASan and UBSan) and calls only its functions through obs-canvas-rules.h. 11 cases: - the header's copies of the flags, REMOVED, the public mask, VIDEO_FORMAT_NONE and MAX_CHANNELS against obs.h; - the main canvas's flags (MAIN | PROGRAM), and the public mask over every single bit and every combination of the five public flags, MAIN, REMOVED and an unknown bit; - obs_load_canvas()'s cast of the saved int64 before the mask, at 0, the named flags, 0x80000000, 0xffffffff, above 32 bits, -1, -2, -32 and the ends of int64; - every flag rule (view type, mix_audio, scene references, save, reset, global signals, rename, remove, removed, the REMOVED write) over those 128 combinations and over every single bit; - the main, program, preview and device canvases, and a caller asking for MAIN; - the public canvas rule, the video info checks (sizes 0, 1, 1920 and UINT32_MAX; formats NONE, I420, NV12, P010 and outside the enum), the channel bound (0 to 1023, 63, 64, 65, 2^31 and UINT32_MAX), the empty name (NULL, "", " ", "a", "Main", "\0b", 0xff) and removing twice. Characterized, not endorsed: - the saved int64 is truncated before the mask, so bits above 31 are dropped silently and a negative value keeps the public flags of its low word (-1 loads as every public flag); - a video format outside the enum counts as set; - a removed canvas can still be reset and renamed. It is in the native test graph, in name order, with the header as a watch input. No assert_in_range or fail_msg, so it builds with cmocka 1.x and 2.x, and no two enum types are compared. Passes 11/11 on the C backend and the hybrid. test_canvas_flags, test_scene_private_canvas, test_canvas_destroy_scene_refs, test_shutdown_canvas_weak_ref, test_scene_canvas_characterization, test_context_names and test_view cover the callers through the real libobs, and pass on both. Refs #2544.
RED for the port of libobs/obs-canvas-rules.c.h to a new canvas_rules module of rust/obs-core, next to canvas_draw. The safe core is a stub (todo!()): main_flags(), public_flags(), main_view(), mix_audio(), is_public() (public is the C name; is_public reads better in Rust), holds_scenes(), saves(), size_set(), format_set(), resets(), global_signals(), channel_ok(), name_empty(), renames(), removable(), mark_removed() and removed(), with the flag constants (MAIN, ACTIVATE, MIX_AUDIO, SCENE_REF, EPHEMERAL, PROGRAM, PREVIEW, DEVICE, REMOVED, PUBLIC), FORMAT_NONE and MAX_CHANNELS. name_empty() takes the name's first byte, None for NULL, so the core reads no pointer. The plan sketched wider steps (reset(has_ovi, flags, video_active), rename(empty, flags, same), scene_ref(flags, is_scene)). Each would take a value the C reads or calls only behind a || or &&, so each check is its own function, asked at its own point, as #2153 did; the pointer checks, obs_source_is_scene(), obs_video_active() and strcmp() stay C. tests/obs_core/canvas_rules.rs ports test_canvas_rules_steps 1:1: its 11 cases under the same names (steps_*), in the same order, with the same values and expectations, the characterized-not-endorsed cases included. Three new proptests (edge_*, 4096 cases each) check every rule over any u32 flags, the load over any i64 (truncated as the C's cast, never keeping MAIN or REMOVED), and the size, format, channel, name byte and private rules over any value, against models written from the C's expressions. soldr cargo test -p obs-data --test obs-tests-core -- canvas_rules:: passes 1 of 14 (the constants) and fails 13 with "not yet implemented". Refs #2544.
Ports libobs/obs-canvas-rules.c.h, the canvas flag rules and setter checks of obs-canvas.c, to the canvas_rules module of rust/obs-core. obs-canvas.c.h stays C around it: every read of the canvas's flags, private flag and video info fields at its point, the allocations and frees, the context data calls, the signal handler setup, the mutexes, the view, the mix and its list, HASH_CLEAR and the destroy walk (the #2038 and #2049 order), every reference, the pointer checks, the group walk, obs_source_is_scene() and _is_group(), obs_video_active(), strcmp(), the calldata, every signal, the activation calls and the logs. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/canvas_rules.rs), seventeen functions: - main_flags(): MAIN | PROGRAM; public_flags(): flags & PUBLIC; - main_view(): ACTIVATE; mix_audio(): MIX_AUDIO; is_public(): !is_private; holds_scenes(): SCENE_REF; - saves(): neither EPHEMERAL nor REMOVED; size_set(): not 0; format_set(): not FORMAT_NONE (a format outside the enum is set); - resets() and renames(): not MAIN; global_signals(): MAIN; channel_ok(): below MAX_CHANNELS; - name_empty(): None or a first byte of 0; - removable(): neither REMOVED nor MAIN; mark_removed(): | REMOVED; removed(): REMOVED. 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/canvas_rules.rs): the seventeen C signatures by value; the flags as u32, the format as int. The one pointer is the name of obs_canvas_set_name(): the shim reads its first byte only when it is not NULL, as the C's !name || !*name. No struct is mirrored. No intentional difference from the C. C side: the file leaves libobs.core-source for its own group, libobs.ported-canvas-rules, registered in its own fragment, libobs/build/ported-source-sets/canvas-rules.json (LIBOBS_PORTED_SOURCES), so it edits no shared ported list. Its PCH is only obs-canvas-rules.h; libobs.pch.h keeps the header for obs-canvas.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 same set as origin/master; the seventeen 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_canvas_rules_steps still compiles the C file into itself, unchanged, and passes 11/11. It has no _rust variant: linking it against libobs_rust-static fails with 401 undefined references (108 symbols), because the shims' archive member (an obs_core codegen unit) also holds the other obs-core ports, as for test_canvas_draw_steps; its tests.d file says so. The Tier 3 parity tests compare the shims with the C instead. soldr cargo test -p obs-data --test obs-tests-core -- canvas_rules:: passes 14 of 14. No user-visible change, so no docs/features.md line. Refs #2544.
rust/obs-c-oracle/oracle/canvas_rules.c compiles the unchanged
libobs/obs-canvas-rules.c.h with its seventeen functions renamed
oracle_*, after obs.h, plus the header's copies, enum
obs_canvas_flags, VIDEO_FORMAT_NONE, MAX_CHANNELS and the type sizes.
tests/obs_core/canvas_rules_parity.rs (7 tests) runs the shim, the C
and the safe core on every input and compares the results exactly: the
C's bool as the byte it returns, the flags as the uint32_t.
- the 23 values and sizes against the C headers, and the main flags;
- exhaustive: every flag rule for every low 16-bit flags word under
16 high words (bits 16, 17, 30 and 31), every single bit and every
combination of the known flags, REMOVED and an unknown bit; the load
for 786,432 saved int64 values (four high words, three top halves,
every low half) and the ends; the size and channel for 0 to 70,000,
every 65,521st u32 and the ends; the format for -70,000 to 70,000
and the ends; the name for NULL and every first byte, through a C
string;
- each caller's decisions in their order (the three constructors, the
save, the reset, the channel bound and global signal, the name
refusals and the public rename, the remove and REMOVED write, the
video info chain), one copy on each side, for every combination of
the known flags, REMOVED, an unknown bit, the private flag, six
channels, four names, three video infos and five formats;
- proptests (20,000 cases each): every decision over any value, and
the callers over all of it at once.
No input reaches a division or a 128-bit multiply on either side, so
nothing is skipped on MSVC x64. No intentional differences.
The parity module passed 3 runs in a row with fresh seeds.
test_canvas_rules_steps passes 11/11 under ASan and UBSan. The
committed regression files hold the seeds proptest saved while mutants
failed; all pass on the port.
Mutation check (the mutants are not committed): 36 mutants, 24 in the
core and 12 in the shims, each run against Tier 1 (14 tests) and Tier
3 (7). 34 fail. The two that survive are equivalent: the resets shim
calling renames() (both are "not MAIN"), and the name shim passing
Some(0) for NULL (both are empty). Tier 1 does not reach the shims;
Tier 3 kills every other shim mutant. Each mutant and the tests that
fail on it:
1. core, main_flags: no SCENE_REF
T1: steps_canvas_kinds, steps_constructor_flags
T3: callers_every_input, proptest_callers,
values_match_the_c_headers
2. core, public_flags: keeps MAIN
T1: edge_flag_rules_any_flags, edge_load_any_int64,
steps_canvas_kinds, steps_constructor_flags,
steps_load_flags_from_int64
T3: callers_every_input, every_flags_word, every_load,
proptest_callers, proptest_decisions
3. core, public_flags: keeps REMOVED
T1: edge_flag_rules_any_flags, edge_load_any_int64,
steps_constructor_flags, steps_load_flags_from_int64,
steps_remove_twice
T3: callers_every_input, every_flags_word, every_load,
proptest_callers, proptest_decisions
4. core, public_flags: drops EPHEMERAL
T1: edge_flag_rules_any_flags, edge_load_any_int64,
steps_canvas_kinds, steps_constructor_flags,
steps_load_flags_from_int64
T3: callers_every_input, every_flags_word, every_load,
proptest_callers, proptest_decisions
5. core, main_view: MIX_AUDIO
T1: edge_flag_rules_any_flags, steps_canvas_kinds,
steps_flag_rules_every_bit, steps_flag_rules_every_combination
T3: callers_every_input, every_flags_word, proptest_callers,
proptest_decisions
6. core, mix_audio: ACTIVATE
T1: as 5; T3: as 5
7. core, is_public: not negated
T1: edge_values_any_input, steps_public_rule
T3: callers_every_input, every_value, proptest_callers,
proptest_decisions
8. core, holds_scenes: EPHEMERAL
T1: edge_flag_rules_any_flags, steps_canvas_kinds,
steps_flag_rules_every_bit,
steps_flag_rules_every_combination, steps_remove_twice
T3: every_flags_word, proptest_decisions
9. core, saves: ignores REMOVED
T1: edge_flag_rules_any_flags, steps_flag_rules_every_bit,
steps_flag_rules_every_combination, steps_remove_twice
T3: callers_every_input, every_flags_word, proptest_callers,
proptest_decisions
10. core, saves: ignores EPHEMERAL
T1: as 5; T3: as 5
11. core, size_set: > 1
T1: steps_video_info_checks
T3: every_value
12. core, format_set: > 0
T1: edge_values_any_input, steps_video_info_checks
T3: callers_every_input, every_value, proptest_callers,
proptest_decisions
13. core, resets: always
T1: as 5; T3: as 5
14. core, global_signals: negated
T1: edge_flag_rules_any_flags, edge_load_any_int64,
steps_canvas_kinds, steps_flag_rules_every_bit,
steps_flag_rules_every_combination
T3: callers_every_input, every_flags_word, proptest_callers,
proptest_decisions
15. core, channel_ok: <=
T1: steps_channel_bound
T3: callers_every_input, every_value, proptest_callers
16. core, name_empty: NULL only
T1: edge_values_any_input, steps_name_checks
T3: callers_every_input, every_value, proptest_callers,
proptest_decisions
17. core, name_empty: NULL is a name
T1: as 16; T3: as 16
18. core, renames: always
T1: as 5; T3: as 5
19. core, removable: ignores REMOVED
T1: as 9; T3: as 9
20. core, removable: ignores MAIN
T1: as 5; T3: as 5
21. core, mark_removed: no write
T1: as 9; T3: as 9
22. core, removed: bit 30
T1: as 9; T3: as 9
23. core, REMOVED: 1 << 30
T1: edge_flag_rules_any_flags, steps_constants,
steps_flag_rules_every_bit
T3: callers_every_input, every_flags_word, proptest_callers,
proptest_decisions, values_match_the_c_headers
24. core, MAX_CHANNELS: 63
T1: steps_channel_bound, steps_constants
T3: callers_every_input, every_value, proptest_callers,
values_match_the_c_headers
25. shim, public_flags: main_flags
T3: callers_every_input, every_flags_word, every_load,
proptest_callers, proptest_decisions
26. shim, main_view: mix_audio
T3: callers_every_input, every_flags_word, proptest_callers,
proptest_decisions
27. shim, public: negated
T3: callers_every_input, every_value, proptest_callers,
proptest_decisions
28. shim, saves: removable
T3: as 26
29. shim, resets: renames: SURVIVES (equivalent)
30. shim, global_signals: removed
T3: as 26
31. shim, format_set: format & 0x7fffffff
T3: every_value
32. shim, channel_ok: low byte only
T3: every_value, proptest_callers, proptest_decisions
33. shim, name_empty: reads the byte, answers Some(1)
T3: callers_every_input, every_value, proptest_callers,
proptest_decisions
34. shim, name_empty: NULL as Some(0): SURVIVES (equivalent)
35. shim, mark_removed: public_flags
T3: as 26
36. shim, removed: removable
T3: as 26
Refs #2544.
- rust/README.md: the obs-core crate row names libobs/obs-canvas-rules.c.h, and a row for the file says what is swapped in the hybrid, what obs-canvas.c.h keeps and why each read asks its own function, the copied values, the characterized cases, why there is no _rust variant, and what Tier 3 covers; - rust/obs-core: the crate description and the lib.rs docs list the module; - docs/rust-port/naming.md: obs-canvas-rules.c.h, extracted from obs-canvas.c.h, maps to rust/obs-core; - rust/obs-c-oracle/benches/port_comparison/canvas_rules.rs: canvas_rules/create and canvas_rules/setters, the constructors' and the setters' decisions in their order over 1024 calls on each side, folded into a checksum both must match. It allocates nothing, so the per-module allocation check holds. The bench's build.rs finds it in the directory, so no shared list changes. port_comparison (x86_64 Linux, GCC, not pinned, load average about 3; criterion's median per 1024 calls): create 7.8 us Rust, 5.4 us C; setters 16.7 us Rust, 11.4 us C, about 2 to 5 ns more a decision through the exported shims. These run when a canvas is created, saved, reset, renamed or removed and when a scene or channel changes, never per frame. No docs/features.md line: the port changes no behaviour. Fixes #2544.
test_canvas_rules_steps pins the seventeen rules on their own, and the move was checked against the callers only in a scratch harness. This pins what the callers in obs-canvas.c do with the rules, through the real libobs and its public API, so it runs unchanged against the C backend, the hybrid and libobs-c-reference. 9 cases: - constructor_flags: the main canvas is MAIN | PROGRAM; create and create_private drop MAIN, REMOVED and unknown bits; obs_load_canvas() keeps the public flags of the saved value's low word; - save_rules: the saved flags and private flag, a private canvas reloaded, and no save for an ephemeral or a removed canvas; - reset_rules: no video info, the main canvas, and active video (a raw video callback on the main mix) are refused, with no video_reset signal; otherwise the canvas gets a mix and signals once; - set_name_rules: NULL, "", the same name and the main canvas are refused with no signal; a public canvas is renamed in the name table and signals canvas_rename globally; a private one signals only its own rename and stays out of the name table; - remove_rules: one remove signal each, none for a second remove or for the main canvas, and the REMOVED bit in the flags; - scene_refs: a scene on the main canvas (SCENE_REF) outlives its creator's reference until it is removed; a plain source on it gets no canvas reference; a scene on a canvas without SCENE_REF dies with its last reference; a SCENE_REF canvas releases its scenes when it is destroyed; - group_walk: removing a group removes its items from every scene of its canvas; a removed plain source leaves the canvas but its items stay in the scenes; - rename_source_signals: a scene rename on the main canvas signals source_rename globally, one on another canvas only on that canvas; - channel_replace: a channel_change handler that replaces the source. Characterized, not endorsed: the saved int64 is truncated before the mask; a removed canvas can still be renamed; the handler's replacement is stored and activated without a reference of its own, so clearing the channel releases one more reference on it than the canvas took, and the reference taken on the source passed in is never released. It needs a display and OpenGL (Linux, the graphics suite, under xvfb-run like test_main_mix_before_video), and is in the test graph in name order. No assert_in_range or fail_msg, and no two enum types are compared. Passes 9/9 three runs in a row on the C backend and the hybrid, and 9/9 against libobs-c-reference, each under a private Xvfb. Refs #2544.
rdoupe
force-pushed
the
fix/rust-port-canvas-flag-rules-and-187
branch
from
October 27, 2026 05:58
45e4a43 to
737e1db
Compare
This was referenced Oct 27, 2026
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2544
What and why
Ports the flag rules and setter checks of
libobs/obs-canvas.c.htorust/obs-core, as a new modulecanvas_rules, next tocanvas_draw. Every canvas goes through them: the main canvas, the canvases plugins and the frontend create, the canvases a scene collection loads, and every scene that joins or leaves one.MAIN | PROGRAMfor the main canvas, and the public mask ofobs_canvas_create(),obs_canvas_create_private()andobs_load_canvas();obs_canvas_create_internal()andobs_canvas_reset_video_internal(): the view type (ACTIVATE) and the mix'smix_audio;SCENE_REF: whether the canvas holds a reference to each scene in it (obs_canvas_destroy(),_insert_source(),_remove_source());obs_save_canvas(),obs_canvas_has_valid_video_info(),obs_canvas_reset_video(),obs_canvas_rename_source(),obs_canvas_set_channel(),obs_canvas_set_name(),obs_canvas_remove()andobs_canvas_removed(): their refusals and flag checks.One function per decision, asked where the C made it.
canvas->flagsis read without a lock andobs_canvas_remove()writes it from any thread, so each check gets the value of its own read, at its point. A check behind a||or&&is still asked only where the C reached it:obs_source_is_scene()only on aSCENE_REFcanvas,obs_video_active()only for a canvas that may reset,strcmp()only for a canvas that may be renamed, each video info field only after the one before it was set. Seventeen functions cross the C ABI, all hidden.What stays C, at its point: the allocations and frees, the context data calls, the signal handler setup, the mutexes, the view, the mix and its list under
mixes_mutex,HASH_CLEARand the destroy walk that takesnextbefore each release (the #2038 and #2049 order), every reference and weak reference, the pointer checks, the group walk, the calldata, every signal (achannel_changehandler can still replace the source, stored without a new reference),obs_source_activate()/_deactivate(),strcmp(),obs_video_active()and every log.obs_load_canvas()keeps its(uint32_t)cast of the savedint64.Seven commits:
Move (behaviour-neutral,
882ab259b): the decisions go tolibobs/obs-canvas-rules.c.h, declared in the newobs-canvas-rules.hwithoutEXPORT. The header copies the flag values,REMOVED, the public mask,VIDEO_FORMAT_NONEandMAX_CHANNELS, andobs-canvas.c.hchecks them with_Static_assert. The file joinslibobs.core-source.The move was checked against the original code. A scratch harness (not committed) compiles origin/master's
obs-canvas.c.hverbatim and this branch's with the moved file, over a stand-inlibobs.pch.hthat logs every call in order with its arguments (context data, signal setup, mutexes, view, mix and its list,HASH_CLEAR, every signal with its calldata, strong and weak references, the source calls,obs_video_active(), the scene walks, theobs_datacalls,blog()); several of them may fail. A concurrent writer may flip any flag bit, the private flag or a video info field of any live canvas at any call, and achannel_changehandler may replace the source. Each run makes up to sixteen random calls across the whole canvas API, then tears down asobs_free_data()does. The C++ build also logs every read and write of the flags, the private flag and the video info fields.-O0and-O2as C, 1,000,000 each (67,558,889 logged lines each side); G++ at-O0and-O2as C++ with the logged reads, 1,000,000 each (95,351,694 each side); ASan and UBSan with no recovery, 200,000 each (GCC-O0, Clang-O2, G++-O1). The logs are identical in every configuration.canvas_dosignal()with no core signal name, andobs_canvas_remove()failing to take a reference its caller holds).obs_video_active()orobs_source_is_scene()asked before the flags, a video info field read early,strcmp()before theMAINcheck, the flags read before a canvas signal, the remove check after the reference, the private flag read once, a second read in save). The C++ build fails all 34.Characterization (
19e822006):test_canvas_rules_steps, 11 cases over every combination of the known flags,REMOVEDand an unknown bit, every single bit, the load cast, the kinds of canvas, the video info checks, the channel bound, the empty name and removing twice. Passes 11/11 on the C backend and the hybrid.RED (
10aa29a5a): Tier 1 againsttodo!(); ports the 11 C cases 1:1 and adds 3 proptests over any flags, any savedint64and any size, format, channel, name byte and private flag.GREEN (
1dc1284ff): the safe core (seventeen functions; it denies clippy's arithmetic, indexing,as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock) and seventeen#[no_mangle]shims, in a newlibobs.ported-canvas-rulesgroup whose PCH is only the new header. The one pointer isobs_canvas_set_name()'s name: the shim reads its first byte only when it is not NULL. The commit registers the group in its own fragment,libobs/build/ported-source-sets/canvas-rules.json, and updatessource-sets.json(the header), the unity lists, the three export lists andci/test_ported_sources.py.test_canvas_rules_stepshas no_rustvariant, as fortest_canvas_draw_steps: linking it againstlibobs_rust-staticfails with 401 undefined references (108 symbols), because the shims' archive member also holds the rest of obs-core. Its tests.d file says so.Tier 3 (
4d80e4b10): a C oracle of the unchanged file and 7 parity tests that compare shim, C and core byte for byte: every low 16-bit flags word under 16 high words, every combination of the known flags,REMOVEDand an unknown bit, 786,432 savedint64values, sizes, channels and formats around their bounds, NULL and every first byte of a name, each caller's decisions in their order, and proptests (20,000 cases each). Mutation check: 36 mutants (24 in the core, 12 in the shims); 34 fail. The two survivors are equivalent: the resets shim callingrenames()(both are "notMAIN"), and the name shim passing a zero byte for NULL (both are empty). The commit message lists each mutant and the tests that catch it.Docs (
254ab94a2): therust/README.mdrows, the crate description andlib.rsdocs, thenaming.mdrow, and aport_comparisonbench (canvas_rules/createand/setters; create 7.8 µs Rust and 5.4 µs C, setters 16.7 µs Rust and 11.4 µs C per 1024 calls, about 2 to 5 ns more per decision through the exported shims; none of these runs per frame). It allocates nothing, so the per-module allocation check holds; the bench'sbuild.rsfinds it in the directory.Caller characterization (
737e1dbfe, from review):test_canvas_rules_callers, 9 cases through the real libobs and its public API, so it runs unchanged against the C backend, the hybrid andlibobs-c-reference. It pins what the callers do with the rules: the flags each constructor keeps and whatobs_save_canvas()writes or refuses;obs_canvas_reset_video()refusing no video info, the main canvas and active video (a raw video callback on the main mix);obs_canvas_set_name()'s refusals (NULL, "", the same name, the main canvas) and its public and private renames; removing twice; theSCENE_REFrule for a scene, a group and a plain source, and the group walk (a removed group leaves every scene of its canvas, a removed plain source's items stay); the main canvas's globalsource_rename; and achannel_changehandler replacing the source (stored and activated without a reference of its own, and the reference on the source passed in kept: characterized, not endorsed). Linux with OpenGL, graphics suite, underxvfb-runliketest_main_mix_before_video. Passes 9/9 on all three.The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and
libobs-c-reference, the same set as master, with the seventeen functions local in all three. The port changes nothing a user can see, sodocs/features.mdhas no line.int64is truncated before the mask (-1 loads as every public flag); a video format outside the enum counts as set; a removed canvas can still be reset and renamed.Upstream's canvases are Dennis Sädtler's work (with tt2468's public-canvas signal rule); the public mask is this fork's (#2151). No upstream issue.
RED → GREEN
10aa29a5a.soldr cargo test -p obs-data --test obs-tests-core -- canvas_rules::passes 1 of 14 (steps_constants) and fails 13 with "not yet implemented". The local gates on it:--lane lintok;--test-diff origin/masterruns 4589 tests, 4576 pass, 13 fail (exactly those), 6 skipped. Runs were onbf9954507.canvas_rules::14/14; Tier 3canvas_rules_parity::7/7.obs_startup(test_v4l2_busy_signal,test_output_deactivate_state); both pass on each build under a private Xvfb. The canvas tests (test_canvas_rules_steps,test_canvas_flags,test_scene_private_canvas,test_canvas_destroy_scene_refs,test_shutdown_canvas_weak_ref,test_scene_canvas_characterization,test_context_names,test_view) pass on both.test_canvas_rules_callerspasses 9/9 on the C backend and the hybrid (three runs in a row each) and againstlibobs-c-reference, under a private Xvfb.libobs-c-reference(./unittest's Docker lane) could not run on this host (no Docker access), so PR CI runs it. Its Rust lane passed.--test-diff origin/master4596 run, 4596 passed, 6 skipped;--lane lintok;--lane crossok;soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsclean;soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses.--test-diff origin/masterand--lane lintagain on873552f85: 4596 run, 4596 passed, 6 skipped; lint ok.401b6e798and873552f85, on top offe410a975.a9344844b(the output stop port in the same shared lists, merged keeping both sides): the CI quick checks,./lint,--lane lint,--lane cross, the Windows clippy, theport_comparisonbench test and the Rust lane of./unittest(4629 run, 4629 passed, 6 skipped) pass; the export sets are again 1766 and equal on all three with the seventeen functions local; the canvas tests,test_canvas_rules_stepsandtest_canvas_rules_callersincluded, pass on the C backend and the hybrid. Runs were on45e4a4332.09f435a55(master's per-portported-source-sets/fragments and generatedport_comparisonlist, build: Let each port register its source groups independently (#1997) #2552 and build: Generate the port_comparison unit list from the directory (#1997) #2554):port_comparison.rsis master's again (the bench is found in the directory), and the group moved into its own fragment. The CI quick checks,./lint,--lane cross, the Windows clippy, theport_comparisonbench test and--test-diff origin/master(4629 run, 4629 passed, 6 skipped) pass. Built with master's new backend switches (OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON), the export sets are 1766 and equal on all three, the seventeen functions local; the hybrid's come from Rust and the group's object is built only for the C backend andlibobs-c-reference. Runs were on737e1dbfe.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC