Skip to content

fix(builtins): #871 — printf recognizes glibc inf/nan word prefixes - #894

Closed
arookieofc wants to merge 1 commit into
masterfrom
arookieofc/fix-871-printf-infnan-prefix
Closed

arookieofc wants to merge 1 commit into
masterfrom
arookieofc/fix-871-printf-infnan-prefix

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Closes #871.

glibc strtod treats inf/infinity/nan as word prefixes: trailing letters are left to *ep while the prefix converts — infin/infx/nann/nanx/inff/nana all print inf/nan and report the operand as an invalid number. scan_float_subject required the exact words, so those forms printed 0.000000.

Now matches the prefix family (infinity as an exact case-insensitive word, else inf/nan prefixes), with the subject ending at the prefix boundary so the tail surfaces as the invalid-number diagnostic, byte-identical to GNU. nan(seq) keeps its parenthesised rule.

Verified vs WSL GNU bash 5.3.9 (the 5.3-series oracle): the full 14-operand matrix plus the infinit/infinitZ boundary prints identically; infinitY is a case-insensitive infinity (no diagnostic), matching GNU. New nonfinite_word_prefixes_convert regression; printf numeric suite 53/53 green.

…not only the exact words

glibc strtod treats `inf`/`infinity`/`nan` as prefixes: a trailing
alphabetic run is left to *ep while the leading letters still convert —
so `infin`, `infx`, `nann`, `nanx`, `inff`, `nana` all print inf/nan and
report the whole operand as an invalid number (chk_converror fires on the
unconsumed suffix). The scanner required the exact words
`inf`/`infinity`/`nan`, so every letter-suffixed form printed 0.000000.

`scan_float_subject` now matches the prefix family: `infinity` as an
exact (case-insensitive) whole word, else the `inf`/`nan` prefixes; the
subject still ends at the prefix boundary so the trailing letters surface
as the *ep suffix diagnostic, byte-identical to GNU. `nan(seq)` keeps its
parenthesised-subject rule.

Verified vs WSL GNU bash 5.3.9 (the 5.3-series oracle): the full
infin/nann/infx/nanx/inf/infinity/nan/INF/INFINITY/NAN/inff/nana/
infinitY/nanx2 matrix prints identically, the `infinit`/`infinitZ`
boundary cases report `invalid number` like GNU, and `nan(x)` keeps its
parenthesised subject. New regression
`nonfinite_word_prefixes_convert`; printf numeric suite 53/53 green.
@github-actions

Copy link
Copy Markdown
Contributor

欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。

@caomengxuan666

Copy link
Copy Markdown
Member

独立评审结论(@caomengxuan666,interim review for #871 / #894 vs #899):建议落地 #899,本 PR 建议关闭并致谢。 交叉评审见 #899。

Oracle 复核(WSL GNU bash 5.3.0(1),/usr/local/bin/bash,97 形矩阵脚本单次批量;双侧各以 master / 本 PR / #899 三分支实建的 rubash shell 跑同一脚本,逐 case 对质 stdout/rc/stderr):

  1. 前缀族修复本身成立:infin/infx/inff/nann/nanx/infinite/infinityX/大小写/符号组合等 46 形,本 PR 与 fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 均与 GNU 逐字节一致(master 全部 0.000000);inf(2)/inf()/infinity(2) 的 invalid number 补修也与 GNU 一致。

  2. 但本 PR 引入 5 个 GNU 不存在的分歧(fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 全部正确):

    operand GNU 5.3.0(1) 本 PR fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899
    nanx(2) nan + rc1 + nanx(2): invalid number nan, rc0, 无诊断 与 GNU 一致
    nana(2) nan + rc1 + 诊断 nan, rc0, 无诊断 与 GNU 一致
    nanX(99) nan + rc1 + 诊断 nan, rc0, 无诊断 与 GNU 一致
    nanx(2x) nan + rc1 + 诊断 nan, rc0, 无诊断 与 GNU 一致
    nanx() nan + rc1 + 诊断 nan, rc0, 无诊断 与 GNU 一致

    根因:括号扩展的判定点用的是 word_end(整段字母 run 的末尾),而 glibc strtod 只看 nan 三字节前缀紧随的那个字节。nanx(2) 里前缀后是 x,括号组不应并入 subject,x(2) 必须留给 *ep 触发 chk_converror。fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 用 rest_bytes.get(word_len)(前缀正后方)判定,与 glibc 契约一致。顺带:本 PR 实现里 is_nan 为真时对 inf 前缀不生效这一点,也使 inf(2) 一并修复——这部分与 fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 等价。

  3. 注释自相矛盾(代码是对的):scan_float_subject 内注释称 “infinitY is inf + the suffix initY, NOT infinity — the oracle reports infinitY: invalid number”。Oracle 实测:infinitY 按 glibc 整词大小写不敏感 infinity 处理,无诊断(inf,rc0)——与本 PR 的代码和测试一致,与该句注释相反。落地前应删改这句,避免误导后续维护者。

  4. 基线较旧:本 PR merge-base 为 2b98675,fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 为 d3528dc(更新一拍,现 master c9e1421)。两分支改同一 hunk,后合者必冲突。

  5. 可回收的价值:inff/nana 操作数与 infinitY 尾字母边界形是本 PR 独有的好测试素材(fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 的 iNfInItY 未覆盖尾位大写边界)。我已验证拼接态(fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 实现 + 本 PR 三个测试形并入 nonfinite_prefix_871.rs):builtins::printf 56/56 绿,97 形矩阵仍 GNU-exact。建议由 fix(printf): #871 recognize glibc strtod inf/nan word prefixes in %f/%e/%g #899 顺手并入(3 行测试数据)。

套件复核:本分支 lib 708/708 绿(含 nonfinite_word_prefixes_convert);--test regression 77/78,唯一失败 upstream_suite_slice_snapshots 在干净 master 上同样复现(Windows 环境 flake,CI ubuntu 绿,非本 PR 引入)。CI 7 项全绿已确认。

谢谢这份 PR——#871 的词前缀分析、14 形矩阵与 infinitY 边界发现都对最终修复有实质贡献。鉴于与 #899 完全同票(同一 issue、同一文件、同一机制),建议关闭本 PR、以 #899 落地(可带上上述三个测试形)。再次致谢!

(另记:nan($%) 一形 GNU 会校验 n-char-sequence 字符集并拒绝整组(报 invalid number),master 与两 PR 均沿用“闭合即吞”的旧规则——该分歧为 master 先天存在、两 PR 等同继承,建议另开 follow-up 票,不阻塞本次裁决。)

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.

printf %f/%e/%g 的 inf/nan 词前缀子类未按 GNU 识别(infin/nann/infx/nanx)——#869 CR NIT-1

2 participants