Repository navigation
fix(glob): export strmatch for loadables and route GLOBIGNORE through it (Refs #3605) - #3630
Conversation
… it (Refs #3605) macOS gate class A: glob-bracket.tests builds strmatch.so with -undefined dynamic_lookup and the plugin crashed calling back into the shell — niu exported no C symbols, so dyld bound the strmatch() call to an unbound address and the first invocation SIGSEGVed. * src/executor/strmatch.rs: single-byte port of lib/glob/strmatch.c (strmatch() at 32-39), smatch.c helpers (FOLD 301-304, SDOT/PDOT 313-314, collsym 168-182, is_cclass 283-297, dequote_pathname glob.c:431), and the full sm_loop.c GMATCH/PATSCAN/BRACKMATCH/EXTMATCH under the real FNM_* flag set (strmatch.h:35-55). Exported #[no_mangle] extern "C" strmatch so loadables resolve it against the host image exactly as GNU bash exports it. * src/executor/glob.rs ignore_pattern_matches(): pathexp.c:543-546 glob_name_is_acceptable() runs every ignore spec through strmatch(pattern, name, FNM_PATHNAME|FNMATCH_EXTFLAG|FNMATCH_NOCASEGLOB) — one matcher. Extglob specs previously went to the conditional case-pattern engine, which lacks the PATHNAME n < endp bound (sm_loop.c:284-290): an extglob sitting AT the slash position is never tried by GNU, so *@(/)cd/efg must not match ab/cd/efg (glob-bracket.right #20). The engine also let * cross /. Now routed through the unified port with GNU's flag set. Verified on macOS via niubash gate: run-glob-bracket PASS (was SIGSEGV exit 139); run-extglob, run-extglob2, run-extglob3, run-globstar, run-quote all still PASS. tests/issue3605 covers the *@(/) and plain-pattern PATHNAME bounds end-to-end through the shell. Refs #3605 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】PR #3630 第1轮 — 建议:FAIL 机制核查:
腿(逐项给数字与名字):
F 点(建议 FAIL):
未跑/VOID 的腿:
|
…th (Refs #3605) smatch.c:585-603 xstrmatch(): when locale_mb_cur_max > 1 and either the name or the pattern carries multibyte characters, GNU converts both to wide chars and runs internal_wstrmatch; the single-byte internal_strmatch is used otherwise. The previous commit ported only the single-byte compile, so under UTF-8 `?`/`[Ä]` in a GLOBIGNORE spec consumed one byte apiece: `u/?.txt` leaked `u/Ä.txt` and `u/??.txt` over-swallowed it (audit F1 on #3630). - strmatch.rs: lift the sm_loop engine onto `char` elements. Bytes are raised through the Latin-1 bijection (order- and equality-preserving), so strmatch_bytes stays the single-byte compile while the new strmatch_chars entry is the wide compile. An internal FNM_WIDE flag selects towlower-style folding (char::to_lowercase) and the glibc- aligned isw* predicates in locale::utf8_posix_class_matches instead of the ASCII domains (smatch.c:301-304 FOLD, smatch.c:283-297 is_cclass). - glob.rs ignore_pattern_matches: mirror the xstrmatch dispatch — is_multi_byte_active() plus a non-ASCII byte in pattern or name (the mbsrtowcs "has multibyte" probe for &str inputs) routes to strmatch_chars; everything else stays byte-wise. - The superseded strmatch_pathname/BracketMatch/parse_bracket_match/ bracket_class_matches/posix_class_matches tree is removed; the unified port now serves both locales. - New pin tests/issue3605_globignore_strmatch_multibyte.rs spawns the binary under LC_ALL=en_US.UTF-8 and LC_ALL=C (locale is env-driven, so the pin discriminates on Windows too, addressing the audit's cfg(unix)-void note). GNU 5.3.20 reference output: UTF-8 `u/?.txt` leaves `u/ab.txt u/Äb.txt`; C locale leaves `u/ab.txt u/Ä.txt u/Äb.txt u/é.txt`. Verification: probe matrix (GLOBIGNORE `?`/`??`/`[Ä]`/`[[:alpha:]]`/`*`, extglob `@(Ä|é)`/`@(?)`/`?(Ä)`, nocaseglob `Ä`/`[ä]`) byte-identical to GNU bash 5.3.20 under both locales; pins 6/6 green. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Rework pushed as F1 (multibyte): Verified against GNU bash 5.3.20 byte-for-byte under both F2 (pin void on Windows): new The dead |
…able-export # Conflicts: # src/executor/glob.rs
Loadable builtins resolve `strmatch()` against the shell image. GNU's exported symbol wraps `xstrmatch` (lib/glob/strmatch.c:33-39), so the C ABI must follow the MB_CUR_MAX dispatch of smatch.c:585-603 instead of answering from the single-byte compile: under a multibyte locale with multibyte data GNU runs `internal_wstrmatch`, and `?`/`[Ä]` consume one character. `ignore_pattern_matches` now calls the same `xstrmatch` entry, so the GLOBIGNORE path and the C ABI share one dispatch; the single-byte and wide compiles stay separate below it. Linux links the binary with `-rdynamic` (build.rs), mirroring GNU's configure:23147 `linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading`. Without it `#[no_mangle] strmatch` stays out of `.dynsym` and a loadable dies on its first call. Pins: a real loadable fixture (tests/fixtures/dynamic_builtin/ strmatch_probe.c) asserts the exported ABI under LC_ALL=C.UTF-8 and LC_ALL=C; GNU bash 5.3.20 is byte-identical on both.
判词 P — 收网 rework(head
|
Summary
Refs #3605 (macOS gate class A).
glob-bracket.testscompilesstrmatch.sowith-undefined dynamic_lookup; afterenable -f, the plugin calls the host symbolstrmatch(). niu exported no C symbols, so dyld bound the call to an unbound address → SIGSEGV (exit 139) on first invocation.src/executor/strmatch.rs(new): single-byte port oflib/glob/strmatch.c(strmatch()at 32-39),smatch.chelpers (FOLD301-304,SDOT/PDOT313-314,collsym168-182,is_cclass283-297,dequote_pathnameglob.c:431), and the fullsm_loop.cGMATCH/PATSCAN/BRACKMATCH/EXTMATCHunder the realFNM_*flags (strmatch.h:35-55). Exported#[no_mangle] extern "C" strmatchso loadables resolve it against the host image exactly as GNU bash exports it.src/executor/glob.rsignore_pattern_matches():pathexp.c:543-546 glob_name_is_acceptable()runs every ignore spec throughstrmatch(pattern, name, FNM_PATHNAME|FNMATCH_EXTFLAG|FNMATCH_NOCASEGLOB)— one matcher. Extglob specs previously went to the conditional case-pattern engine, which lacks the PATHNAMEn < endpbound (sm_loop.c:284-290): GNU never tries an extglob sitting AT the slash position, so*@(/)cd/efgmust not matchab/cd/efg(glob-bracket.right[Bug 批量] 命令替换状态污染 / heredoc / case 模式 / 参数替换 / 路径转换 / 重定向 / 调试钩子 - 20+ 个与 GNU Bash 的兼容性差异(含最小复现) #20). Now routed through the unified port with GNU's exact flag set.Single-byte (C locale) port;
internal_wstrmatchmultibyte path not implemented.Verified (macOS, niubash gate)
run-glob-bracket: PASS (was SIGSEGV / exit 139)run-extglob,run-extglob2,run-extglob3,run-globstar,run-quote: all PASS, no regressionstests/issue3605_globignore_strmatch_regressions.rspins the*@(/)and plain-pattern PATHNAME bounds end-to-end through the shell.