Repository navigation
obs-graphics: Port the libnsgif state machine and public API (#2510) - #2514
Conversation
|
Windows failure (run 40375738347, Rust Tier 2 windows-2025-vs2026): |
zackees
left a comment
There was a problem hiding this comment.
Reviewed:
gif.cmoves into the ported group, and the Windows warning options follow it (that was the earlier test failure).- The exports, hidden and macOS-unexport lists all gain the new symbols, and there's a C oracle copy, parity tests and a bench.
- In
test_nsgif_decode.c, only the header comment and one#endifguard are removed; no assertion is removed, and the file adds 735 lines of new cases. The test's cmake files drop the compiled-inlibobs.nsgif+.h.ccopies, which the Rust exports replace. - No public header is touched.
Auto-merge is on; it goes in once the Fast Gate re-run (after a runner shutdown) is green. #2516 needs a rebase after this lands.
|
Fast Gate has failed twice in a row with "The runner has received a shutdown signal" (exit 143). Both times it happened during |
|
I measured the memory of the new tests in advance, in case the third run fails too. On Linux x86_64 (Debian 13), at 6a417d4, each of the 93 GIF, LZW and
So the nsgif tests do not use enough memory to stop a runner. I did not measure the runner's disk use. In both failed attempts, the tests that nextest reports as SLOW before the shutdown are obs-data parity tests that this PR does not change: |
6a417d4 to
8cbad5f
Compare
|
The merge queue ejected this. Configure failed on every platform with |
|
The Windows Rust Tier 2 failure here (LNK2005 on |
d2f833c to
17f4235
Compare
|
The macOS Rust Tier 2 failure on this run (job 121885792485) is an intermittent crash, not the earlier assertion: The lldb step after it found no crash in 30 runs. I built master's A possible cause, not proven: the group setup calls |
|
Note on the rebase: the |
|
Found the cause of the macOS crash. It is not in this PR, and it is not random. In both runs, the two normal ctest suites pass (339/339 against So in that stage, Fix: I will open an issue and a small PR that makes |
17f4235 to
1479e1e
Compare
|
Windows Rust Tier 2 on the rebased head (run 40422466703) failed on a crash in a test from #2508, not in this PR's code:
So it looks intermittent, maybe in the obs_startup()/obs_shutdown() teardown of that test. I will re-run the Windows job when the run is complete. If it crashes again, the cargo hybrid suite and that test's teardown are the place to look. |
|
The Windows re-run (job 121928441055) crashed again in What the log shows: Proposal: quarantine |
…nsgif.h (#2510) Ten cases for gif.c before its port, on GIFs that a small writer in the test builds (header, screen descriptor, colour tables, graphic control and loop count extensions, images of one colour from the LZW emitter): the error and disposal strings; the nine bitmap formats and their byte orders, and the default black and white table; a whole scan (info, frame info, the default delay of a frame without a graphic control extension, local palettes, a second scan, a scan after nsgif_data_complete); scans in two parts and byte by byte; the screen size quirk with the first frame setting or growing the size; a GIF without frames, a cut one and not a GIF; nsgif_data_complete for a frame cut in its image data (also frame 0, which gets transparency); the frame order of nsgif_frame_prepare with the redraw area, the delay rules, play once, loop forever, data not complete and one frame; the disposal across frames (restore background with and without transparency, restore previous), a restart, a cached frame and a bad frame number; the bitmap callbacks and a row span wider than the image. 39/39 on the C. Kept, characterized, not endorsed: - When a scan stops at the end of the data inside a frame, nsgif_data_scan keeps the position where the frame's parse stopped, not the frame's start. The next scan reads image data or an extension's terminator as the next block: a bad frame from then on, also with all the data. A split inside the image data or on an extension's last byte breaks a scan in parts; OBS scans whole files. - With play once (no loop extension), one more nsgif_frame_prepare after the last frame (infinite delay) shows frame 0 again before NSGIF_ERR_ANIMATION_END. Refs #2510 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The safe core of libobs/graphics/libnsgif/gif.c.h as obs_graphics::gif, with todo!() bodies: Gif<B: Bitmaps> with new, set_frame_delay_behaviour, data_scan, data_complete, reset, frame_prepare, frame_decode, info, frame_info, global_palette and local_palette, and strerror and str_disposal. Info and FrameInfo have the C layout of nsgif_info_t and nsgif_frame_info_t, which the API returns pointers to. Bitmaps is the client's nsgif_bitmap_cb_vt, with default methods for the optional callbacks. Every call that reads the GIF data takes it. gif_blocks' disposal constants get UNSPECIFIED and NONE. Tier 1 (render::gif in obs-tests-graphics): the ten cmocka cases one to one with the same GIF writer, edge cases (dropping a Gif destroys its bitmap; a bitmap that cannot be created is out of memory) and a proptest (random and mutated GIFs, scanned in parts, then random calls: no panic, the frame count never shrinks). RED: 0 of 13 pass. Refs #2510 Co-Authored-By: Claude Opus 5.5 <[email protected]>
GREEN for obs_graphics::gif: the safe core (the frame table and the scan positions of nsgif_data_scan with its frame parse on the gif_blocks parsers, nsgif_data_complete, the frame order, loop count and delay rules of nsgif_frame_prepare, nsgif_frame_decode with the disposal across frames, the saved frame and the bitmap callbacks on the gif_frame decode, the palettes and the strings; the C's uint32_t arithmetic as wrapping operations) and a thin hidden #[no_mangle] shim for the fourteen functions of nsgif.h. nsgif_t is NsgifCtx: the safe Gif plus the buffer of the last scan; Info and FrameInfo have the C layout, as the API returns pointers to them; nsgif_bitmap_cb_vt is BitmapCbVt, which implements the Bitmaps trait over the client's function pointers. gif.c.h, the last C file of libnsgif, moves from libobs.nsgif to the ported group libobs.ported-nsgif-gif (its PCH renamed with it), so the hybrid libobs has no libnsgif C left. The C oracle no longer builds libnsgif as a library: image-file.c.h in the oracle calls the Rust shims, as libobs does, and oracle/gif.c is gif.c.h renamed, calling the C oracles of the other three files, for the parity test. The _rust test executables (test_effect_parser_lifecycle_rust, test_sprite_geometry_steps_rust, test_nsgif_decode_rust) take libnsgif from the staticlib instead of compiling the group. Tier 1: 13/13. Tier 3 (render::gif_parity): the strings, and 3 000 random cases of generated GIFs (one to four frames, every disposal, delays, transparency, rectangles inside and past the screen, interlace, local tables, loop counts, the screen size quirk), mutated or cut, and random bytes; scanned whole or in two to four parts, with or without nsgif_data_complete, in all nine bitmap formats, with or without a row span wider than the image and the optional callbacks; then random prepares, decodes, resets and delay rules. After every call the result, the info, every frame info, both palettes, the prepare outputs, the decoded bitmap and the callback counts match the whole of libnsgif in C. 3/3 with the shim-only null pointer test. test_nsgif_decode_rust runs the thirty-nine cmocka cases against the shims without any libnsgif C. port_comparison (M1 Max, five 1920x1080 frames scanned and decoded through the API, Rust on Rust, C on C, three runs): 49.3 to 50.6 ms, C 53.0 to 54.4 ms. Refs #2510 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Windows Rust build of libobs (rust/obs-build) gave the C group libobs.nsgif /wd4244 /wd4267. #2510 moves gif.c.h to the ported group libobs.ported-nsgif-gif, which is not in that build target (the hybrid takes libnsgif from Rust), and the build refuses options for sources outside its target ("compiler options refer to sources outside this target", native_libobs::windows_tests::core_builds_from_the_canonical_manifest in Rust Tier 2 windows). The other three ported libnsgif groups have no entry either. Refs #2510 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…group #2528 added test_graphics_state_stacks_rust on master with libobs.nsgif+.h.c, which this PR moves into the Rust staticlib; #2537 then gave that file MSVC warning options. Drop the file and its MSVC block. Also drop the two MSVC set_source_files_properties blocks that no longer name a file (test_sprite_geometry_steps_rust, test_effect_parser_lifecycle_rust). Co-Authored-By: Zach Vorhies <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Coordinator tick (2026-10-27). This PR is 1. Rebase conflict: master moved the bench-unit list into
2. Rebase conflict: master now links Master added 3. Windows Tier 2 failure (run 40422466703, The failing test is not one this PR touches, so the first question is whether the ported I did not push a rebase: the branch needs a force-push and this session cannot rewrite a remote branch. The resolution above applies cleanly with |
|
Two corrections to my comment above, after reading the thread properly. The Windows failure is not yours. You already diagnosed it at 00:10 and 00:20: Your own note at 22:46 is still open: the The branch's only README change against master is the loss of three rows that master gained after you branched ( The two rebase resolutions in my comment above stand: take master's generated |
|
Thanks, on it. The rebase onto current master is done locally and the force-push comes shortly, after the local Tier 2 run finishes:
|
1479e1e to
4261f81
Compare
… data Two defects in render::gif_parity::api (#2510), both from random seeds: - A mutated logical screen descriptor can ask the bitmap callback for up to 65535 x 65535 pixels. cb_create allocated and filled that (17 GB), for the C and the Rust decoder. This starved the 16 GB CI runners: all three Fast Gate exit-143 runner losses of this PR (runs 40380261405 attempts 1 and 2, merge queue run 40478704942). With a 6 GB limit, 3 of 10 runs were OOM-killed. cb_create now returns NULL above 4 M pixels (16 MiB), as an out-of-memory host does; both sides get the same callback. - After a scan that stops inside a frame's local colour table, nsgif_local_palette in C decodes the table from past the end of the data (buf_len); the Rust decodes only the bytes in the data. This is an intentional difference (OBS does not call nsgif_local_palette). The views now compare, for frames at or after frame_count, only whether there is a local palette and its size. The shrunk case is kept in proptest-regressions/gif_parity.txt; rust/README.md lists the difference. Verified: the saved case passes; 50 runs (150 000 random cases) pass, maximum resident size 154 MB; obs-tests-graphics 420/420; clippy clean. Refs #2510 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I removed this PR from the merge queue and cancelled queue run 40478704942. Its Fast Gate runner died in the unit tests (exit 143), and the cause is this PR's own test, not GitHub. New head
Verified: 50 runs (150 000 random cases) pass, maximum resident size 154 MB; Separately, the queue stall: the dead job stayed |
…dle (obs-rust#2538) (obs-rust#2540) On macOS, find_libobs_data_file() built the path from [NSBundle bundleWithIdentifier:@"com.obsproject.libobs"]. When libobs is loaded from a libobs.framework with no bundle identifier (no Info.plist), the bundle is nil, the path string is nil and strlen(libobsDataPath.UTF8String) is strlen(NULL): the first obs_find_data_file() call crashed. The macOS Rust Tier 2 stage "Cargo [obs-c-reference] unchanged ctest suite" runs the cmocka tests against such a framework (obs-build makes it without an Info.plist), so test_obs_core_info_characterization (test_find_data_file) crashed there with SIGSEGV. Now the function returns NULL when the bundle or its path is not found, and obs_find_data_file() searches the data paths, as on Linux and Windows. With the bundle present, nothing changes. RED: master's macOS Rust Tier 2 cargo stage (two runs of obs-rust#2514), and locally test_obs_core_info_characterization against a libobs.framework without Info.plist: SIGSEGV in test_find_data_file. GREEN: the same framework 8/8; the CMake libobs-c-reference and hybrid frameworks 7/8 plus the macOS skip, as before (5 runs each). Fixes obs-rust#2538 Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #2510
Slice 2c, the last one of libnsgif: the state machine and the public API of
nsgif.h(libobs/graphics/libnsgif/gif.c.h), ported toobs_graphics::gif. With it, the hybrid libobs has no libnsgif C left: the LZW decoder (#2466), the block parsers (#2488), the frame decode (#2501) and now the state and the API are Rust.What changed
rust/obs-graphics/src/gif.rs(safe core) andsrc/ffi/gif.rs(shim) for the fourteen functions ofnsgif.h.nsgif_tisNsgifCtx: the safeGifplus the buffer of the last scan, which the C keeps too and the decodes read.nsgif_info_tandnsgif_frame_info_tare#[repr(C)]in the state, sincensgif_get_infoandnsgif_get_frame_inforeturn pointers to them.nsgif_bitmap_cb_vtisBitmapCbVt, which implements theBitmapstrait of the core over the client's function pointers. NotEXPORT, so the shims are hidden (rust-hidden.txt,rust-exports.map,rust-unexports-macos.txt).gif.c.hmoves fromlibobs.nsgifto the ported grouplibobs.ported-nsgif-gif(its PCH renamed with it).ci/test_ported_sources.py,rust/README.md,rust/obs-build(Windows warning options of the renamed group).image-file.c.hin the oracle calls the Rust shims, as libobs does, so the cargoimage_filetests run on Rust libnsgif.oracle/gif.cisgif.c.hrenamed, calling the C oracles of the other three files, for the parity test.test_effect_parser_lifecycle_rust,test_sprite_geometry_steps_rustandtest_nsgif_decode_rusttake libnsgif from the staticlib instead of compiling the group.src/platform/(Dylint platform boundary).Kept, characterized, not endorsed
nsgif_data_scankeeps the position where the frame's parse stopped, not the frame's start. The next scan reads the rest of the frame as the next block:NSGIF_ERR_DATA_FRAMEfrom then on, also with all the data. OBS scans whole files, so libobs never gets there. Upstream libnsgif has the same code. A fix with its own issue and PR follows this PR.nsgif_frame_prepareafter the last frame (infinite delay) shows frame 0 again beforeNSGIF_ERR_ANIMATION_END.Intentional differences (C dereferences null; no caller gets there)
nsgif_t, callback table or out-pointer makesnsgif_createreturnNSGIF_ERR_DATA, and the other calls do nothing (or returnNSGIF_ERR_DATA,NULL,false).createorget_buffercallback is a bitmap that cannot be made (NSGIF_ERR_OOM) or has no pixels.RED → GREEN
2b6891848: tengif_*cases intest_nsgif_decodethroughnsgif.h, on GIFs that a small writer in the test builds: the strings; the nine bitmap formats and their byte orders; a whole scan (info, frame info, the default delay, local palettes, a second scan, a scan afternsgif_data_complete); scans in two parts and byte by byte; the screen size quirk; GIFs without frames, a trailer as image data, a minimum code size of 12, not a GIF;nsgif_data_completefor cut frames; the frame order ofnsgif_frame_prepare(redraw area, delay rules, play once, loop forever, data not complete, one frame); the disposal across frames, a restart, a cached frame; the bitmap callbacks and a wider row span. 39/39 on the C.d5891b032: Tier 1render::gif, the ten cases 1:1 with the same writer, plus edge cases and a proptest (random and mutated GIFs, scanned in parts, then random calls: no panic, the frame count never shrinks): 0 of 13 pass (todo!()).3c3475dcb: 13 of 13, and Tier 3render::gif_parityagainst the whole of libnsgif in C: the strings, and 3 000 random cases of generated GIFs (one to four frames, every disposal, delays, transparency, rectangles inside and past the screen, interlace, local tables, loop counts, the screen size quirk), mutated or cut, and random bytes; scanned whole or in two to four parts, with or withoutnsgif_data_complete, in all nine bitmap formats, with or without the optional callbacks and a wider row span; then random prepares, decodes, resets and delay rules. After every call the result, the info, every frame info, both palettes, the prepare outputs, the decoded bitmap and the callback counts match. 3 of 3 with the shim-only null pointer test.Mutation check (done once, not committed): 14 of 16 applied mutants fail Tier 1 or Tier 3; two of them first survived (a trailer as the second byte of the image data, a minimum code size of 12 in the scan), and two cases now cover them in all tiers. The two survivors are equivalent:
>=to>in the restart condition ofnsgif_frame_decode(the equal case returns the cached frame before it) and in the frame bound ofnsgif_local_palette(the scan raises the partial frame count before a local table can be set).port_comparison(M1 Max, five 1920×1080 frames scanned and decoded through the API, Rust on Rust, C on C, three runs): 49.3 to 50.6 ms, C 53.0 to 54.4 ms.Tier 2 (Linux x86_64, Debian 13)
ci/local_gate.py --lane lint) passes.test_nsgif_decode,test_nsgif_decode_rust,test_image_file,test_image_file_version,test_image_file_version_filetime,test_media_gif_last_frame,test_effect_parser_lifecycle,test_effect_parser_lifecycle_rust,test_sprite_geometry_stepsandtest_sprite_geometry_steps_rustpass on the hybrid libobs and onlibobs-c-reference(10/10 each).test_nsgif_decode_rustruns the thirty-nine cmocka cases against the shims without any libnsgif C, with AddressSanitizer and UBSan.Checklist
master🤖 Generated with Claude Code