fix(libs): parse decimals on macOS releases without floating from_chars #27767

Closed
LODIBIDO wants to merge 2 commits from upstream-pr/27767 into main
LODIBIDO commented 2026-11-27 08:55:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LODIBIDO on 2026-11-27T08:55:47Z.


What

On macOS releases before 26, libc++ has no floating-point std::from_chars, so libSceNKWebKit/CharactersToNumber.cpp and libSceVideoOut/src/InputMapping.cpp do not compile (call to deleted function 'from_chars').

Both now call ParseDecimal_nid_no_patch in the new core/libs/DecimalParsing.hpp.

  • Every other target, including macOS 26 and later, calls std::from_chars exactly as before.
  • Before macOS 26 it scans the from_chars general syntax (decimal numbers, inf, infinity, nan, nan(...)), converts with strtod_l or strtof_l in the C locale under the default floating-point environment, restores that environment and errno, and reports overflow and underflow to zero as result_out_of_range without writing the value.

The guard is the one in RavenCurseBurg's candidate fix for UpscaleMode.hpp (744123f1bd, posted on #24341). This PR does not touch that file, so libSceAgcDriver still needs that fix on these releases.

#20016 also edits InputMapping.cpp; the from_chars call it adds parses an integer.

Refs #27647.

Tested

Native Intel Mac (i5-8259U, x86_64, no Rosetta, macOS 15.7.8, Apple clang 17.0.0), Release, main afdd33906b plus the diff of #27201 so that libc compiles.

  • Without this change both source files fail with the error above; with it they compile.
  • pad_input_mapping, guest_nkwebkit_numbers, nkwebkit_wtf, nkwebkit_wtftext, nkwebkit_wtftext_allocation, nkwebkit_doubletofixed and nkwebkit_doubletostringconverter: each passed 5 of 5. pad_input_mapping has new cases for rejected syntax, range limits and a written zero.
  • A throwaway program compared the new path with exact rational arithmetic on 63,064 strings, for float and double: no difference in error code, consumed length or result bits (for NaN: sign and NaN class, not the payload), by default, with a comma-decimal locale, with tr_TR.UTF-8 and tr_TR.ISO8859-9, and with downward rounding and flush-to-zero/denormals-are-zero set. errno, the rounding mode and MXCSR were unchanged after each call.
  • A syntax-only pass over the 74 configured translation units that use from_chars: the only from_chars errors left are in VulkanDevice.cpp and PresentationPass.cpp, both from UpscaleMode.hpp:25. libSceAgcDriver/tests/Recorder.cpp needs generated shader headers that were not built; with placeholder headers it reports no from_chars error. The pass also reports an unrelated error on main, libSceAgcDriver/Execution/src/GuestMemory.cpp:4175 (no matching function for call to 'min').
  • Overlap was checked from the file lists of open pull requests; tools/pr_overlap.py was not run.

Not tested: Linux, Windows, Apple silicon, macOS 26, any title.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (only the input settings parser changes in VideoOut; no GPU test run)
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved decimal-number parsing on supported macOS versions, including values with exponents and signed infinity or NaN.
    • Numeric settings now handle written zero and report malformed or out-of-range values more consistently, including overflow and underflow cases.
    • Decimal values entered in browser-related and video settings now use consistent parsing behavior.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5523887247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767). Originally posted by [LODIBIDO](https://github.com/LODIBIDO) on 2026-11-27T08:55:47Z. --- ### What On macOS releases before 26, libc++ has no floating-point `std::from_chars`, so `libSceNKWebKit/CharactersToNumber.cpp` and `libSceVideoOut/src/InputMapping.cpp` do not compile (`call to deleted function 'from_chars'`). Both now call `ParseDecimal_nid_no_patch` in the new `core/libs/DecimalParsing.hpp`. - Every other target, including macOS 26 and later, calls `std::from_chars` exactly as before. - Before macOS 26 it scans the `from_chars` general syntax (decimal numbers, `inf`, `infinity`, `nan`, `nan(...)`), converts with `strtod_l` or `strtof_l` in the C locale under the default floating-point environment, restores that environment and `errno`, and reports overflow and underflow to zero as `result_out_of_range` without writing the value. The guard is the one in RavenCurseBurg's candidate fix for `UpscaleMode.hpp` (744123f1bd, posted on #24341). This PR does not touch that file, so `libSceAgcDriver` still needs that fix on these releases. #20016 also edits `InputMapping.cpp`; the `from_chars` call it adds parses an integer. Refs #27647. ### Tested Native Intel Mac (i5-8259U, x86_64, no Rosetta, macOS 15.7.8, Apple clang 17.0.0), Release, `main` afdd33906b plus the diff of #27201 so that libc compiles. - Without this change both source files fail with the error above; with it they compile. - `pad_input_mapping`, `guest_nkwebkit_numbers`, `nkwebkit_wtf`, `nkwebkit_wtftext`, `nkwebkit_wtftext_allocation`, `nkwebkit_doubletofixed` and `nkwebkit_doubletostringconverter`: each passed 5 of 5. `pad_input_mapping` has new cases for rejected syntax, range limits and a written zero. - A throwaway program compared the new path with exact rational arithmetic on 63,064 strings, for `float` and `double`: no difference in error code, consumed length or result bits (for NaN: sign and NaN class, not the payload), by default, with a comma-decimal locale, with `tr_TR.UTF-8` and `tr_TR.ISO8859-9`, and with downward rounding and flush-to-zero/denormals-are-zero set. `errno`, the rounding mode and MXCSR were unchanged after each call. - A syntax-only pass over the 74 configured translation units that use `from_chars`: the only `from_chars` errors left are in `VulkanDevice.cpp` and `PresentationPass.cpp`, both from `UpscaleMode.hpp:25`. `libSceAgcDriver/tests/Recorder.cpp` needs generated shader headers that were not built; with placeholder headers it reports no `from_chars` error. The pass also reports an unrelated error on `main`, `libSceAgcDriver/Execution/src/GuestMemory.cpp:4175` (`no matching function for call to 'min'`). - Overlap was checked from the file lists of open pull requests; `tools/pr_overlap.py` was not run. Not tested: Linux, Windows, Apple silicon, macOS 26, any title. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 (only the input settings parser changes in VideoOut; no GPU test run) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved decimal-number parsing on supported macOS versions, including values with exponents and signed infinity or NaN. * Numeric settings now handle written zero and report malformed or out-of-range values more consistently, including overflow and underflow cases. * Decimal values entered in browser-related and video settings now use consistent parsing behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
JJenkx commented 2026-11-27 09:03:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T09:03:37Z.

Review: COMMENTED


The fallback scans its special tokens in the caller's character locale before converting in the C locale. strncasecmp uses the current locale on macOS, and std::isalnum also uses the current character locale. Floating-point from_chars requires C-locale syntax for the whole scan. Apple libc · C++ floating-point grammar

I forced the exact fallback header at ece6946fc027 on Linux with a small adapter for LC_C_LOCALE, then compared with the ordinary std::from_chars branch. With tr_TR.UTF-8, INF, INFINITY, and -InFiNiTy! returned invalid_argument for both float and double when the ordinary branch accepted them. With tr_TR.ISO-8859-9, a NaN followed by a parenthesized non-ASCII letter also reported 6 bytes consumed where the C-locale parser consumed 3.

A local variant using strncasecmp_l(..., LC_C_LOCALE) and isalnum_l(..., LC_C_LOCALE) matched all 102 comparisons across C and both Turkish locales. Please make the character scan locale-independent as well. This checks the scanner contract. The two current callers reject or never generate these special tokens. The forced-branch test used Linux libc and did not run on macOS.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6085755780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767#pullrequestreview-6085755780). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T09:03:37Z. **Review:** COMMENTED --- The fallback scans its special tokens in the caller's character locale before converting in the C locale. `strncasecmp` uses the current locale on macOS, and `std::isalnum` also uses the current character locale. Floating-point `from_chars` requires C-locale syntax for the whole scan. [Apple libc](https://github.com/apple-oss-distributions/Libc/blob/main/string/FreeBSD/strcasecmp.c#L59-L82) · [C++ floating-point grammar](https://eel.is/c++draft/charconv.from.chars#6) I forced the exact fallback header at `ece6946fc027` on Linux with a small adapter for `LC_C_LOCALE`, then compared with the ordinary `std::from_chars` branch. With `tr_TR.UTF-8`, `INF`, `INFINITY`, and `-InFiNiTy!` returned `invalid_argument` for both float and double when the ordinary branch accepted them. With `tr_TR.ISO-8859-9`, a NaN followed by a parenthesized non-ASCII letter also reported 6 bytes consumed where the C-locale parser consumed 3. A local variant using `strncasecmp_l(..., LC_C_LOCALE)` and `isalnum_l(..., LC_C_LOCALE)` matched all 102 comparisons across C and both Turkish locales. Please make the character scan locale-independent as well. This checks the scanner contract. The two current callers reject or never generate these special tokens. The forced-branch test used Linux libc and did not run on macOS. <!-- decimal-fallback-ctype-locale-20261127 -->
MarcZX10 commented 2026-11-27 09:13:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T09:13:17Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed change has no verified blocking defects; the reported macOS tests were not run in this review.

What I ran

Read the prepared diff and all four changed files at head ece6946fc02790fa3cad337be239cacb96b44b15 through repo_read.py. No build or test commands were run.

Results

Check Result Note
Changed code review passed All four changed files read
Build and tests not run Results in the PR description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build and test results were not independently verified. Linux, Windows, Apple silicon, macOS 26, and console behavior were not tested in this review. All files listed as reviewed were read: core/libs/DecimalParsing.hpp, core/libs/prx/libSceNKWebKit/CharactersToNumber.cpp, core/libs/prx/libSceVideoOut/src/InputMapping.cpp, and core/libs/prx/libSceVideoOut/tests/InputMapping.cpp. No changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6085872545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767#pullrequestreview-6085872545). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T09:13:17Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed change has no verified blocking defects; the reported macOS tests were not run in this review. ## What I ran Read the prepared diff and all four changed files at head `ece6946fc02790fa3cad337be239cacb96b44b15` through `repo_read.py`. No build or test commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All four changed files read | | Build and tests | not run | Results in the PR description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Build and test results were not independently verified. Linux, Windows, Apple silicon, macOS 26, and console behavior were not tested in this review. All files listed as reviewed were read: `core/libs/DecimalParsing.hpp`, `core/libs/prx/libSceNKWebKit/CharactersToNumber.cpp`, `core/libs/prx/libSceVideoOut/src/InputMapping.cpp`, and `core/libs/prx/libSceVideoOut/tests/InputMapping.cpp`. No changed files were excluded. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-27 09:43:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T09:43:53Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: restore the saved floating-point environment even when conversion or classification fails.

What I ran

Reviewed head c2aeb13ac63d603aacf2f5e7ef1cdb689a6b1884 and its prepared diff. I read all four changed files listed in the manifest; no commands or tests were run.

Results

Check Result Note
Diff and changed code passed Four changed files read
Tests not run No local execution

Findings

Blocking

  • core/libs/DecimalParsing.hpp:68 changes the calling thread’s floating-point environment to FE_DFL_ENV, then restores it only on the normal path at line 73. If std::string allocation at line 64 throws, or a conversion/classification operation fails exceptionally, the caller’s rounding mode and exception flags may remain altered. Guard the environment change with an RAII restore so every exit path reinstates it.

Non-blocking

None.

Not verified

No tests or compilation were run. The PR description reports author-run macOS checks, but these were not independently verified. No files were excluded by the provided manifest; all four changed files were read.

To get this to a good state

Add exception-safe restoration of the floating-point environment, then rerun the relevant parsing and environment-preservation checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6086216734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767#pullrequestreview-6086216734). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T09:43:53Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: restore the saved floating-point environment even when conversion or classification fails. ## What I ran Reviewed head `c2aeb13ac63d603aacf2f5e7ef1cdb689a6b1884` and its prepared diff. I read all four changed files listed in the manifest; no commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Four changed files read | | Tests | not run | No local execution | ## Findings ### Blocking - `core/libs/DecimalParsing.hpp:68` changes the calling thread’s floating-point environment to `FE_DFL_ENV`, then restores it only on the normal path at line 73. If `std::string` allocation at line 64 throws, or a conversion/classification operation fails exceptionally, the caller’s rounding mode and exception flags may remain altered. Guard the environment change with an RAII restore so every exit path reinstates it. ### Non-blocking None. ## Not verified No tests or compilation were run. The PR description reports author-run macOS checks, but these were not independently verified. No files were excluded by the provided manifest; all four changed files were read. ## To get this to a good state Add exception-safe restoration of the floating-point environment, then rerun the relevant parsing and environment-preservation checks.
JJenkx commented 2026-11-27 09:54:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T09:54:40Z.

Review: COMMENTED


I retested the ASCII scanner on exact head c2aeb13ac63d. The forced fallback matched std::from_chars in all 102 comparisons across C, Turkish UTF-8, and Turkish ISO-8859-9.

For the floating-point environment follow-up, 72 checks passed across all four rounding modes. They cover successful, invalid, overflow, and underflow inputs, plus eight injected std::bad_alloc throws from the temporary string allocation for float and double. The caller's rounding mode and pre-raised exception flags survived all cases. The allocation happens before the switch to FE_DFL_ENV, and the ordinary out-of-range return follows the restore. This experiment used the exact fallback on Linux with a C-locale API adapter. Native macOS remains the portability check.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6086347112 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767#pullrequestreview-6086347112). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T09:54:40Z. **Review:** COMMENTED --- I retested the ASCII scanner on exact head `c2aeb13ac63d`. The forced fallback matched `std::from_chars` in all 102 comparisons across C, Turkish UTF-8, and Turkish ISO-8859-9. For the floating-point environment follow-up, 72 checks passed across all four rounding modes. They cover successful, invalid, overflow, and underflow inputs, plus eight injected `std::bad_alloc` throws from the temporary string allocation for float and double. The caller's rounding mode and pre-raised exception flags survived all cases. The allocation happens before the switch to `FE_DFL_ENV`, and the ordinary out-of-range return follows the restore. This experiment used the exact fallback on Linux with a C-locale API adapter. Native macOS remains the portability check. <!-- ascii-fenv-retest-20261127 --> AI-assisted: yes
ligmaSec commented 2026-12-03 12:31:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:31:31Z.

Review: COMMENTED


pad_input_mapping and agc_driver_gcn_scalar_buffer_base passed on main and the patched tree on the same Linux llvmpipe device with Vulkan required, shader cache disabled, and validation layer 1.4.369. Both logs show layer insertion and no missing-layer diagnostic or VUID- entry. A Linux fixture that selected the macOS fallback passed 20,052 conversion comparisons and caller-state checks. Native macOS remains outside this run.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6169860024 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27767#pullrequestreview-6169860024). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:31:31Z. **Review:** COMMENTED --- `pad_input_mapping` and `agc_driver_gcn_scalar_buffer_base` passed on main and the patched tree on the same Linux llvmpipe device with Vulkan required, shader cache disabled, and validation layer 1.4.369. Both logs show layer insertion and no missing-layer diagnostic or `VUID-` entry. A Linux fixture that selected the macOS fallback passed 20,052 conversion comparisons and caller-state checks. Native macOS remains outside this run. AI-assisted: yes.

Pull request closed

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!27767
No description provided.