Skip to content

exec: bind every heredoc/here-string entry at its redirect-list position — #3603+#3580 synthesis (Refs #3578) - #3752

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3578-heredoc-binding-synthesis
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3578-heredoc-binding-synthesis

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

综合来源(captain 可直接合)

本单是 issue #3578 双实现的综合收编,按 #3603 上的【队长终裁】PASS 裁断落地:

  • 机制取 exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) #3603(fix/3578-exec-multi-heredoc,head 4b589f12):redirect-only exec 的 walk 内按位配对 cmd.redirects ↔ cmd.heredoc_redirects 孪生(heredoc_twins),每条 heredoc/编号 here-string 在自己的 GNU do_redirections 位置 materialize 并绑定(redir.c:423 here_document_to_fd + redir.c:1065-1072/:1120 dup2)。{var}<< 消耗孪生、绑定仍归 walk 后 fd_var heredoc 循环(vredir1.sub);无编号 <<< 走既有 here_string fd-0 路径;未配对残余在尾部绑定。master 已大幅前进(rlimit 门 rubash#3195、fd_var heredoc 独立循环等),机制按现状重接线,展开统一走 canonical expand_heredoc_redirect_text,删除尾部单条查找 exec_heredoc_fd_input。
  • 钉面取并集(tests/issue3578_exec_multi_heredoc.rs,12 格):exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) #3603 的 4 格为基 + fix(executor): redirect-only exec binds every heredoc entry (Refs #3578) #3580 独有格(read -u 双 heredoc 种子形、三 heredoc、同 fd 后胜、fd-0+编号、{var}+编号、brace-group 对照)+ 1 格综合新增(exec <<A 3<&0 钉住"按位绑定"本身——3<&0 dup 到的是 walk 位置已绑的 body)。每格先经 WSL GNU bash 5.3.x script-file 探针字节级验证再写入。

验证

  • 新钉文件 12/12 绿;邻面 issue3195_heredoc_fd_limit、issue1413、issue1965/1966、issue2265、issue2467、issue2612、issue2082、issue2676、issue699、issue726、issue2821、issue2395 等全绿。
  • cargo test --lib 1351/1352、RUSTFLAGS="-D warnings" cargo build 干净。
  • 下列红项已逐一对 clean master 基线复核为既有/环境红(嵌套 rubash.exe spawn fd 投递在本机不落、诊断路径风格断言、coproc 时序),与本 diff 无关:issue2270 8/10、issue2305 6/16、issue2309 12/18、issue1651 2/10、issue3046 7/15、issue2125 1/21、issue2615 1/13、issue1102 1/1、issue2803 1/6、lib issue2084。

已知残余(非本单范围,供队长备案)

  • exec <<<a <<B:GNU 后胜给 fd0=B;本机制(与 exec: bind every heredoc/here-string entry at its redirect-list position (Refs #3578) #3603 一致)将无编号 <<< 延至 walk 后 here_string 路径回绑,得 a。系改动前既有的偏离(旧代码同样给 a),非本单回归;若要根治需让无编号 here-string 也按位绑定(redirect.target 逐条词可用),建议另立跟进。
  • exec <<<a 3<&0 <<<b 同类 fd-0 时序边角,同上。

两条旧 PR 的处置建议(留给队长)

Refs #3578

Generated with Devin

…ion (Refs #3578)

Synthesis of PR #3603's mechanism and PR #3580's wider pin grid for
issue #3578 (captain's survivor ruling: #3603's in-walk pairing wins
on mechanism fidelity; #3580's extra pin cells re-verified on the
merged shape).

GNU applies each redirect in do_redirections' list order —
here_document_to_fd (redir.c:423) materializes the body and dup2s it
onto the redirector at redir.c:1065-1072/:1120, and a redirect-only
exec keeps those binds persistent (builtins/exec.def). The parser
mirrors every heredoc / numbered here-string into both cmd.redirects
(its list position) and cmd.heredoc_redirects (its body store), but
the redirect-only exec walk skipped the heredoc kinds entirely and
the tail lookup bound only the LAST body — `exec 14<<A 15<<B` left
fd 14 unbound.

Pair the two parallel stores in list order (heredoc_twins): {var}
entries consume their twin so the fd_var heredoc loop keeps owning
their bind (vredir1.sub), an unnumbered here-string keeps its fd-0
here_string path, and any unpaired leftover still binds at the tail.
The #3195 rlimit gate still aborts the whole walk before any bind.
Expansion goes through the canonical expand_heredoc_redirect_text
ladder — the same bytes execute_dynamic_fd_var_heredoc binds —
replacing the deleted exec_heredoc_fd_input tail lookup.

Pins (tests/issue3578_exec_multi_heredoc.rs, 12 cells): #3603's four
plus #3580's union-unique cells (read -u two-heredoc seed, three
heredocs, same-fd last-wins, fd-0+numbered, {var}+numbered,
brace-group control) plus an interleave pin for the at-position bind
itself (exec <<A 3<&0). Every expectation byte-verified against WSL
GNU bash 5.3.x script-file probes.

Refs #3578

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit b69e175 into master Nov 15, 2026
7 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3578-heredoc-binding-synthesis branch November 15, 2026 23:56
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
…3578) (#3895)

The core fix already landed via #3752 (b69e175): the exec redirect walk
pairs each numbered heredoc/here-string entry with its heredoc_redirects
twin at its own list position (GNU redir.c do_redirections ordered walk,
here_document_to_fd materialization). This adds dedicated regression pins
for the under-limit class the issue title describes — exec 14<<A 15<<B
under ulimit -n 16 — plus boundary variants: multi-line bodies, reversed
fd order, three heredocs at the boundary, heredoc+here-string mix, and
persistence into the next command. Byte-identical to WSL GNU Bash 5.3.20
on all six scripts.

Residuals found during review filed separately: #3892 (exec {var} binds
lost on later-entry failure — GNU varassign entries carry no undo record,
redir.c:972/1091/1153), #3893 ({var}<< allocation deferred to walk tail),
#3894 ({var}<< body double-bound to fd 0 on simple commands).

Generated with [Devin](https://devin.ai)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant