Repository navigation
Restore a native call's copied first argument on unwind - #1189
Merged
schungx merged 1 commit intoOct 17, 2026
Merged
Conversation
Collaborator
|
Can you split this into two separate PRs just so we can track issues independently? Also some CI's are failing. Thanks for catching these! |
schungx
reviewed
Oct 17, 2026
| * Failed function resolutions are now cached properly for calls with other than two arguments - a regression from version 1.10 (thanks [`@ImTheSquid`](https://github.com/ImTheSquid) [`#1183`](https://github.com/rhaiscript/rhai/pull/1183)). | ||
| * A function resolution cache is now created (if none exists) when entering a block. Previously, a loop body evaluated with no cache yet would resolve every function call again on each iteration (thanks [`@ImTheSquid`](https://github.com/ImTheSquid) [`#1183`](https://github.com/rhaiscript/rhai/pull/1183)). | ||
| * Assigning a constant into a container variable (array, map etc.) now works properly without making the value read-only (thanks [`@cuervolu`](https://github.com/cuervolu) [`#1187`](https://github.com/rhaiscript/rhai/pull/1187)). | ||
| * A panic inside a native Rust function that takes its first argument by value, called with a variable first argument, now unwinds normally and can be caught by `catch_unwind`. Previously the copied first argument was restored only on the normal-return path, so the unwind tripped an internal assertion and the process aborted ([`#1188`](https://github.com/rhaiscript/rhai/issues/1188)). |
Collaborator
There was a problem hiding this comment.
Better to link to this PR (#1189) than to the issue. Also good to add your username (similar style as others) as credit!
schungx
reviewed
Oct 17, 2026
| * A function resolution cache is now created (if none exists) when entering a block. Previously, a loop body evaluated with no cache yet would resolve every function call again on each iteration (thanks [`@ImTheSquid`](https://github.com/ImTheSquid) [`#1183`](https://github.com/rhaiscript/rhai/pull/1183)). | ||
| * Assigning a constant into a container variable (array, map etc.) now works properly without making the value read-only (thanks [`@cuervolu`](https://github.com/cuervolu) [`#1187`](https://github.com/rhaiscript/rhai/pull/1187)). | ||
| * A panic inside a native Rust function that takes its first argument by value, called with a variable first argument, now unwinds normally and can be caught by `catch_unwind`. Previously the copied first argument was restored only on the normal-return path, so the unwind tripped an internal assertion and the process aborted ([`#1188`](https://github.com/rhaiscript/rhai/issues/1188)). | ||
| * Under `sync`, a method call on a shared variable with a closure argument that captures the same variable now raises `ErrorDataRace`, as it does without `sync`, instead of panicking while resolving the function. `Dynamic::is_locked` now returns `true` under `sync` when the value cannot be read, which includes being locked for write by the current thread ([`#1188`](https://github.com/rhaiscript/rhai/issues/1188)). |
yuvalrakavy
force-pushed
the
fix-native-call-restore-on-unwind
branch
from
October 17, 2026 12:14
de75c2b to
377df35
Compare
Contributor
Author
|
Done, thanks for the quick look.
|
Contributor
Author
|
NoStdBuild: it is the nightly, not this branch. rust-lang/rust#148413 (nightly 2026-10-16) mangles the personality symbol, so no_std_test's #[no_mangle] rust_eh_personality no longer links. Fix for the harness in #1191; this PR touches nothing no_std-specific. |
Collaborator
|
There seem to be merge conflicts... Can you resolve them? I'll merge if it can. |
exec_native_fn_call swaps a copy of the first argument in through ArgBackup when a non-method native function is called with a variable first argument, and restored it only on the normal-return path. If the native function panicked, the unwind dropped the ArgBackup unrestored, its Drop assertion panicked during the unwind, and the process aborted, so no catch_unwind in the host could contain it. Restore through the same defer! guard the script-function path in this file already uses, which runs on unwind as well. The assertion is kept. The regression test runs the aborting case, `buggy(t)`, under every feature combination; the method-call spelling is a control and needs the dot syntax, which `no_object` disables, so it is gated. Fixes rhaiscript#1188 (the abort half).
Contributor
Author
yuvalrakavy
force-pushed
the
fix-native-call-restore-on-unwind
branch
from
October 17, 2026 22:46
377df35 to
5c8a405
Compare
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 the abort reported in #1188. The
syncpanic behind it is split out into #1190, as requested.exec_native_fn_callswaps a copy of the first argument in throughArgBackupwhen a non-method native function is called with a variable first argument, and restored it only on the normal-return path. If the native function panics, the unwind drops theArgBackupunrestored, itsDropassertion panics during the unwind, and the process aborts, so a host'scatch_unwindcannot contain it.The fix restores through the same
defer!guard the script-function path infunc_call.rsalready uses, which also runs on unwind. The assertion is kept.Test:
test_native_panic_with_variable_first_argument_unwindsintests/native.rs.buggy(t)is the aborting case and runs under every feature combination; the method-call spellingt.buggy()is a control and is gated onno_object, which disables the dot syntax (that was the CI failure on theno_objectrows). Without the fix the test aborts with SIGABRT; with it the panic is caught and the engine is usable afterwards.Checks:
cargo testwith default features,cargo test --test nativeunder the threeno_objectrows of the CI matrix,cargo +nightly fmt --check. CHANGELOG line under 1.27.0's bug fixes, linking this PR.🤖 Generated with Claude Code