Repository navigation
api: Session::run admits live expand_aliases with an empty table - #3672
Conversation
…field (Refs #3605) GNU hands `%.<digits>' verbatim to the host libc's printf(3) via the PF() macro (builtins/printf.def:152-175). On BSD/Darwin libc the precision digit run accumulates into an int field (xprintf.c:558-559), wrapping mod 2^32: `printf "%.9223372036854775825s" XY' prints XY, and the vendored printf.right golden expects exactly that. The previous EOVERFLOW+PRETURN model fits an inline field *width* (xprintf.c:604-625 feeds an INT_MAX-checked pad) but not precision. Precision overflow now wraps the digit run two's-complement into i32: positive results apply as precision, negative results are "as if it were missing". Inline width overflow keeps the EOVERFLOW error, and the printstr specs (b/q/Q/T/S/C/wide) keep GNU decodeint() erange semantics unchanged. Verified on macOS arm64 vs GNU bash 5.3.20: %.9223372036854775825s/d render as %.17s/%.17d, %.4294967295s prints the full string, and niubash run-printf is PASS (the only remaining diff is the Mach-O exec gap covered by PR #3586). New unit tests pin the wrap, the wrapped-negative case, and the width EOVERFLOW boundary. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…#3605) rubash#3605 class B (run-alias tail): Session::run's grouped-driver admission required a NON-EMPTY alias table on top of the live expand_aliases flag, so a submission like '-o posix -c' text — where shell.c:1853 init_noninteractive seeds expand_aliases before the reader starts but no aliases are defined yet — took the whole-source route. That route's word-level alias fallback expands reserved words without parse.y:5751-5769's posix ordering (posix checks reserved words BEFORE alias expansion), so 'alias for=echo\nal for foo in v\ndo ...' expanded 'for' to 'echo' and died on a syntax error where GNU runs the loop and prints 'foo=v bar='. GNU's reader is incremental (evalstring.c parse_and_execute) and the alias gate is consulted on every token (parse.y:5759), so aliases defined by an earlier line must be live for the lines read after it — the same admission main.rs computes as alias_live_at_start for the -c route (rubash#414). Drop the non-empty-table term: the flag is the whole admission, matching the bin-side answer. Verified: niu -o posix -c 'alias for=echo; al for foo in v; do echo foo=$foo bar=$bar; done' now prints 'foo=v bar=' (GNU bash 5.3.20 identical); niubash gate run-alias diff cleared (PASS). New session_api test pins the posix run over this contract; the pre-existing macOS-only build_run_and_state_views_round_trip /var -> /private/var canonicalization flake is unchanged. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】 阻塞结论(为什么不合):
机制核查(只看本 PR 自己的两个文件):
腿(逐项给数字与名字):
F 点(PENDING,按「待修」列出):
未跑/VOID 的腿:无(新钉在本机以临时探针替代跑通,原钉的 Windows 红已定位为测试路径缺陷)。 |
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项给数字与名字):
F 点:无 续作记录:
未跑/VOID 的腿:
|
|
【WIN-AGENT-AUDIT】 |
Summary
Session::run's grouped-driver admission required a non-empty alias table on top of the liveexpand_aliasesflag — so a submission where the flag is armed at reader start but no aliases exist yet (-o posix/--posix/-O expand_aliases;shell.c:1853 init_noninteractiveseedsexpand_aliases = posixly_correct) took the whole-source route. That route's word-level alias fallback expands reserved words withoutparse.y:5751-5769's posix ordering (posix checks reserved words BEFORE alias expansion), soalias for=echo+al for foo in vunder-o posixexpandedfortoechoand died on a syntax error where GNU runs the loop and printsfoo=v bar=.The flag is the whole admission — the same answer
run_command_string_with_initcomputes asalias_live_at_startfor the bin-croute (rubash#414). GNU's reader is incremental (evalstring.cparse_and_execute) and the alias gate is consulted on every token (parse.y:5759), so aliases defined by an earlier line must be live for the lines read after it. One-line change: drop the non-empty-table term; plus asession_apiregression test pinning a posix run through this contract.Refs #3605 (class B, run-alias tail — clears the suite's last diff).
GNU anchors
shell.c:1853 init_noninteractive—expand_aliases = posixly_correctfor a non-interactive posix shell (aliases live from the first line).parse.y:5751-5769 read_token_word— posix reserved-word check BEFOREalias_expand_token(parse.y:3249); default mode after.evalstring.c parse_and_execute— incremental command-by-command reading;aliasdefinitions apply to subsequent input.main.rsalias_live_at_start = executor.alias_expansion_enabled()— the bin-side admission this contract now matches.Verification (macOS arm64, GNU bash 5.3.20 oracle)
niu -o posix -c 'alias al=" "; alias foo=bar; alias for=echo\nal for foo in v\ndo echo foo=$foo bar=$bar\ndone'→foo=v bar=(byte-identical to GNU; wasfoo in v+syntax error near unexpected token 'do').run-alias→ PASS (last diff cleared).cargo test --test session_api— newposix_run_expands_aliases_defined_in_the_same_submissionpins the contract; all 9issue414reserved-word-alias regressions still pass. One pre-existing macOS-only flake (build_run_and_state_views_round_trip,/var→/private/varcanonicalization) is unrelated.niu -c(no posix) still expandsfor→echoper parse.y:5768.Test plan
cargo test --test session_apicargo test --test issue414_posix_reserved_word_alias_regressionsrun-aliasPASS