Repository navigation
test(trap): pin GNU RETURN-trap contract for source and function returns (closes #204) - #244
Merged
Merged
Conversation
…on returns (closes #204) GNU bash 5.2 fires the RETURN trap on sourced-script completion unconditionally, and on shell-function return only when the function inherits it: global functrace (set -T / extdebug) or the per-function trace attribute (declare -ft f). A plain function call does not fire it. The function-return dispatch itself lives in the embedded rubash engine (run_function_return_trap, src/executor/trap_exec.rs, rubash#343/#345 family); rubash master carries the GNU-aligned fix and niu builds against it via the sibling-clone [patch] override, so the niubash 1.3.3 symptom (engine revision predating that work) is resolved upstream. This locks the oracle-verified contract on the niubash side so the class cannot regress silently: source completion, trace-attribute and extdebug inheritance, declare -t variable-path non-inheritance, per-level firing on nested calls under set -T, and in-function trap arming scope.
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.
Closes #204.
Root cause
The issue's symptom (RETURN trap fires when a sourced script completes but not when a function returns) traces to the embedded rubash engine: the function-return dispatch lives in rubash's
run_function_return_trap(src/executor/trap_exec.rs, the rubash#343/#345 family). niubash 1.3.3 shipped a rubash revision predating that work.Fix location: the GNU-aligned engine fix has already landed on rubash
master; niu builds against it via the sibling-clone[patch."https://github.com/unixwin/rubash.git"]override (CI clones the sibling at latest master, same path). No niubash runtime code needed changing, so this PR delivers the niubash-layer half: an oracle-locked regression suite so the contract cannot regress silently again. If the release pipeline pins a rubash rev, it must be bumped to a revision containingrun_function_return_trap(post rubash#343/#345) for shipped binaries to pick the behavior up.GNU semantics verified against the oracle (GNU bash 5.2.37 msys,
D:\Git\usr\bin\bash.exe, byte-compared)set -T) /shopt -s extdebug(implies functrace), or the per-function trace attribute (declare -ft f/declare -f -t f). A plaintrap ... RETURN; fdoes not fire (execute_cmd.c:5291-5295).declare -t fwithout-fgoes down the variable-attribute path: no trace attribute, no fire.set -T, each nested call level fires exactly once, inner-first.Test matrix (tests/issue204_return_trap_function_return.rs, 9 tests, all green)
trap … RETURN; fdeclare -ft f/declare -f -t fdeclare -t f(variable path)shopt -s extdebugset -T, nested callsRegression runs
tests/issue204_return_trap_function_return.rs: 9/9 pass.smoke,smoke_1_3_0,defaults_floor,startup_files,rubash_revision_banner: green.compat: 18 ignored by design (needs real winuxcmd command links, per suite header).host_contract::closed_stdout_pipe_does_not_print_broken_pipe_error("niu: line 1: Broken pipe" spam / does not exit after stdout pipe closes) reproduces on this branch with zero source changes and is outside the RETURN-trap scope — filed separately rather than mixed into this PR.cargo fmtclean.