Repository navigation
obs-c-oracle: Free what port_comparison's fixtures allocate - #2159
Merged
Merged
Conversation
util's bmem/count pair compares obs-util's bnum_allocs() with the C bmem oracle's counter, so any earlier module whose fixtures allocate through the shared bmalloc and don't free it fails that pair instead (obs-rust#2154: 16 vs 0 on a full run). comparisons() now runs each module through module(), which checks both counters are where they were before the module ran, so a leak names its module. On master it fails at source_profiler: 16 Rust-side allocations live. The module list becomes a sorted modules![...] list, one per line, and ci/test_sorted_shared_lists.py reads it there. Refs obs-rust#2154
source_profiler's bench made its 16 C sources with oracle_sp_source_new(), a bzalloc through obs-util's shared bmalloc, and left them live. They were the 16 Rust-side allocations that made util's bmem/count pair (16 vs 0) panic on a full port_comparison run. Free them with oracle_sp_source_free() after the closing oracle_sp_reset(), which has already dropped the profiler's entries for them. Refs obs-rust#2154
Since obs-rust#1094 the dstr-libc oracle took os_utf8_to_wcs_ptr and os_mbs_to_utf8_ptr from oracle/platform.c, which allocates with oracle_bmalloc, while dstr-libc.c frees the wide string with bfree and keeps the UTF-8 string as a dstr's array, both obs-util's allocator. Every oracle_dstr_to_upper/to_lower freed an oracle_bmalloc block with bfree: the counters drift apart (-4 / +4 after util's dstr/to_upper benches in --test mode) and the two allocators are only compatible by accident. Define the two helpers in oracle/dstr_libc.c as their util/platform-conversions.c.h bodies around oracle/platform.c's conversions, allocating with bmalloc. A full port_comparison --test run now completes. Fixes obs-rust#2154
rdoupe
force-pushed
the
fix/bench-bmem-count
branch
from
October 24, 2026 14:04
194c1eb to
b2590b8
Compare
This was referenced Oct 24, 2026
This was referenced Oct 24, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
rust/README.md: a row for libobs/obs-source-volume.c.h -> obs-source::volume_apply (the four functions, what stays C and in what order, what is kept and characterized, the one intentional difference, the tests that see the swap and what Tier 3 compares), the obs-source crate row lists the file, and the ptm_gate row now says get_source_volume() goes through its four functions too. The crate's description and lib.rs list the new module. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. port_comparison gets source_volume.rs: apply_audio_volume() and get_source_volume() over 1024 ticks (every gate flag, volumes at and around 0 and 1, mixer masks from none to all, actions due and not due), and 1024 snaps, each side through its own functions, with checksums that must match. Measured with soldr cargo bench -p obs-c-oracle --bench port_comparison -- source_volume, every fixture built (obs-rust#2159 made the full run work again): apply_volume 6.71 us Rust, 9.84 us C per 1024 ticks; snap 1.76 us Rust, 1.70 us C per 1024. Fixes obs-rust#2158
This was referenced Oct 24, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
- rust/README.md: the obs-source crate row names libobs/obs-source-transition-render.c.h, and a new ported-unit row says what moved, what stays C and in which order, how values cross, what is kept and characterized, the intentional difference (a null pos is not written), which tests see the swap and what Tier 3 compares. - rust/obs-source: the crate description and the lib.rs docs list the new module. - rust/obs-c-oracle/benches/port_comparison/source_transition_render.rs, in the sorted mod and modules![...] lists: render (1024 frames of the video steps, the draw choice, the direct index and two offsets) and audio (1024 audio ticks of the stop step, the mix, and two children's checks and start frames). Both sides must give the same checksum; the fixtures allocate nothing, so the module's bmem check (obs-rust#2159) holds. Measured on x86_64 Linux, GCC, load average 6: render 12.46 us Rust, 12.83 us C (0.97x); audio 10.81 us Rust, 11.11 us C (0.97x). docs/rust-port/naming.md needs no row: libobs/obs-source*.c.h already maps to rust/obs-source. Fixes obs-rust#2173
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
rust/README.md: a row for libobs/obs-source-volume.c.h -> obs-source::volume_apply (the four functions, what stays C and in what order, what is kept and characterized, the one intentional difference, the tests that see the swap and what Tier 3 compares), the obs-source crate row lists the file, and the ptm_gate row now says get_source_volume() goes through its four functions too. The crate's description and lib.rs list the new module. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. port_comparison gets source_volume.rs: apply_audio_volume() and get_source_volume() over 1024 ticks (every gate flag, volumes at and around 0 and 1, mixer masks from none to all, actions due and not due), and 1024 snaps, each side through its own functions, with checksums that must match. Measured with soldr cargo bench -p obs-c-oracle --bench port_comparison -- source_volume, every fixture built (obs-rust#2159 made the full run work again): apply_volume 6.71 us Rust, 9.84 us C per 1024 ticks; snap 1.76 us Rust, 1.70 us C per 1024. Fixes obs-rust#2158
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
The rust/README.md crate table now lists libobs/obs-scene-audio-window.c.h among the rust/obs-scene units, and its port table has a row for it, next to the audio actions: the seven functions, what stays C (audio_lock, the volume buffer and the audio actions, every obs_source_* call, the mix loops and every field read, in the old order and count), why several calls and not one plan per item, how values cross, what the characterization pins and the port keeps, the one intentional difference (MSVC x64 rates above 1 GHz), the _rust variant of the steps test, the real-libobs tests that see the swap and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to rust/obs-scene. No docs/features.md line: no user-visible change. port_comparison gets its own bench file, benches/port_comparison/scene_audio_window.rs, in the sorted modules! list: one audio tick of a 16-item scene at 48 kHz, both loops of scene_audio_render()'s decisions in its order, folded into a checksum both sides must match (checked before timing). It allocates nothing, so the leak check of obs-rust#2159 holds. On x86_64 Linux (GCC, pinned to one core, load average near 40, so noisy; medians, two runs): 185 / 332 ns Rust against 215 / 508 ns C per scene tick, well under a microsecond per 1024-frame tick. Fixes obs-rust#2178
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
- rust/README.md: the obs-source crate row names libobs/obs-source-transition-render.c.h, and a new ported-unit row says what moved, what stays C and in which order, how values cross, what is kept and characterized, the intentional difference (a null pos is not written), which tests see the swap and what Tier 3 compares. - rust/obs-source: the crate description and the lib.rs docs list the new module. - rust/obs-c-oracle/benches/port_comparison/source_transition_render.rs, in the sorted mod and modules![...] lists: render (1024 frames of the video steps, the draw choice, the direct index and two offsets) and audio (1024 audio ticks of the stop step, the mix, and two children's checks and start frames). Both sides must give the same checksum; the fixtures allocate nothing, so the module's bmem check (obs-rust#2159) holds. Measured on x86_64 Linux, GCC, load average 6: render 12.46 us Rust, 12.83 us C (0.97x); audio 10.81 us Rust, 11.11 us C (0.97x). docs/rust-port/naming.md needs no row: libobs/obs-source*.c.h already maps to rust/obs-source. Fixes obs-rust#2173
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 24, 2026
…#2175) * libobs: Move the source volume snap and apply decisions into obs-source-volume.c Behaviour-neutral extraction before the Rust port. The volume decisions of get_source_volume() and apply_audio_volume() move to libobs/obs-source-volume.c.h, as four functions on plain values declared in the new libobs/obs-source-volume.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_volume_snap(muted, volume): 0 when muted or close_float(volume, 0.0f, 0.0001f), 1 when close_float(volume, 1.0f, 0.0001f), else the volume, the same expressions; - obs_source_volume_action_due(action_ts, audio_ts, duration): whether the first queued action falls inside this tick, action_ts < audio_ts + duration, the sum wrapping as before; - obs_source_volume_step(vol, mixers): SKIP at vol == 1.0f, CLEAR at vol == 0.0f (so -0 too) or mixers == 0, else MULTIPLY (NaN multiplies); - obs_source_volume_mixes(audio_mixers, mixers, mix): whether the multiply touches a mix, in both masks, with the same (1 << mix). get_source_volume()'s gate (disabled, muted, push-to-mute and push-to-talk active) now goes through obs-rust#2089's helpers, obs_source_ptm_gate_held(), _mutes() and _talk_mutes(), instead of a second copy of their expressions; its stop times already went through obs_source_ptm_gate_stop_time(). obs-source.c.h keeps every read and write of the source's fields in the same order: each pressed flag is read where it was (in the stop-time test and again for its active flag), a stop time only when its key is not pressed, and enabled, muted and the gates' enabled flags only where the short-circuit reached them. source->audio_mixers is still read once per mix (another thread sets it). The one change in reads: source->volume is read once and passed to the snap, also when muted, where the C read it up to three times and not at all when muted; it is written only by apply_audio_action() on the same mix thread, so every read sees the same value. The action queue and its mutex, apply_audio_actions(), conv_frames_to_time() (the duration is passed in), the memset, the multiply loops and multiply_output_audio() stay as they were. The new file joins libobs.core-source, before obs-source.c.h, 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); the four functions are local. Checked in a scratch harness (not committed) that compiles origin/master's get_source_volume() and apply_audio_volume() verbatim next to this branch's and the moved file, on a stand-in source, and records every call they make (the action mutex, conv_frames_to_time(), apply_audio_actions(), the memset and multiply_output_audio(), floats by bit pattern): 30,000,000 runs of each function under ASan and UBSan (20,000,000 at -O2, 10,000,000 at -O0) with every gate flag, stop times and clocks around each other and at the u64 ends, volumes from the snap edges and their float neighbours, -0, NaN payloads, +-inf, subnormals and random bit patterns, mixer masks at 0, 1, 0x3f, 0x40, 0xff, 0x80000000, UINT32_MAX and random, 0 to 2 queued actions due and not due (the sum wrapping), and durations at the u64 ends; 150,000 of the runs also clear and multiply real buffers of random bits. 220,449,492 recorded calls, the returned volumes (by bits) and the source after each call are equal, and so are the buffers. Ten deliberately broken moves (each snap edge, the muted test, the -0 result, the due compare and a modular one, the clear on <= 0 and on no mixers, either mask, the mix bit) all fail it; vol == 1.0f written as fabsf(vol - 1.0f) <= 0.0f, which is equivalent, passes. git log -L on both functions shows obs-rust#2058 (the saturated stop times) and and 1 compares and the due compare date from the 2015 audio subsystem and move as they are. Refs obs-rust#2158 * test: Characterize the source volume snap and apply decisions test_source_volume_apply_steps compiles libobs/obs-source-volume.c.h and libobs/obs-source-ptm-gate.c.h into itself (ASan and UBSan) and calls only their hidden functions, through their headers. get_source_volume() and apply_audio_volume() are copied from obs-source.c onto a stand-in source, with apply_audio_actions(), the memset and multiply_output_audio() recorded instead of run, so the compositions are pinned too. 14 cases pin: - the snap at 0: 0, -0 (to +0), +-0.0001f and the float inside each, the smallest subnormal and FLT_MIN of either sign snap to 0; the float just past 0.0001f, 0.00011f and 0.001f are kept; - the snap at 1: the last floats that snap, 1 - 1677 * 2^-24 and 1 + 838 * 2^-23, and their outer neighbours, which do not (checked to be float neighbours); characterized, not endorsed: 0.9999f, 1.0001f, 1.0f - 0.0001f and 1.0f + 0.0001f all round to those outer floats, so none of them snaps; 0.99995f and 1.00005f do; - every other volume kept bit for bit: 0.5, 2, 20, +-FLT_MAX, -0.5, +-inf, -1 and NaNs of either sign and several payloads (a signalling NaN is still NaN); muted gives +0 for every volume, NaN and -0 included; - the gate over all 64 combinations of enabled, muted and each gate's enabled flag and pressed key, with each stored stop time before, at and after the clock and saturated (1,600 runs against the rule written out, the stored stop times included), and an open gate giving the snapped volume held, inside the delay and after it; - the action-due compare at audio_ts + duration - 1 (due), at it and + 1 (not), actions from before the tick, a duration of 0, the u64 ends, and characterized, not endorsed, the wrap: in the last tick before the clock ends audio_ts + duration wraps, so nothing at or after audio_ts is due; - the step for 15 volumes with 12 mixer masks (0, 1, 2, 0x20, 0x3f, 0x40, 0x41, 0x7f, 0x80, 0xff, 0x80000000, UINT32_MAX): exactly 1 skips whatever the mixers (characterized, not endorsed: with none too, where the callers have already cleared the buffers), exactly 0 or -0 or no mixers clears, anything else multiplies, the float next to 0 or 1 and NaN included; the enum values and size; - the mix choice over every pair of those masks and each of the six mixes; - apply_audio_volume(): a due action hands the tick to apply_audio_actions() and nothing else; one not due, or an action timestamp with an empty queue, does not; each step with every pair of masks: the clear is one memset of all six mixes and eight channels, the multiply runs over the mixes in both masks in order with the channels and the snapped volume; characterized, not endorsed: tick mixers of 0x40 and above are not 0, so nothing is cleared, and no mix is in both masks, so nothing is multiplied (the callers have cleared those mixes already). The test is in the core suite of the test graph and links libm except on MSVC. test_source_audio_ranges, test_source_volume_mix, test_audio_capture_mix_race and the scene item audio action tests cover the callers through the real libobs. Refs obs-rust#2158 * obs-source: Add Tier 1 tests for the source volume snap and apply port Adds the volume_apply module to rust/obs-source with its API and every function as todo!(): SNAP_EPSILON (the C's 0.0001f), MAX_AUDIO_MIXES, the Step enum (SKIP, CLEAR, MULTIPLY with the C enum's values), snap(), action_due(), step() and mixes(). tests/source/volume_apply.rs ports test_source_volume_apply_steps 1:1 (steps_*: the same 14 cases, inputs and expectations, with the stand-in source and the copies of get_source_volume() and apply_audio_volume(), the gate through obs_source::ptm_gate) and adds edge cases (edge_*): - the snap against the rule computed in f64 (exact there; within [0.5, 2] the f32 difference is exact too, and outside it both distances are at least 0.5): every float within 2^14 ulps of +-0.0001, of the two last floats that snap to 1 and of +-0 (196,620 patterns, NaNs past the top included), a stride of 4,103 through all 2^32 bit patterns (1,046,788) and a proptest over any bit pattern, muted and not; the epsilon's bits (0x38d1b717); - the step against the IEEE compares written another way, over any bit pattern and mixers, -0, NaN and the floats next to 0 and 1 included; - the due compare against u128 arithmetic wrapping at 2^64, over every triple of 35 special values, full-range u64 proptests and actions within 3 ns of the tick's end; - the mix choice for every index below 32 with every pair of mask edges, and none chosen at 32 and past (an intentional difference: the C's int shift is undefined there; libobs passes mix < 6); - get_source_volume() over any flags, stop times, delays, clocks and volume bits against the gate and the snap written out. RED: soldr cargo test -p obs-data --test obs-tests-core source::volume_apply: 2 passed (the epsilon's bits and the enum values), 23 failed, each on a todo!() (obs_source_volume_snap, _action_due, _step and _mixes). Refs obs-rust#2158 * obs-source: Port the source volume snap and apply decisions Ports libobs/obs-source-volume.c.h, the volume decisions of get_source_volume() and apply_audio_volume(), to the volume_apply module of rust/obs-source. obs-source.c.h stays C around it: every read and write of the source's fields in the same order, the gate's short-circuits (through obs-rust#2089's ptm_gate shims), the action queue and its mutex, apply_audio_actions(), conv_frames_to_time(), the memset, the multiply loops and multiply_output_audio(). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/volume_apply.rs): - snap(): 0.0 when muted or close to 0, 1.0 when close to 1, else the volume with its bits; close() is close_float(): (f1 - f2).abs() <= SNAP_EPSILON in f32, the C's fabsf(f1 - f2) <= precision, so NaN is never close and -0.0 is close to 0 (and gives +0.0); - action_due(): action_ts < audio_ts.wrapping_add(duration), the C's uint64_t sum; - step(): Skip at vol == 1.0, Clear at vol == 0.0 (-0.0 too) or no mixers, else Multiply (NaN included), IEEE compares as the C's; - mixes(): the mix's bit in both masks; a mix of 32 or more chooses none. 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_volume.rs): the four functions keep the C signatures; the step goes back as the C enum's value (u32, 0 to 2). No pointer crosses. Intentional difference: obs_source_volume_mixes() with a mix of 31 or more, where the C's 1 << mix on an int is undefined (libobs passes mix < 6). C side: the file leaves libobs.core-source for its own group, libobs.ported-source-volume (LIBOBS_PORTED_SOURCES), whose PCH is graphics/math-defs.h (close_float) and obs-source-volume.h; libobs.pch.h keeps the header for obs-source.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 four functions are local in all three, and the hybrid's come from the Rust archive (no C object of the group in the hybrid libobs). ci/test_ported_sources.py checks the group on every host. test_source_volume_apply_steps still compiles the C files into itself, unchanged, and test_source_volume_apply_steps_rust runs the same test source against libobs_rust-static alone (and libm except on MSVC): the obs-source member links on its own, as for test_source_ptm_gate_steps_rust, and holds both the volume and the ptm_gate shims the test calls. Tier 1 obs_source::volume_apply passes 25/25. Refs obs-rust#2158 * obs-source: Check the source volume snap and apply port against the C Adds the oracle_* build of the unchanged libobs/obs-source-volume.c.h to obs-c-oracle (oracle/source_volume.c, its four functions renamed, plus the enum's values and size), and tests/source/volume_apply_parity.rs, which gives every input to the oracle, the shim and the core. Floats are compared by bits (NaN payloads, -0 and the infinities count), the step as the u32 the C returns, each bool as the byte the C returns (it must be 0 or 1): - the enum's values and size (4) against the C header; - the snap, muted and not, and the step with 14 mixer masks, over 115 special floats (the snap edges and the floats around them, -0, NaN payloads, +-inf, subnormals, 0.9999f and 1.0001f); - the snap over every float within 2^16 ulps of +-0.0001, of the last floats that snap to 1 and of +-0 (786,444 patterns); - the mix choice exhaustively over every pair of the low seven mask bits, with no high bits and with all of them, for every mix of 0 to 30 (1,015,808 calls; from 31 the C's int shift is undefined, the one intentional difference, checked in Tier 1); - the due compare over every triple of 35 special values (42,875); - get_source_volume() copied from obs-source.c onto a stand-in source and run once over the oracle's functions (obs-rust#2089's ptm_gate oracle for the gate) and once over the shims: the 64 flag combinations, five stored stop times per gate around the clock and saturated, three pairs of delays, three clocks and 16 volumes (230,400 runs); the result's bits and both stored stop times must match; - apply_audio_volume() copied the same way, apply_audio_actions(), the memset and multiply_output_audio() recorded: the 64 flag combinations, 16 volumes, 14 x 14 masks and four queue states (none, not due, due, the wrapped end), 802,816 runs; the recorded calls and the source must match; - proptests (20,000 cases each) over any f32 bit pattern for the snap and the step, any masks, full-range u64 times for the due compare and within 3 ns of the tick's end, and full-range sources through both callers. An ignored test runs all 2^32 bit patterns through the snap (muted and not) and the step (with and without mixers) against the oracle; in a release build it passes in 35 s. The regression files hold the seeds proptest saved while the mutation check below ran. Mutation check (not committed): 25 mutants of the core and the shims, each run against Tier 1 (25 tests) and Tier 3 (14). 23 are killed by both or by the tier that reaches them. C6, the snap's distance computed in f64, is equivalent (within [0.5, 2] the f32 difference is exact, outside it both are at least 0.5) and survives both. C19, a mix shift that wraps past 31, is killed by Tier 1 only, since Tier 3 stays where the C is defined. Tier 1 does not reach the shims; Tier 3 kills all six shim mutants. Tier 1 25/25 and Tier 3 14/14 (1 ignored) pass. Refs obs-rust#2158 * docs: Record the source volume snap and apply port rust/README.md: a row for libobs/obs-source-volume.c.h -> obs-source::volume_apply (the four functions, what stays C and in what order, what is kept and characterized, the one intentional difference, the tests that see the swap and what Tier 3 compares), the obs-source crate row lists the file, and the ptm_gate row now says get_source_volume() goes through its four functions too. The crate's description and lib.rs list the new module. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. port_comparison gets source_volume.rs: apply_audio_volume() and get_source_volume() over 1024 ticks (every gate flag, volumes at and around 0 and 1, mixer masks from none to all, actions due and not due), and 1024 snaps, each side through its own functions, with checksums that must match. Measured with soldr cargo bench -p obs-c-oracle --bench port_comparison -- source_volume, every fixture built (obs-rust#2159 made the full run work again): apply_volume 6.71 us Rust, 9.84 us C per 1024 ticks; snap 1.76 us Rust, 1.70 us C per 1024. Fixes obs-rust#2158
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
The rust/README.md crate table now lists libobs/obs-scene-audio-window.c.h among the rust/obs-scene units, and its port table has a row for it, next to the audio actions: the seven functions, what stays C (audio_lock, the volume buffer and the audio actions, every obs_source_* call, the mix loops and every field read, in the old order and count), why several calls and not one plan per item, how values cross, what the characterization pins and the port keeps, the one intentional difference (MSVC x64 rates above 1 GHz), the _rust variant of the steps test, the real-libobs tests that see the swap and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to rust/obs-scene. No docs/features.md line: no user-visible change. port_comparison gets its own bench file, benches/port_comparison/scene_audio_window.rs, in the sorted modules! list: one audio tick of a 16-item scene at 48 kHz, both loops of scene_audio_render()'s decisions in its order, folded into a checksum both sides must match (checked before timing). It allocates nothing, so the leak check of obs-rust#2159 holds. On x86_64 Linux (GCC, pinned to one core, load average near 40, so noisy; medians, two runs): 185 / 332 ns Rust against 215 / 508 ns C per scene tick, well under a microsecond per 1024-frame tick. Fixes obs-rust#2178
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
- rust/README.md: the obs-source crate row names libobs/obs-source-transition-render.c.h, and a new ported-unit row says what moved, what stays C and in which order, how values cross, what is kept and characterized, the intentional difference (a null pos is not written), which tests see the swap and what Tier 3 compares. - rust/obs-source: the crate description and the lib.rs docs list the new module. - rust/obs-c-oracle/benches/port_comparison/source_transition_render.rs, in the sorted mod and modules![...] lists: render (1024 frames of the video steps, the draw choice, the direct index and two offsets) and audio (1024 audio ticks of the stop step, the mix, and two children's checks and start frames). Both sides must give the same checksum; the fixtures allocate nothing, so the module's bmem check (obs-rust#2159) holds. Measured on x86_64 Linux, GCC, load average 6: render 12.46 us Rust, 12.83 us C (0.97x); audio 10.81 us Rust, 11.11 us C (0.97x). docs/rust-port/naming.md needs no row: libobs/obs-source*.c.h already maps to rust/obs-source. Fixes obs-rust#2173
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 24, 2026
* libobs: Move the transition render and audio steps into obs-source-transition-render.c Behaviour-neutral extraction before the Rust port. The render and audio step decisions of the transitions in obs-source-transition.c.h move to libobs/obs-source-transition-render.c.h, declared in the new libobs/obs-source-transition-render.h without EXPORT (hidden): - obs_source_transition_render_video_due() and _video_stop(): the stop step of obs_transition_video_render2() and obs_transition_video_render_direct(). Due at t >= 1 while the video transitions (a NaN t is never due). Then the video ends, and the transition stops unless its audio runs on; the direct render first ends the audio of a transition that is not active (eb35b07). render2 has no inactive rule and passes active as true. - obs_source_transition_render_draw(): render2's draw choice: both children through the callback while the video transitions with the textures locked and a callback set; else source B while the audio transitions; else source A. - obs_source_transition_render_direct_index(): the child the direct render draws: B only for OBS_TRANSITION_SOURCE_B while transitioning. - obs_source_transition_render_audio_stop(): the stop step of obs_transition_audio_render() and transition_stop_audio() (removed): with a timestamp at t >= 1 while the audio transitions; without one only once the video has ended too (7af9c2d). The audio ends, and the transition stops unless its video runs on. - obs_source_transition_render_audio_mix(): mix each child that is there while the audio transitions, else copy source A. - obs_source_transition_render_audio_valid() and _audio_place(): the checks of transition_process_audio(): a child, its audio not pending and not duplicated; a timestamp that is not 0 (3191f5d); the start frame, ns_to_audio_frames(sample_rate, ts - min_ts) written out as its util_mul_div64() so the file needs only util_uint64.h, and the "> AUDIO_OUTPUT_FRAMES" check. - obs_source_transition_render_offset(): the scaled child size of recalculate_transition_matrix() and the offsets it passes to add_alignment(), before the (int) casts: each product rounded to float, then subtracted, as before. Why nine functions and not one step each: every call keeps its place and its condition. obs_source_active() is asked only once the video step is due, so the due test is its own function; obs_source_get_audio_mix() is read between the timestamp check and the start-frame check, so the place says NONE, LATE or MIX and the C returns before or after the read; calc_time() is asked only with a timestamp, so the audio stop step takes whether there is one. The re-read of the children after the audio stop step stays where it was. obs-source-transition.c.h keeps the locks, get_video_time() and calc_time(), copy_transition_state() and the refs, obs_transition_stop(), handle_stop() and the signals, obs_source_active(), the drop of removed children (obs_source_removed() is asked only of a child that is there) and transition_calc_min_ts() with its pending check and obs-rust#130's snapshot read (as obs-rust#2055 left them), the texture trylock, render_child(), the callbacks, the cx/cy check, mix_child() and get_sample_time(), the mixer loop, the memcpy(), the (int) casts, add_alignment() and the matrix calls. transition_process_audio() now reads audio_is_duplicated also when audio_pending is set (two plain field reads of a child it holds a reference to); nothing else is read that was not read before. The target crosses as int; obs-source-transition.c.h checks at compile time that the header's values are OBS_TRANSITION_SOURCE_B and AUDIO_OUTPUT_FRAMES and that enum obs_transition_target is int-sized. Checked against the unchanged functions with a scratch harness (not committed): master's and the moved recalculate_transition_matrix(), obs_transition_video_render2(), obs_transition_video_render_direct(), transition_process_audio() and obs_transition_audio_render() (with their helpers) against stubs that log every lock, trylock, clock read, ref, stop, signal, render, gs_*/matrix call, alignment, timestamp read, mix and memcpy with its arguments (floats as bits), plus the final state. 4,008,640 scenarios, byte-identical logs under GCC -O2 and clang -O0. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2173 * test: Characterize the transition render and audio steps test_transition_render_steps, 16 cases, compiles libobs/obs-source-transition-render.c.h (ASan and UBSan) and calls only its nine functions. It pins: - the video stop step's due test at 14 values of t: 0, -0, the smallest subnormal, 0.5, just below 1, 1, just above 1, 2, +-inf, -1, and quiet, negative and signalling NaNs (only t >= 1 is due; a NaN t never ends a transition), with and without the video transitioning; - the stop step for every audio and active flag, and as render2 and the direct render apply it at t just below, at and above 1 and NaN, for every video, audio (and, direct, active) combination: which flags end, the video stop signal and obs_transition_stop(); - render2's draw choice for all 16 flag combinations, including a video transition whose textures are busy or which has no callback (it draws B only while its audio transitions, else A); - the direct render's child for both transitioning states and targets A, B, 2, -1 and the ends of int (only B while transitioning draws B); - the audio stop step with a timestamp at the 14 values of t, without one (only once the video has ended, 7af9c2d; t is not read), and for every pair of children absent, removed, pending, without a timestamp or with one, as obs_transition_audio_render() passes them; - the mix or copy and the validity check for every flag; - the start frame: a timestamp of 0 (nothing more read, pos untouched); the frame edges at 48 kHz and 44.1 kHz around min_ts, 1023, 1024 and 1025 frames, a start at AUDIO_OUTPUT_FRAMES mixing (">", where the scene uses ">="), sample rates of 0, 1 and 1e9; a timestamp below min_ts wrapping to a late frame (885443715538058 with a 64-bit size_t), and a min_ts near UINT64_MAX wrapping back to frame 0; - the offsets for each scale type's scale (32x16 in 64x64 as in test_transition_scale_type, 1280x720, 1000x1000 and 3840x2160 in 1920x1080), the product rounded to float before the subtract (3 times 0x3eaaaaab gives exactly 0; 1053 in 1080 gives -2^-13), transitions of size 0, infinite and NaN scales, and u32-sized sizes. Every pinned float is one rounded multiply and one subtract, the same on every platform the tests run on. Kept, characterized, not endorsed: - a NaN t never ends a transition (render or audio stop step); - a busy texture lock or a missing callback draws the old scene, A, during a video-only transition; - a start frame of exactly AUDIO_OUTPUT_FRAMES mixes 0 frames; - the audio re-read after the stop step does not drop removed children; transition_process_audio() then checks only pending and duplicated; - a timestamp below min_ts wraps and is placed late; a min_ts near UINT64_MAX wraps back to an early frame. It is in the test graph in name order, with libm except on MSVC, and the tests.d fragment says what it pins. Passes 16/16 on the C backend. Refs obs-rust#2173 * obs-source: Add Tier 1 tests for the transition render and audio steps port The transition_render module of rust/obs-source, with its types and todo!() bodies, and its Tier 1 tests (tests/source/transition_render.rs, run by obs-data's obs-tests-core): - steps_*: test/cmocka/test_transition_render_steps.c 1:1, the 16 cases under the same names and in the same order, with the same inputs and expectations, the "characterized, not endorsed" ones included. The stop steps run as the render functions apply them under the lock. - edge_*: the draw choice, the direct index and the mix against their rules over every flag and any i32 target; the start frame at the first ns of every frame up to 1100 and the ns before it at eight sample rates; proptests (20,000 cases each) for the due test and the audio stop step over any f32 bit pattern (half near 1), the video stop step over every flag, the start frame against an exact 128-bit model over any u64 min_ts and difference wherever util_mul_div64() cannot overflow (a rate up to 1e9), its order in ts, and the offsets against an f64 model of one rounded multiply and one rounded subtract over f32 bit patterns and whole-number sizes (never a wide float range, obs-rust#1951). The safe API differs from the C header where Rust says it better: the audio stop step takes Option<f32> (None: no timestamp, the clock is not asked), the place carries its frame (Place::Late(pos), Place::Mix(pos)), the mix is a struct of three bools, and the direct index is a usize. soldr cargo test -p obs-data --test obs-tests-core source::transition_render fails 25 of 25, each with "not yet implemented". Refs obs-rust#2173 * obs-source: Port the transition render and audio steps Ports libobs/obs-source-transition-render.c.h, the render and audio step decisions of the transitions, to the transition_render module of rust/obs-source. obs-source-transition.c.h stays C: the locks, the clock reads, copy_transition_state() and the refs, obs_transition_stop(), handle_stop() and the signals, obs_source_active(), the removed and pending checks and the timestamp reads, the texture trylock, the renders and callbacks, mix_child() and get_sample_time(), the mixer loop and the memcpy(), the (int) casts, add_alignment() and the matrix calls. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/transition_render.rs): - video_due(): t >= 1.0 in f32 while the video transitions (NaN never). - video_stop(): StopAudio when not active, else Stop without the audio, else End. - draw(): Callback with the video, the lock and a callback; else B while the audio transitions; else A. - direct_index(): 1 only for TARGET_B while transitioning. - audio_stop(Option<f32>, ...): with a t, t >= 1.0 and the audio; without one, the audio with the video ended; then Stop without the video, else End. - audio_mix() and audio_valid(): the C's flags. - audio_place(): None for a timestamp of 0; else the frame ns_to_audio_frames(rate, ts - min_ts) with the difference wrapping, as Late past AUDIO_FRAMES and Mix up to it. mul_div64() is the C's util_mul_div64(): the wrapping u64 formula, or the exact 128-bit quotient on MSVC x64 (the new platform module's MUL_DIV64_IS_UDIV128, as obs-scene's), written out so the crate still depends on no other crate. The frame is cast to usize as the C casts to size_t (to_size(), the one as-conversion, commented). - offset(): each product rounded to f32, then the subtract (Rust never fuses them). The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented and unreachable lints, keeps no state and takes no lock. Shims (src/ffi/source_transition_render.rs): plain values in and out; the steps as the C's enum values, the mix as its bits, the offset as the repr(C) struct. The place writes the frame through the size_t * only for Late and Mix, as the C does. Intentional difference: a null pos is not written (the C writes through it; libobs passes its own size_t). C side: the file leaves libobs.core-source for its own group, libobs.ported-source-transition-render (LIBOBS_PORTED_SOURCES), whose PCH is only obs-source-transition-render.h and util/util_uint64.h; libobs.pch.h keeps the header for obs-source-transition.c. The nine 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 nine are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_transition_render_steps still compiles the C file into itself, unchanged. The new test_transition_render_steps_rust builds the same test source against libobs_rust-static alone (the test includes only the header, so no SIMDe and no libobs include directories), with libm except on MSVC. It passes 16 of 16 on the hybrid tree. Tier 1 source::transition_render passes 25/25. Refs obs-rust#2173 * obs-source: Check the transition render and audio steps port against the C Tier 3 for obs-source::transition_render. The oracle (rust/obs-c-oracle/oracle/source_transition_render.c) compiles the unmodified libobs/obs-source-transition-render.c.h with its nine functions renamed to oracle_*, plus a table of its constants and layouts. The renames also rename struct obs_source_transition_render_offset and enum obs_source_transition_render_audio_place, whose tags share their function's name, so the table names the renamed tags. source::transition_render_parity (13 tests and one ignored) compares the shims with the C, the frame through a size_t * pre-filled with the same guard on both sides (written or not), floats by their bits: - the header's constants, enum values and sizes, the offset struct's size and field offset, int, bool and size_t, and FLT_EVAL_METHOD 0; - every flag combination of the video stop step, the draw choice, the mix and the validity check; the direct index over both states and every target from -70000 to 70000, every 65521st i32 and the ends; the due test and the audio stop step over every flag at 40 special t; the three stop steps as the render functions apply them; - the due test and the audio stop step over every 4099th f32 bit pattern and every pattern within 2^16 of 1.0 (every f32, run once with --release --ignored: all equal); - the place over every combination of 26 special timestamps for ts and min_ts and 14 sample rates up to usize::MAX (where util_mul_div64() wraps), and around the first ns of every frame up to 1100 at eight rates, above and below min_ts; - the offsets over 14 special sizes and scales on each side and both sides at once; - proptests (20,000 cases each) over full-range u64 timestamps (half near min_ts, either side), any usize rate, f32 bit patterns for t, sizes and scales (never a wide Range<f32>, obs-rust#1951) and any i32 target. In the offsets only, where one float operation has two NaN operands, which NaN comes out depends on the operand order the compiler picks (obs-rust#2021); there both sides must give a NaN. Everything else is bit for bit. The intentional difference (a null pos is not written by the shim) is checked on the shim alone. Tier 1 and the parity module pass 38 of 38 (one ignored), 10 runs in a row with fresh seeds. No proptest regression file came up. Refs obs-rust#2173 * docs: Record the transition render and audio steps port - rust/README.md: the obs-source crate row names libobs/obs-source-transition-render.c.h, and a new ported-unit row says what moved, what stays C and in which order, how values cross, what is kept and characterized, the intentional difference (a null pos is not written), which tests see the swap and what Tier 3 compares. - rust/obs-source: the crate description and the lib.rs docs list the new module. - rust/obs-c-oracle/benches/port_comparison/source_transition_render.rs, in the sorted mod and modules![...] lists: render (1024 frames of the video steps, the draw choice, the direct index and two offsets) and audio (1024 audio ticks of the stop step, the mix, and two children's checks and start frames). Both sides must give the same checksum; the fixtures allocate nothing, so the module's bmem check (obs-rust#2159) holds. Measured on x86_64 Linux, GCC, load average 6: render 12.46 us Rust, 12.83 us C (0.97x); audio 10.81 us Rust, 11.11 us C (0.97x). docs/rust-port/naming.md needs no row: libobs/obs-source*.c.h already maps to rust/obs-source. Fixes obs-rust#2173
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
The rust/README.md crate table now lists libobs/obs-scene-audio-window.c.h among the rust/obs-scene units, and its port table has a row for it, next to the audio actions: the seven functions, what stays C (audio_lock, the volume buffer and the audio actions, every obs_source_* call, the mix loops and every field read, in the old order and count), why several calls and not one plan per item, how values cross, what the characterization pins and the port keeps, the one intentional difference (MSVC x64 rates above 1 GHz), the _rust variant of the steps test, the real-libobs tests that see the swap and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to rust/obs-scene. No docs/features.md line: no user-visible change. port_comparison gets its own bench file, benches/port_comparison/scene_audio_window.rs, in the sorted modules! list: one audio tick of a 16-item scene at 48 kHz, both loops of scene_audio_render()'s decisions in its order, folded into a checksum both sides must match (checked before timing). It allocates nothing, so the leak check of obs-rust#2159 holds. On x86_64 Linux (GCC, pinned to one core, load average near 40, so noisy; medians, two runs): 185 / 332 ns Rust against 215 / 508 ns C per scene tick, well under a microsecond per 1024-frame tick. Fixes obs-rust#2178
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 24, 2026
* libobs: Move the scene audio render window decisions out Behaviour-neutral extraction before the Rust port. The decisions of scene_audio_render() in obs-scene.c.h move to libobs/obs-scene-audio-window.c.h, declared in the new libobs/obs-scene-audio-window.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_scene_audio_window_pick(): the source an item's audio is read from, the show transition while it plays for a visible item, the hide transition for a hidden one, else the source (an enum the scene maps back to the item's pointer); - obs_scene_audio_window_counts() and obs_scene_audio_window_earliest(): the items whose timestamp takes part in the tick's (not pending, and visible or hiding), and the fold to the earliest non-zero one; - obs_scene_audio_window_silent(): no such timestamp, so the scene only processes every item's pending audio actions and reports no audio; - obs_scene_audio_window_frames(): skip a pending source, one with no timestamp and one starting on frame AUDIO_OUTPUT_FRAMES or later; otherwise pos = ns_to_audio_frames(rate, source_ts - timestamp), the same uint64_t arithmetic, and count = AUDIO_OUTPUT_FRAMES - pos; - obs_scene_audio_window_mixes(): skip a hidden item with no volume buffer and no hide transition; - obs_scene_audio_window_adds(): skip adding duplicated audio. obs-scene.c.h keeps audio_lock, apply_scene_item_volume() and process_all_audio_actions() (it passes the volume result), obs_source_audio_pending(), obs_source_get_audio_timestamp(), obs_source_get_audio_mix() and the two mix loops, and reads every item and source field itself. Why several calls and not one plan per item: the C reads between its decisions. apply_scene_item_volume() runs before the pending check, obs_source_get_audio_timestamp() only for a source that is not pending, item->visible and the hide transition only after the window and only without a volume buffer, and audio_is_duplicated only after obs_source_get_audio_mix(). One plan would have to read them all up front. So each decision is made where the C made it, and the scene asks each value only where the old short circuits asked it, passing false or 0 for one they did not; no decision looks at those. The read order and count of every field are unchanged: item->visible is still read a second time when the show transition is not picked, as the old else-if did. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2178 * test: Characterize the scene audio render window decisions test_scene_audio_window_steps compiles libobs/obs-scene-audio-window.c.h (ASan and UBSan) and calls only its hidden functions, so it runs on every platform. 14 cases: - the source read for all 8 combinations of visibility and running show and hide transitions (a show transition of a hidden item and a hide transition of a visible one are not read); the enum values and size; AUDIO_OUTPUT_FRAMES is 1024; - which items count for the tick's timestamp, all 8 combinations of pending, visible and hiding; - the earliest timestamp over item sets: none, one (visible, hiding, hidden, pending, no timestamp), three in all 6 orders, zeros around a timestamp, no timestamps, all pending, pending and hidden items left out of the minimum, equal timestamps, 1 and UINT64_MAX; the fold step on its own; no audio exactly when the earliest is 0; - the item window at pos AUDIO_OUTPUT_FRAMES - 1, at it and + 1, on the first and last ns of each frame, at 48 kHz and 44.1 kHz, and at the frame 1023/1024 edges of 8, 16, 22.05, 32, 88.2, 96, 192 and 384 kHz; - the skips: pending (whatever the timestamp), no timestamp, from frame 1024 on, a hidden item with no volume buffer and no hide transition (all 8 combinations), duplicated audio; - a timestamp before the minimum (an item left out of it): the uint64_t subtraction wraps to a frame far past the tick and the item is skipped, at every rate; across the end of uint64_t it wraps back into the tick and is mixed (characterized, not endorsed); - the uint64_t edges at both ends, rate 0 (every item on frame 0) and rate 1 (characterized, not endorsed); and, where util_mul_div64() is the wrapping formula (everywhere but MSVC x64, where it faults instead), rates of 2^62, 2^63 and SIZE_MAX, where the frame wraps (2 s at 2^63 Hz is frame 0). It is in the native test graph in name order, with libm except on MSVC, in the core suite, so no pinned count changes. It reports failures with fprintf(stderr, ...) and fail(), not fail_msg(), and uses no assert_in_range. It passes 14/14 on the C backend. The real-libobs scene audio tests are unchanged. Refs obs-rust#2178 * obs-scene: Add the scene audio render window tests Failing tests for the port of libobs/obs-scene-audio-window.c.h to a new audio_window module of rust/obs-scene. The safe core is a stub (todo!()), one function per hidden C function: pick() giving a Child (Source, Show, Hide); counts(), earliest() and silent(); frames() giving an Option<Frames> (pos and count); mixes() and adds(); plus ns_to_audio_frames(), the frame of a distance as the C computes it on the target, and min_timestamp(), earliest() folded over a scene. The plan sketched one item_window() returning Skip or Mix; it is three steps (frames(), mixes(), adds()) because the C reads between them: the item's visibility only once the window is known and only without a volume buffer, and audio_is_duplicated only after obs_source_get_audio_mix(). tests/scene/audio_window.rs ports test_scene_audio_window_steps 1:1: its 14 cases under the same names (steps_*), in the same order, with the same inputs and expectations, the characterized-not-endorsed cases included, and the wrapping-rate cases only where util_mul_div64() wraps (not MSVC x64), as the C test does. Edge cases (edge_*): the values the C does not ask for left unread; the first ns of every frame from 0 to 1025 and the ns before it at the ten rates OBS offers; small frames and the u64 ends; the minimum over small sets; and four proptests (4000 cases each): the frame against exact 128-bit math at the real rates for any u64 distance, against the C's wrapping formula for any rate (saturating on MSVC x64), the window against its rule over full-range timestamps and rates, and the minimum against a model in any order. The tests are a module of obs-tests-core (rust/obs-data/tests/core.rs), as the other obs-scene units' are. soldr cargo test -p obs-data --test obs-tests-core scene::audio_window fails 21 of 22 with "not yet implemented"; steps_child_values, which calls no stub, passes. Refs obs-rust#2178 * obs-scene: Port the scene audio render window decisions Ports libobs/obs-scene-audio-window.c.h, the audio window decisions of scene_audio_render(), to the audio_window module of rust/obs-scene. scene_audio_render() stays C in obs-scene.c.h: audio_lock, apply_scene_item_volume() and process_all_audio_actions() (it passes the volume result), obs_source_audio_pending(), obs_source_get_audio_timestamp(), obs_source_get_audio_mix(), the two mix loops and every item and source field read, each in its old order and count. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/audio_window.rs), one function per hidden C function: - pick(): Show when visible and the show transition is active, Hide when hidden and the hide transition is active, else Source; - counts(): not pending, and visible or hiding; earliest(): the non-zero source_ts below the earliest so far, or the first one; min_timestamp(): earliest() folded from 0; silent(): the earliest is 0; - frames(): None when pending, with no timestamp, or from frame 1024 on; else pos and AUDIO_OUTPUT_FRAMES - pos, pos being ns_to_audio_frames(rate, source_ts - timestamp) with the subtraction wrapping as the C's uint64_t; - mixes(): a volume buffer, visible, or hiding; adds(): not duplicated. ns_to_audio_frames() is audio_actions' util_mul_div64(), now pub(crate): the wrapping uint64_t formula, and exact 128-bit math on MSVC x64, where the C faults on a frame that does not fit (a rate above 1 GHz) and the core saturates (the item is skipped). The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented and unreachable lints, allocates nothing, keeps no state and takes no lock. Shim (src/ffi/scene_audio_window.rs): the seven functions with the C signatures. The child crosses as the C's enum value, the window as struct obs_scene_audio_window by value (mix false with pos and count 0 when skipped), size_t as usize (the rate goes to the core's u64 by try_from, saturating, which never happens on a 64-bit size_t). No scene, item or source pointer crosses. C side: the file leaves libobs.core-source for its own group, libobs.ported-scene-audio-window (LIBOBS_PORTED_SOURCES), whose PCH has only media-io/audio-io.h and obs-scene-audio-window.h; libobs.pch.h keeps the header for obs-scene.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. ci/test_ported_sources.py checks the group on every host. The exported symbol sets are unchanged and equal (1766 on the C backend, the hybrid and libobs-c-reference); the seven are local in all three. test_scene_audio_window_steps still compiles the C file into itself, unchanged. The new test_scene_audio_window_steps_rust builds the same test source against libobs_rust-static alone (the test includes only the header and media-io/audio-io.h, so it needs neither SIMDe nor libobs's include directories), with libm except on MSVC. It passes 14/14 against the shims. The real-libobs scene audio tests see the swap through the hybrid. Tier 1 scene::audio_window passes 22/22. Refs obs-rust#2178 * obs-scene: Check the scene audio render window port against the C Oracle (oracle/scene_audio_window.c): the original obs-scene-audio-window.c.h, unmodified, with its seven functions renamed to oracle_*, plus the size and values of enum obs_scene_audio_window_child, the size, alignment and offsets of struct obs_scene_audio_window and AUDIO_OUTPUT_FRAMES (10 values). ns_to_audio_frames() and util_mul_div64() stay the header inlines. Tier 3 (tests/scene/audio_window_parity.rs, 8 tests), each result compared as the C has it (bools, the child's int, the u64, the window's mix, pos and count): - the layout against the C header; - exhaustive over the flags: the pick, the count and the mix over all 8 combinations of their three flags, and both duplicated values; - the fold step over every pair of 22 special timestamps, and silent(); - the window over the pending flag, 8 ticks (0, 1, 1e9, the test tick, the middle and the top end of u64), and per tick and rate 11 source timestamps plus both sides of the first ns of frames 1022 to 1025 in both directions, at 24 rates (the 10 OBS offers, 0, 1, 7, 11025, 999999999 and, not on MSVC x64, 1 GHz up to usize::MAX); - the first ns of every frame from 0 to 1025, and the ns before, at the 10 rates OBS offers; - proptests (20,000 cases each): the window over full-range u64 timestamps (and near 0, the tick and u64::MAX) and rates (the real ones, 8000 to 384000, below 1e9, and any usize off MSVC x64); the fold and silent(); and scene_audio_render()'s decisions in its order for random scenes of up to 8 items, one copy on each side, each side asking only the values the C asks. Tier 1 and Tier 3 passed 5 runs in a row (30/30). Mutation check (done once, not committed): 34 mutants, 25 in the core and 9 in the shim, failures per mutant (Tier 1 has 22 tests, Tier 3 8). | Mutant | Tier 1 | Tier 3 | |---|---|---| | pick: show transition of a hidden item read | 2 | 1 | | pick: hide transition of a visible item read | 2 | 1 | | pick: Show and Hide swapped | 1 | 2 | | counts: pending ignored | 3 | 1 | | counts: hiding ignored | 2 | 2 | | earliest: 0 counts as a timestamp | 4 | 3 | | earliest: first timestamp not taken | 4 | 3 | | earliest: latest kept | 4 | 3 | | silent: inverted | 2 | 3 | | frames: pending mixed | 3 | 2 | | frames: no timestamp mixed | 0 | 3 | | frames: frame 1024 mixed | 6 | 3 | | frames: frame 1023 skipped | 7 | 2 | | frames: saturating subtraction | 2 | 4 | | frames: subtraction reversed | 7 | 4 | | frames: count is the whole tick | 7 | 4 | | frames: count one short | 7 | 4 | | frame: exact 128-bit math (no wrap) | 3 | 1 | | frame: rounded up | 9 | 4 | | frame: divided by 1e9 + 1 | 7 | 2 | | mixes: volume buffer ignored | 2 | 2 | | mixes: hiding ignored | 1 | 2 | | adds: duplicated added | 1 | 2 | | shim: Show and Hide values swapped | 0 | 2 | | shim: pick flags swapped | 0 | 2 | | shim: counts pending and visible swapped | 0 | 2 | | shim: frames timestamps swapped | 0 | 4 | | shim: a skipped window has pos 1 | 0 | 4 | | shim: rate through u32 | 0 | 1 | | shim: adds inverted | 0 | 2 | | equivalent: pick tests hide first | 0 | 0 | | equivalent: earliest `<=` for `<` | 0 | 0 | | equivalent: shim earliest arguments swapped | 0 | 0 | | equivalent: shim mixes buffer and visible swapped | 0 | 0 | 30 are killed by Tier 3. The four that survive are equivalent: the pick's two tests exclude each other (visible against hidden); an equal timestamp keeps the same value; earliest() is symmetric (the smaller non-zero one); and the mix rule is an OR. Tier 1 does not reach the shims; test_scene_audio_window_steps_rust and Tier 3 do. "no timestamp mixed" passes Tier 1 because a timestamp of 0 below any tick wraps past the tick anyway; Tier 3 gives it ticks near 0. The proptest regression files keep the seeds the mutants failed on. Refs obs-rust#2178 * docs: Record the scene audio render window port The rust/README.md crate table now lists libobs/obs-scene-audio-window.c.h among the rust/obs-scene units, and its port table has a row for it, next to the audio actions: the seven functions, what stays C (audio_lock, the volume buffer and the audio actions, every obs_source_* call, the mix loops and every field read, in the old order and count), why several calls and not one plan per item, how values cross, what the characterization pins and the port keeps, the one intentional difference (MSVC x64 rates above 1 GHz), the _rust variant of the steps test, the real-libobs tests that see the swap and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to rust/obs-scene. No docs/features.md line: no user-visible change. port_comparison gets its own bench file, benches/port_comparison/scene_audio_window.rs, in the sorted modules! list: one audio tick of a 16-item scene at 48 kHz, both loops of scene_audio_render()'s decisions in its order, folded into a checksum both sides must match (checked before timing). It allocates nothing, so the leak check of obs-rust#2159 holds. On x86_64 Linux (GCC, pinned to one core, load average near 40, so noisy; medians, two runs): 185 / 332 ns Rust against 215 / 508 ns C per scene tick, well under a microsecond per 1024-frame tick. Fixes obs-rust#2178
MCPVOT
pushed a commit
to MCPVOT/obs-studio
that referenced
this pull request
Oct 25, 2026
* libobs: Move the scene item transform steps Behaviour-neutral extraction before the Rust port. The composition of compute_item_transform() in obs-scene.c.h moves to libobs/obs-scene-item-transform.c.h, as four steps on plain values declared in the new libobs/obs-scene-item-transform.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_scene_item_transform_prepare(): the bounds crop reset, a nested scene's crop rescaled by its size change (update_nested_scene_crop(), moved verbatim: the guard on both last sizes, (float)width / (float)last_width, obs_scene_scale_crop()), the cropped size (obs_scene_cropped_size(), as calc_cx() and calc_cy() take it) and the last size; - obs_scene_item_transform_bounded(): bounds_type != OBS_BOUNDS_NONE; - obs_scene_item_transform_matrix(): draw_transform and box_transform, the same matrix4_identity(), matrix4_scale3f(), matrix4_translate3f(), matrix4_rotate_aa4f(RAD(rot)) and matrix4_translate3f() in the same order; - obs_scene_item_transform_box_scale(): scale.x *= (float)width, in float, for an item without bounds. obs-scene.c.h keeps everything that reads or casts, between the steps: - every get_scene_dimensions() read where it was: item_canvas_scale() and pos_to_absolute() after prepare, size_to_absolute() in calculate_bounds_data(), and size_to_absolute() again for the box scale, after the draw matrix. A concurrent obs_reset_video() sees the same reads as before; - calculate_bounds_data(): the bounds read, then the ported obs_bounds_place(); - add_alignment() and all six float-to-integer casts: the two (uint32_t)((float)cx * scale.x) of an item without bounds and the four (int) passed to add_alignment(). A negative float cast to uint32_t (a flipped item, R7-3) wraps on x86-64 and saturates on arm64, so the casts stay where they were and each architecture keeps its result; - the DEBUG_TRANSFORM logging; update_item_transform() (the defer check, the source size read, the parent's video lock, the signal). calc_cx() and calc_cy() stay for render_item(). 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-scene*.c.h to rust/obs-scene. The exported symbol sets are unchanged (1766 on the C backend, the hybrid and libobs-c-reference). Checked in a scratch harness (not committed) that compiles origin/master's compute_item_transform() and its helpers verbatim next to this branch's and the moved file, on a stand-in item: a script rewrites every item field dereference into a logging accessor and get_scene_dimensions() into a stub that hands out a fresh value from a seeded stream on every read (so a hoisted or merged read shows), and --wrap logs every call out of the composition with its arguments and results as bits (matrix4_scale(), matrix4_translate3v(), matrix4_rotate_aa(), add_alignment(), obs_bounds_place(), obs_scene_cropped_size(), obs_scene_scale_crop() and the three coordinate conversions), with the set of item fields dereferenced between two calls. Random items: crops, sizes and last sizes at the int and uint32_t ends and anywhere, any float bits or item-sized values for the position, scale, rotation and bounds, every bounds type, any alignment, all flags, garbage in the outputs. 150,000,000 random items (50,000,000 each with GCC and Clang at -O2, 20,000,000 each at -O0, and 5,000,000 each under ASan and UBSan, GCC -O0 and Clang -O2): all 6,060,775,041 events match, as do the final item states. Two normalizations: the moved prepare reads last_width even when last_height is 0 (the old short-circuit did not), and item->rot is passed to the matrix step, so it is read before matrix4_scale() rather than just before matrix4_rotate_aa(); the matrix calls in between do not touch the item. 15 deliberately broken moves were tried; 14 fail the harness: the guard on last_width dropped, the x factor from the height, the bounds crop not reset, the last size set before the nested crop, the nested flag ignored, bounded for STRETCH only, the box scale in double or by the height, RAD() in double, the rotation before the origin, the box scale read hoisted above the draw matrix, a saturating cast (as Rust's as), the base origin from the cast size, the box scale from the cast size. The one that passes is equivalent: bounded as bounds_type > OBS_BOUNDS_NONE. Refs obs-rust#2385 * test: Characterize the scene item transform steps test_scene_item_transform_steps compiles libobs/obs-scene-item-transform.c.h into itself (ASan and UBSan), with the hidden crop, coordinate and bounds files it is composed with (obs-scene-crop.c.h, obs-scene-coords.c.h, obs-scene-bounds.c.h, obs-scene-bounds-place.c.h); matrix4_* come from libobs. It calls the four steps directly, and through compose(), which runs them in compute_item_transform()'s order with what obs-scene.c keeps between them: the canvas size (given), the coordinate conversions, obs_bounds_place(), add_alignment() and the casts. 13 cases pin: - the struct layout, the bounds type and alignment values and RAD(1); - prepare: the bounds crop zeroed from any value; the cropped size with no crop, a crop on each side, all of it (0), more (2), a negative sum (2) and two INT_MAX crops of UINT32_MAX (64-bit sum); the last size; a crop kept when not nested; - the nested crop: kept with last_width 0 and with last_height 0; doubled, the same size, two thirds (truncated toward 0), a factor per axis, to 0 x 0; a huge factor (INT_MAX) and a negative crop scaled negative (characterized, not endorsed); sizes past 2^24 rounding to the same float; - bounded: false for NONE only; 7, -1, INT_MAX and INT_MIN are bounded (characterized, not endorsed: obs-rust#2281 makes them NONE before this runs, test_scene_bounds_type_range pins that); - the box scale as float bits: one rounding, sizes past 2^24, signed zeros, infinities and a NaN payload; - the matrix at rotation 0 and -0 bit for bit (identity, scaled, flipped); RAD() of 0, 90, 45, -30, 720, 180, 360 and -90; the matrix against the same matrix4 calls in the C's order, and unequal to the rotation done before the origin; - the composition for every alignment (9 values and two with extra bits), each scale sign combination with each alignment, each bounds type with crop to bounds off and on, upright and flipped, relative coordinates on two canvases and a group's child, and the nested scene crop: last_width 0, a size change, no update_tex, not a scene, and the bounds crop reset between two compositions; - a hash of every output over all alignments x bounds types x crop x absolute/relative x scale signs (1232 compositions), at 0 and -0. Flipped items without bounds are pinned through x86-64's float-to-uint32_t cast, done in defined C ((uint32_t)(int64_t)f), so the pins are the same on every architecture; obs-scene.c keeps the cast itself (on arm64 such an item sits elsewhere, R7-3). Only sinf() and cosf() are library calls, exact at 0: the bits of rotated matrices and the sweeps at 90, 45, -30 and 720 are pinned only with glibc on x86-64, where they were taken. It is in the native test graph in name order, with libm except on MSVC and the headers it reads as watch_inputs, in the core suite (no suite size is pinned). It reports failures with fprintf(stderr, ...) and fail(), not fail_msg(), and uses no assert_in_range. It passes 13/13 on the C backend, and on the hybrid and libobs-c-reference (where matrix4_* is the Rust graphics port). The real-libobs scene, group, bounds, crop and clipboard tests are unchanged. Refs obs-rust#2385 * obs-scene: Test the item_transform port Failing tests for the port of libobs/obs-scene-item-transform.c.h to a new item_transform module of rust/obs-scene. The safe core is a stub (todo!()), one function per hidden C function: prepare() giving a Prepared (the crop, the zeroed bounds crop, the last size and the cropped size), bounded() on the C's int, matrix() giving an obs-graphics Matrix4, and box_scale(); RAD is the C's float constant. The plan sketched one draw() and one box() matrix; the C makes both with the same five calls, so there is one matrix(), called twice, as obs-scene.c.h calls obs_scene_item_transform_matrix() twice. tests/scene/item_transform.rs ports test_scene_item_transform_steps 1:1: its 13 cases under the same names (steps_*), in the same order, with the same inputs and pins. compose() runs the steps in compute_item_transform()'s order with the ported coordinate, bounds placement and alignment functions between them, and x86-64's cast through i64, as the C test does; the glibc x86-64 pins are under the same cfg. Edge cases (edge_*): the guard with each last size 0 or not, nested or not; the bounds crop zeroed in every case; the box scale's signed zeros, NaN and overflow; the rotation-0 matrix lanes; and four proptests (4000 cases each): prepare() against a model of update_nested_scene_crop() and calc_cx()/calc_cy() over any crops and sizes, matrix() against the same Matrix4 calls in the C's order over item-sized floats, box_scale() as one f32 multiply over any bits, and bounded() over any i32. The tests are a module of obs-tests-core (rust/obs-data/tests/core.rs), as the other obs-scene units' are. soldr cargo test -p obs-data --test obs-tests-core scene::item_transform fails 20 of 21 with "not yet implemented"; steps_layout, which calls no stub, passes. Refs obs-rust#2385 * obs-scene: Port the scene item transform steps Ports libobs/obs-scene-item-transform.c.h, the composition of compute_item_transform(), to the item_transform module of rust/obs-scene. compute_item_transform() stays C in obs-scene.c.h: every get_scene_dimensions() read where it was (none hoisted), calculate_bounds_data() and the ported obs_bounds_place(), add_alignment(), all six float-to-integer casts, the DEBUG_TRANSFORM log and update_item_transform() (the defer check, the source size read, the parent's video lock, the signal). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/item_transform.rs), one function per hidden C function: - prepare(): the bounds crop zeroed; when nested and neither last size is 0, each crop times (width as f32) / (last_width as f32) through crop::scale_crop(); the cropped size through crop::cropped_size() with the zeroed bounds crop; the last size set to the source size; - bounded(): bounds_type != 0 (OBS_BOUNDS_NONE), on the C's int; - matrix(): the identity, scaled by (x, y, 1), translated by minus the origin, rotated by rot * RAD about (0, 0, 1), translated by the position, each a post-multiply as matrix4_mul(dst, m, &temp) does; - box_scale(): scale * (size as f32), one f32 multiply per axis. The matrices are bit-equal to the C's: matrix4_mul and vec4_dot are group_transform's (the SSE sum order, as obs-graphics' and the hybrid libobs's matrix4_*), now pub(crate), and quat_from_axisang() and matrix4_from_quat() are written out in item_transform with the C's operations in their order (halfa = w * 0.5, each axis lane times the sine, the norm as quat_dot, 2 / norm, 1 - (yy + zz), ...). The plan was to call obs-graphics' Matrix4 directly; that put obs-graphics' texture render code, with its gs_* references, into the obs-scene member, and test_scene_audio_window_steps_rust and test_scene_render_plan_steps_rust, which link libobs_rust-static alone, stopped linking. group_transform and extent write their math out for the same reason. sinf() and cosf() go through a new platform::sin_cos, as obs-graphics calls them on each host (separate non-inlined calls on macOS, where LLVM would pair them into __sincosf_stret). There is no f64 intermediate and Rust never fuses a multiply and an add, so this holds on x86-64, arm64 and the MSVC targets. No float becomes an integer anywhere in the module. It denies clippy's arithmetic, indexing, unwrap, expect, panic, unimplemented and unreachable lints, allocates nothing, keeps no state and takes no lock. Shim (src/ffi/scene_item_transform.rs): the four functions with the C signatures. The crops cross as struct obs_sceneitem_crop (bounds_place's SceneItemCrop), the size as struct obs_scene_item_transform_size by value, the matrix and vectors as obs-graphics' matrix4 and vec2. Each shim reads all its inputs before it writes. C side: the file leaves libobs.core-source for its own group, libobs.ported-scene-item-transform (LIBOBS_PORTED_SOURCES), whose PCH has only string.h, obs.h, the graphics headers it uses, obs-scene-crop.h and obs-scene-item-transform.h; libobs.pch.h keeps the header for obs-scene.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. ci/test_ported_sources.py checks the group on every host. The exported symbol sets are unchanged and equal (1766 on the C backend, the hybrid and libobs-c-reference); the four are local in all three, and the group's object is built only for libobs-c-reference in the hybrid tree. test_scene_item_transform_steps still compiles the C file into itself, unchanged. The new test_scene_item_transform_steps_rust builds the same test source against OBS::libobs (for matrix4_*) and libobs_rust-static (the four shims and the hidden crop, coordinate, bounds and alignment shims), with libm except on MSVC. It passes 13/13 against the shims on the hybrid and on libobs-c-reference. The real-libobs scene, group, bounds, crop and clipboard tests see the swap through the hybrid. Tier 1 scene::item_transform passes 21/21. Refs obs-rust#2385 * obs-scene: Check item_transform against the C Oracle (oracle/scene_item_transform.c): the original obs-scene-item-transform.c.h, unmodified, with its four functions renamed to oracle_*; its matrix4_*, quat and axisang calls resolve to the graphics oracle (graphics_math_names.h) and its crop calls to the crop oracle, so the C side is all C. It also reports the size, alignment and offsets of struct obs_scene_item_transform_size, OBS_BOUNDS_NONE and the enum's size (6 values). Tier 3 (tests/scene/item_transform_parity.rs, 9 tests), every float by its bits (a NaN by its payload and sign, -0 apart from +0): - the layout against the C header; - exhaustive over the flags: prepare() over nested and 13 last widths x 4 last heights (0 and not), 8 special crops and 5 sizes; bounded() over -2..=8 and the int ends; - the matrix over 16 special values (signed zeros, the float ends, a subnormal, infinities, NaNs) in every pair, at 10 rotations (0, -0, 90, 45, -30, 720, 180, 1e30, NaN, inf); the box scale over 9 special values in every pair and 4 sizes; - proptests (20,000 cases each): prepare() over any crops and sizes; the matrix over finite floats (any finite bit pattern, item-sized values and the usual ones) for every input; the box scale over any bits; and (2,000 cases, 448 compositions each) compute_item_transform()'s sequence with the shims on one side and the oracle on the other, exhaustive over the six flags (absolute, update_tex, nested scene, group, parent group, crop to bounds) and the seven bounds types, over random items, alignments, bounds alignments, sizes and four canvases. Both sides get the same glue (the ported coordinate, bounds placement and alignment functions, x86-64's cast in i64), so only the four steps differ. Tier 1 and Tier 3 pass (21/21 and 9/9); Tier 3 takes 5 s. Mutation check (done once, not committed): 37 mutants, 31 in the core (three in the written-out rotation, one in group_transform's dot) and 6 in the shim; failures per mutant (Tier 1 has 21 tests, Tier 3 9). | Mutant | Tier 1 | Tier 3 | |---|---|---| | prepare: bounds crop kept from the crop | 3 | 3 | | nested: guard drops last_width | 3 | 3 | | nested: guard needs both 0 | 3 | 3 | | prepare: nested flag ignored | 4 | 3 | | prepare: never nested | 4 | 3 | | nested: x factor from the height | 2 | 3 | | nested: factor inverted | 4 | 3 | | nested: factor in f64 | 1 | 2 | | prepare: last size kept | 6 | 3 | | prepare: cx from top and bottom | 5 | 3 | | bounded: > 0 | 2 | 1 | | bounded: always | 7 | 2 | | matrix: z scale 0 | 5 | 3 | | matrix: origin added | 9 | 3 | | matrix: rotation before the origin | 3 | 3 | | matrix: pre-multiplied position | 9 | 3 | | rad: in f64 | 1 | 2 | | axis: no half angle | 3 | 3 | | axis: sine and cosine swapped | 9 | 3 | | axis: sin_cos paired in f64 | 1 | 2 | | axis: 2 / norm skipped | 3 | 3 | | axis: 1 - yy - zz | 0 | 0 | | axis: 0 axis lanes not multiplied | 0 | 0 | | axis: rotation transposed | 3 | 3 | | translation: w 0 | 9 | 3 | | dot: x + y + z + w | 0 | 1 | | box scale: height on x | 8 | 3 | | box scale: in f64 | 0 | 0 | | shim: bounds crop not written | 0 | 3 | | shim: last sizes swapped | 0 | 3 | | shim: cx and cy swapped | 0 | 3 | | shim: origin and position swapped | 0 | 3 | | shim: box scale size swapped | 0 | 3 | | shim: bounded inverted | 0 | 2 | | equivalent: guard order swapped | 0 | 0 | | equivalent: bounded through BoundsType | 0 | 0 | | equivalent: y factor computed first | 0 | 0 | 31 are killed, all by Tier 3. The six that survive are equivalent: the guard's two tests in either order; any non-zero int is a BoundsType other than None; the two factors are independent; (1 - yy) - zz is 1 - (yy + zz) when yy is +0, as it is for the z axis, the only one the scene rotates about; a zero axis lane's sign reaches only lanes the next multiply adds to +0; and an f32 product computed in f64 and rounded once is the f32 product (the size is already a float). Tier 1 does not reach the shims; test_scene_item_transform_steps_rust and Tier 3 do. The proptest regression files keep the seeds the mutants failed on. Refs obs-rust#2385 * docs: Record the scene item transform port The rust/README.md crate table now lists libobs/obs-scene-item-transform.c.h among the rust/obs-scene units, and its port table has a row for it, after the item names: the four steps, what stays C (every get_scene_dimensions() read where it was, calculate_bounds_data(), add_alignment(), the six float-to-integer casts and why, update_item_transform()), how values cross, why the matrix math is written out in the crate and not called from obs-graphics (the _rust tests that link the staticlib alone), what the characterization pins and the port keeps, the _rust variant of the steps test, the real-libobs tests that see the swap and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-scene*.c.h to rust/obs-scene. No docs/features.md line: no user-visible change. port_comparison gets its own bench file, benches/port_comparison/scene_item_transform.rs, in the sorted modules! list: one transform update of 16 items (half of them bounded, rotations from 0 to 337.5 degrees), each running prepare, the bounds test, both matrices and the box scale as compute_item_transform() does, folded into a checksum both sides must match (checked before timing). It allocates nothing, so the leak check of obs-rust#2159 holds. On x86_64 Linux (GCC, pinned to one core; medians of two runs): 2.1 us Rust against 3.3 us C per 16-item update. Fixes obs-rust#2385
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 #2154
What and why
A full
soldr cargo bench -p obs-c-oracle --bench port_comparisonrun panicked at util'sbmem/countfixture (16 vs 0). That pair compares obs-util'sbnum_allocs()with the C bmem oracle's own counter, so it fails whenever an earlier module allocates through the sharedbmallocand doesn't free it.source_profilerbench (obs-core: Port util/source-profiler.c #1887) made its 16 C sources withoracle_sp_source_new()and left them live ("the sources are leaked"). That function is abzallocthrough obs-util's allocator, so these were the 16 Rust-side allocations.service 'bench_live'"Failed to create" line logged before the panic is expected. The bench'screate()stub returns NULL on purpose, asservice.rssays. That service is created, released and destroyed, and leaves both counters where they were.comparisons()now runs each module throughmodule(). It checks that both counters end where they started, so a leak names its module instead of failing a later fixture. The module list becomes a sortedmodules![...]list, one entry per line, andci/test_sorted_shared_lists.pyreads it from there.source_profilerbench now frees its sources withoracle_sp_source_free()after its closingoracle_sp_reset().utilitself ended at Rust -4 / C +4.oracle/dstr_libc.chas takenos_utf8_to_wcs_ptrandos_mbs_to_utf8_ptrfromoracle/platform.c, which allocates withoracle_bmalloc. Butdstr-libc.cfrees the wide string withbfreeand keeps the UTF-8 string as a dstr's array, and both of those use obs-util's allocator.oracle_dstr_to_upper/to_lowerfreed anoracle_bmallocblock with the other allocator'sbfree. It worked only because the two allocators happen to be compatible. The same applies tooracle_dstr_from_mbs,to_mbsandto_wcsin the obs-util string tests.oracle/dstr_libc.cnow defines those two helpers as theirutil/platform-conversions.c.hbodies aroundoracle/platform.c's conversions, allocating withbmalloc. The conversion code compared is still the C code.pair()'s fixture assertion andbmem/countare unchanged: both still compare absolute counts.RED → GREEN
soldr cargo bench -p obs-c-oracle --bench port_comparison -- --testpanics withsource_profiler benches leave (bmalloc, oracle_bmalloc) allocations live, left(16, 0), right(0, 0). On master (af31b65) the same run panics atbenchmark fixture differs: bmem/count, left 16, right 0.util benches leave ... live, left(-4, 4). b2590b8 fixes the dstr-libc allocator. On b2590b8, the full--testrun passes all 354 benchmarks. A short real full run (-- --warm-up-time 0.1 --measurement-time 0.2) also completes all 354.soldr cargo test -p obs-c-oracle --locked --bench port_comparison(criterion test mode, dev profile) passes 354 as well. (Those runs were on the same commits before the rebase over obs-output: Port the encoder size and info choices #2148; after the rebase, which merged obs-output: Port the encoder size and info choices #2148'sencoder_sizebench into the sorted module list,soldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses all 360 on b2590b8.)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 MSVCLocal gate:
--test-diff origin/master(3111 passed, 4 skipped by the nextest profile, including the obs-utildstr_conversionsanddstr_libcparity tests),--lane lintand--lane crossall passed on the same three commits before a rebase onto bd83035. That rebase touched none of these files. On the rebased head, the full--testrun andci/test_sorted_shared_lists.pywere run again and passed.No CI lane runs this bench today:
clippy --all-targetsonly type-checks it.soldr cargo test -p obs-c-oracle --locked --bench port_comparisonreuses the dev-profile build of the Rust test job and took about 11 s on a warm tree. It could followcargo test --workspacein the Linux Rust job or in local_gate's rust-test lane. That change is left for a separate decision.