feat(libc): implement the std::__sce_v2 num_get virtuals for char floating point #16944
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16944"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-08T00:00:44Z.
What
Builds on #16919: this branch contains its commits, and through it #16560, #16516, #16214, #16178 and #15923, with current
mainmerged in. Until they merge, only the last commit is this PR's change.Implement the three floating-point
do_getvirtuals ofstd::__sce_v2::num_get<char>, the last slots of the facet that still threwNotImplemented_nid_no_patch:float,doubleandlong double. These slots are not exports, so this PR adds no NID. Thewchar_tfacet of #16924 keeps throwing in these slots.The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), read from its disassembly and run. The module reads these fields in two generations of Dinkumware code, and this PR keeps both where it does:floatanddouble(0xD24C0,0xD2710) read the field with the current reader (0xD4D80, microsoft/STL's_Parse_fp_with_locale). It takes up to 768 significant digits and turns later ones into a power of ten. It reads0xhex fields withpexponents whatever the flags say, takes the decimal point fromnumpunctand writes the C locale's, and checks groups as the integer reader does. It folds the power into a clamped exponent that it writes into the field. The field is converted with_Stofor_Stodwitherrnosaved and restored. A failure assignsfailbitand stores the converted value, or 0 when nothing converted. A bad grouping fails but keeps the value.long double(0xD2960) uses the older reader (0xD69A0). Withouthexfloatit keeps 48 significant digits, rounds up on a nonzero lost digit, carries into the backstop digit with an extra power of ten, keeps 8 exponent digits and returns the power for_Stoldx. A double separator or a separator at the start ends the field, and a bad grouping empties it. Withhexfloatit calls the current reader with 36 significant digits and empties the field on a failure or a bad grouping. The value is always stored,eofbitand thenfailbitare added to the state rather than assigned, and the grouping does not setfailbitby itself.The
_Makelocdebt entry now lists all ofnum_get<char>, and thenum_getentry names the conversion functions and the module's 768-byte buffer, which a field of about 760 significant digits overruns there.Tested
Windows 11, MinGW GCC 15.2, Release, head on top of #16919. Not run on Linux or macOS, not run in a title.
guest_sce_v2_num_get_charnow also covers the three slots: decimal and hex fields, exponents, a lone zero, point orewithout digits, leading fraction zeros, overflow to infinity witherrnorestored, digits past 768, thenumpunctdecimal point, good and bad groups for both readers,hexfloatforlong double, its addedfailbit, and the carry into the backstop. Each of these inputs was also run against the module. The test passes, as doguest_sce_v2_num_put_char,guest_sce_v2_num_put_wide,guest_sce_v2_char_facet_virtuals,guest_sce_v2_makeloc,guest_sce_v2_locale,guest_sce_v2_locale_basics,guest_sce_v2_locimp_references,guest_sce_v2_facet_ids,guest_locale,guest_sce_v2_exceptions,guest_sce_v2_string_to_integerandpublic_headers(13 of 13).hexfloaton a quarter of the calls. It compares the value bytes, the state,errno, the stream's fields, the iterator and buffer state, and the order of thectype,numpunct,underflowanduflowcalls._Sto*x,_Stof,_Stodand_Stoldxredirected to this library's: 400,000 calls over 2 seeds, 0 differences.float(97) ordouble(17), which thestrtofdebt entry already describes.booland pointer regression on the harness of #16919: 50,000 calls, 0 differences.0after0x, storing leading fraction zeros, and two more exponent digits give the same converted value. The 48-digit limit and the lost-digit nudge would need a field that decides rounding past those digits.check_conventions,git diff --check: clean. Merges cleanly withmain.pr_overlapfinds no open PR with the same functions. It lists #16924, which builds on #16919 like this PR and adds thewchar_tvirtuals. Merging the two branches conflicts only in the two debt entries both rewrite; the code merges cleanly, and thewchar_tfloating-point slots keep throwing after it. Whichever merges second needsmainmerged in. It could not compare 34 PRs that conflict withmainon shared files; of those, the 4 that touchLocaleSupport.cpp(#9526, #11172, #12518, #12704) do not add these virtuals.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T12:48:33Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent out-of-bounds access when rounding a field whose significant digits were all discarded.
What I ran
9f337f9b9bde0fc05ff6261781bbe1e2c417f807usingrepo_read.py.Results
Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:3041: When the integer part has at leastmaxSignificantdigits but all are zero,significantremains zero whileoutstill points after the initial0. If the fraction then contains a nonzero digit, the fraction loop reaches the limit and setslost = truewithout writing a fraction digit. The rounding code then selectsout[-1](orout[-2]if that is the decimal point) and increments it. For input such as0.followed by 769 zeros and then1, this modifies the decimal point or the leading zero instead of a retained significant digit. Handle this all-zero retained prefix before applying the lost-digit rounding adjustment; add a regression test for a tiny nonzero value beyond the significant-digit limit.Non-blocking
None.
Not verified
LocaleSupport.cpp. The full text for changed files was excluded from the review bundle; source inspection used the pinned reader. Other changed files and behavior outside the cited code were not fully reviewed.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T21:00:06Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the code reviewed; the points below are optional.
What I ran
Reviewed head
a856bf56c1b41b6eca62a0c835cca7498bfe6531. No commands or tests were run. The reported Windows and harness results are author supplied; no merged preview was run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Read:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cpp,core/libs/tests/GuestSceV2CharFacetVirtuals.cpp,core/libs/tests/GuestSceV2NumGetChar.cpp,core/libs/tests/GuestSceV2NumPutChar.cpp,core/libs/tests/GuestSceV2NumPutWide.cpp, anddocs/dev/debt/libc.md. These are all files listed as reviewed in the manifest; no changed files were excluded. Only relevant portions of the larger files were inspected. Build and runtime behavior were not independently confirmed, including Linux, macOS, and title execution.To get this to a good state
Nothing is required. The author supplied detailed differential and regression test results; these were not independently rerun.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:42Z.
Review: COMMENTED
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused
GuestSceV2NumGetCharfixture passed.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.