feat(libc): implement bounded decimal parsing with strtonum #8037

Merged
MarrasFederico merged 2 commits from upstream-pr/8037 into main 2026-10-20 07:07:27 +00:00
MarrasFederico commented 2026-10-19 18:23:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-19T18:23:08Z.


What

Add the missing strtonum export (XrIfmNFHL4I) to libc. Parse decimal signed 64-bit values within inclusive caller bounds, return invalid, too small or too large on failure, and preserve the caller's errno on success. Malformed input takes precedence over overflow, and reversed bounds are rejected before parsing.

The signature and behavior follow FreeBSD 11.4 strtonum.c. The name/NID pair is present in the pinned symbol database. Console behavior remains unverified and is recorded in libc technical debt.

No matching open or closed PR, issue, or origin/main symbol-history change was found. pr_overlap.py reported no direct overlaps. Its not-compared shared files were reviewed manually: #5021, #5303, #6226, #6469, #6819, #7081, #7332, #7386, #7417, #7473, #7525 and #7715 change unrelated libc debt entries; #6044 only renames GuestStrings.cpp into tests/runtime/ with zero content changes. None implements or tests strtonum.

Tested

Ubuntu 26.04 x86-64, GCC 15.2.0, Release, BUILD_TESTING=ON:

  • Initialized all recursive submodules and completed the full build with -j12.
  • The new semantic regression cannot link against the original libc because strtonum_nid_postfix is absent.
  • guest_strings, guest_wide_strings, guest_errors, guest_safe_errors and guest_allocating_strings pass.
  • Seven temporary production-source mutations are detected by guest_strings: reversed-bound validation, trailing-character rejection, signed underflow, signed overflow, successful errno preservation, successful error-pointer clearing, and failure errno assignment.
  • The patched libc exports XrIfmNFHL4I.
  • Conventions, whitespace and overlap checks completed. The not-compared cases are described above.

No title, console, Windows or macOS execution was tested. No performance claim.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4925458223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8037). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-19T18:23:08Z. --- ### What Add the missing `strtonum` export (`XrIfmNFHL4I`) to libc. Parse decimal signed 64-bit values within inclusive caller bounds, return `invalid`, `too small` or `too large` on failure, and preserve the caller's errno on success. Malformed input takes precedence over overflow, and reversed bounds are rejected before parsing. The signature and behavior follow [FreeBSD 11.4 strtonum.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdlib/strtonum.c). The name/NID pair is present in the pinned [symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv). Console behavior remains unverified and is recorded in libc technical debt. No matching open or closed PR, issue, or `origin/main` symbol-history change was found. `pr_overlap.py` reported no direct overlaps. Its not-compared shared files were reviewed manually: #5021, #5303, #6226, #6469, #6819, #7081, #7332, #7386, #7417, #7473, #7525 and #7715 change unrelated libc debt entries; #6044 only renames `GuestStrings.cpp` into `tests/runtime/` with zero content changes. None implements or tests `strtonum`. ### Tested Ubuntu 26.04 x86-64, GCC 15.2.0, Release, `BUILD_TESTING=ON`: - Initialized all recursive submodules and completed the full build with `-j12`. - The new semantic regression cannot link against the original libc because `strtonum_nid_postfix` is absent. - `guest_strings`, `guest_wide_strings`, `guest_errors`, `guest_safe_errors` and `guest_allocating_strings` pass. - Seven temporary production-source mutations are detected by `guest_strings`: reversed-bound validation, trailing-character rejection, signed underflow, signed overflow, successful errno preservation, successful error-pointer clearing, and failure errno assignment. - The patched libc exports `XrIfmNFHL4I`. - Conventions, whitespace and overlap checks completed. The not-compared cases are described above. No title, console, Windows or macOS execution was tested. No performance claim. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 18:23:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T18:23:55Z.


Progress report (98db779 → 20f75e9)

📈 System libraries: 66.63% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc strtonum_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274236099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8037#issuecomment-6274236099). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T18:23:55Z. --- <!-- progress-report --> ### Progress report (98db779 → 20f75e9) 📈 **System libraries**: 66.63% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `strtonum_nid_postfix` | </details>
github-actions[bot] commented 2026-10-19 18:39:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T18:39:33Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8137 docs/dev/debt/libc.md L4-5

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestStrings.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7332 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274538381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8037#issuecomment-6274538381). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T18:39:33Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 8137](https://www.github.com/boykopovar/AnyPS5/pull/8137) | `docs/dev/debt/libc.md` [L4-5](https://github.com/boykopovar/AnyPS5/blob/98db779227f1d9d6d9fe162ce9b876eb2427008c/docs/dev/debt/libc.md#L4-L5) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestStrings.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `docs/dev/debt/libc.md` | | [PR 7386](https://www.github.com/boykopovar/AnyPS5/pull/7386) | `docs/dev/debt/libc.md` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
wachi35676 commented 2026-10-19 22:29:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T22:29:57Z.


Windows run (the description has Linux only): Windows 11 Home 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. This PR merged onto main 9127ea36d.

  • It builds.
  • guest_strings passes 3/3, including the errno-preservation checks through __error_nid_postfix, so the host errno the function sets is the one the guest reads on MinGW too.
  • With StringExtensions.cpp from main the test doesn't link, as on Linux.
  • The body matches FreeBSD 11.4 strtonum.c step for step: the minval > maxval check first, then strtoll base 10, the INVALID / TOOSMALL / TOOLARGE order, *errstrp set even on success, and errno restored on success.
  • strtonum hashes to XrIfmNFHL4I.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278789989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8037#issuecomment-6278789989). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-19T22:29:57Z. --- Windows run (the description has Linux only): Windows 11 Home 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. This PR merged onto `main` 9127ea36d. - It builds. - `guest_strings` passes 3/3, including the errno-preservation checks through `__error_nid_postfix`, so the host `errno` the function sets is the one the guest reads on MinGW too. - With `StringExtensions.cpp` from `main` the test doesn't link, as on Linux. - The body matches FreeBSD 11.4 [strtonum.c](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdlib/strtonum.c) step for step: the `minval > maxval` check first, then `strtoll` base 10, the INVALID / TOOSMALL / TOOLARGE order, `*errstrp` set even on success, and `errno` restored on success. - `strtonum` hashes to `XrIfmNFHL4I`. AI-assisted: yes (Claude Code); results above were run on this machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8037
No description provided.