Repository navigation
obs-callback: Port signal.c to Rust - #1642
Merged
Merged
Conversation
Mirror test/cmocka/test_signal.c, as fixed by obs-rust#1556 and obs-rust#1639, against todo stubs in obs-callback. Add: global connect and disconnect matched by callback and data, a connect of many callbacks then remove_current from the running callback, a global signal in a nested pass, and a disconnect from another thread that waits for the running pass. From obs-rust#1639: a global callback that connects more global callbacks then removes itself, a nested pass that must not erase an earlier removed global callback, and a global disconnect during the pass. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The safe core follows signal.c.h as fixed by obs-rust#1556 and obs-rust#1639: per-signal and global re-entrant locks held while callbacks run, deferred removal while signalling, keep_ref references, and the thread-local running callback. The running callback is a (signal, index) pair instead of a pointer into the callback array, so a connect from the callback cannot leave it dangling. As in the fixed C: - Passes of one signal nest by count, and so do the global passes. Removed callbacks are erased only when the outermost pass ends. A disconnect while a pass runs only marks the callback. The running global callback is an index, as the running signal callback is. - Each callback call saves and restores both running callbacks. A signal callback clears the global one, a global callback clears the signal one. remove_current marks the signal one first. - Global callbacks are found by callback and data only. - A keep_ref reference given back after a pass destroys the handler when it was the last one. signal() reports it to the owner. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ten signal_handler_* exports move into obs-callback. signal_handler_add_array stays inline in signal.h. The handle is one bmalloc block that holds an Arc, as in the audio-controls port, so bnum_allocs sees the handler until its last reference goes (keep_ref_remove_current_last_ref_test reads it). Both are freed when the C reference count reaches zero. signal_handler_signal keeps its own clone while callbacks run and frees the handler after the pass when the pass gave back the last reference. The log texts are the C ones. callback/signal.c moves into the ported group libobs.ported-callback, on its header. The audio-controls oracle defined signal_handler_connect and signal_handler_disconnect as stubs. A test binary that also links obs-callback, such as obs-tests-core, would define them twice (GNU ld stops). Rename the stubs to oracle_audio_controls_* with #define, as the oracle already does for its own exports. Tier 3 runs the original signal.c.h, as fixed by obs-rust#1639, on the decl oracle (oracle/signal.c). Random scripts of add, connect, connect_ref, disconnect, connect_global, disconnect_global and signal run with re-entrant actions. Signal callbacks remove the current one, disconnect or connect another, connect then remove, or start a nested signal. Global callbacks remove the current one, disconnect themselves, connect or disconnect another global callback, connect then remove, or start a nested signal. The test compares every callback call in order and every logged line. Excluded: a destroy from a callback (C frees the handler under the running pass). Against the core without the obs-rust#1639 rule, Tier 3 finds a failing script. Checks on Linux x86_64 (Debian 13), CMake with OBS_BUILD_C_REFERENCE: test_signal.c passes 19/19 against the hybrid libobs and against libobs-c-reference (loader checked). ctest against the hybrid passes 344/344 under xvfb-run, without the xcomposite/xshm tests that do not build on Debian's cmocka. obs-tests-core passes 422/422 with GNU ld. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher
force-pushed
the
rust/1441-signal-port
branch
from
October 21, 2026 19:10
98ea046 to
8a495f6
Compare
zackees
enabled auto-merge
October 21, 2026 19:12
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1441
What and why
Port
libobs/callback/signal.c.htorust/obs-callbackand swap it into the hybridlibobs. The tensignal_handler_*exports move.signal_handler_add_arraystays inline insignal.h.The port follows the C as fixed by #1556 and #1639:
keep_refreference given back after a pass destroys the handler when it was the last one.The C handle is one
bmallocblock that holds anArc<SignalHandler>, as in the audio-controls port.bnum_allocstherefore sees the handler until its last reference goes;keep_ref_remove_current_last_ref_testreads it.signal_handler_signalholds its ownArcclone while callbacks run, so a callback that destroys the handler does not free it under the pass.Intentional differences, all where C dereferences null: a null handler in
signal_handler_addreturns false, a null signal name is not found, and a null callback is stored but not called. They are listed in the shim header and inrust/README.md.The audio-controls oracle defined
signal_handler_connectandsignal_handler_disconnectas stubs. A test binary that also links obs-callback, such as obs-tests-core, would define them twice, and GNU ld stops. The stubs are renamed tooracle_audio_controls_*, as the oracle does for its own exports.While I prepared this port, the Rust core showed the same behavior as the old C for global callbacks in a nested pass and for a global disconnect during the pass. Tier 3 was green because both sides had the bug. #1639 fixes the C, and this port follows it.
Tiers
tests/callback/signal.rs): mirrorstest/cmocka/test_signal.cwith the callback: Fix signal callback removal across nesting, recursion and registration (split from #1464) #1556 and callback: Track the running global signal callback by index #1639 cases, plus edge cases: global connect and disconnect matched by callback and data, a global signal in a nested pass, and a disconnect from another thread that waits for the running pass.test/cmocka/test_signal.cagainst the hybridlibobsand againstlibobs-c-reference.tests/callback/signal_parity.rs): random scripts against the originalsignal.c.hon the decl oracle. Signal and global callbacks connect, disconnect, remove themselves, connect then remove, and start nested signals. The test compares every callback call in order and every logged line. Only a destroy from a callback is excluded (C frees the handler under the running pass).RED → GREEN
Base: master 01561bf (includes #1639).
todo!()stubs): 23 signal tests fail, the 56 other callback tests pass.-D warningsand rustfmt ok.-DOBS_BUILD_C_REFERENCE=ON, on 01561bf:test_signal19/19 against the hybridlibobsand againstlibobs-c-reference(loader checked).xvfb-run, without thexcomposite/xshmtests (the 3test_xcomposite_*targets do not compile with Debian's cmocka; not related). obs-tests-core 422/422 with GNU ld.Checklist
mastersrc/ffi/signal.rs) and rust/README.md; the Tier 3 exclusion in the parity test header