Repository navigation
feat(libc): implement the std::__sce_v2 num_get virtuals for char floating point - #16944
Danigamer05 wants to merge 19 commits into
Conversation
…irtuals for char The facets built by _Makeloc threw NotImplemented from every virtual except the lifecycle slots. The char ctype, numpunct and codecvt facets now answer as the console's libc.prx does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irtuals for wchar_t Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…get-char-20261107
Main removed GuestStringInlineCapacity, GuestStringCapacityMask and GuestStringLargeAllocation from LocaleSupport.cpp, so the versioned facets' strings use GuestLocale::StringInlineCapacity, GuestLocale::StringCapacityMask and GuestStringStorage::Deallocate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egers, bool and pointers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-facet-virtuals-20261105
Main removed GuestStringInlineCapacity and GuestStringCapacityMask from LocaleSupport.cpp, so AssignSceV2String uses GuestLocale::StringInlineCapacity and GuestLocale::StringCapacityMask. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t/libc-sce-v2-num-put-char-20261106
Main removed GuestStringInlineCapacity and GuestStringLargeAllocation from LocaleSupport.cpp, so TakeSceV2String tests GuestLocale::StringInlineCapacity and frees through GuestStringStorage::Deallocate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sce-v2-num-put-wide-20261107 Brings in current main through boykopovar#16516. The templated TakeSceV2String frees through GuestStringStorage::Deallocate, since main removed GuestStringLargeAllocation from LocaleSupport.cpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sce-v2-num-get-char-20261107
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ating point Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
The head does not compile on Linux x86-64 (GCC 14.2.0, libstdc++, Debian 13), and neither do the PRs stacked on it; PrivacyOnion's reviews on #17277 and #17296 show the same error at their lines. The cause is this PR's own commit: 90d09a0 adds Every PR stacked on this one contains 90d09a0 and fails the same way, at the line this moves to in each: #16949, #16975, #17277, #17296, #17331, #17539, #17568, #17578, #17607 and #17610 (checked on all eleven, this one included, merged onto current Checked with AI-assisted: yes (run and drafted with an AI agent, checked by me) |
…61108 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
std::int64_t is long on Linux x86-64 and std::llabs returns long long, so std::min could not deduce a single type and LocaleSupport.cpp did not build there. Name std::int64_t explicitly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Doorriiaann Thanks, that was the cause. Fixed in 942b87f with The fix is merged into every PR stacked on this one, one changed line each: #16949, #16975, #17277, #17296, #17331, #17539, #17568, #17578, #17607 and #17610 (top of the stack: a78c139). Checked at the top of the stack:
The description footer is gone too. AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
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
- Reviewed head
9f337f9b9bde0fc05ff6261781bbe1e2c417f807usingrepo_read.py. - No tests or build commands were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Source review | failed | Found a verified out-of-bounds write |
| Tests | not run | Author-reported tests were not run here |
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
- Read the prepared description, commits, manifest and diff, and targeted ranges in
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. - Did not run the author-reported Windows test suite or differential harness; Linux, macOS and console behavior were not verified.
To get this to a good state
- Fix the rounding path for an all-zero retained prefix and add a regression test for a nonzero digit discarded after the significant-digit limit. Rerun the relevant floating-point tests and differential harness on the new head.
|
@MarcZX10 Thanks for the review. That path can't be reached, because a zero is never counted while nothing significant has been written:
With |
A review asked whether a field whose first 768 or more digits are zeros could reach the lost-digit rounding with no kept digit, and bump the leading zero or the decimal point. It cannot: leading zeros in the integer part are not counted, and leading fraction zeros only lower the power, so the first nonzero digit is always kept. Pin that down with 800 integer zeros, 769 fraction zeros before a 1 scaled back by e770, and both together. Counting leading zeros as significant fails two of them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@MarcZX10 Added the regression test you asked for in a856bf5 (
On Windows 11 with MinGW GCC 15.2, |
MarcZX10
left a comment
There was a problem hiding this comment.
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
| Check | Result | Note |
|---|---|---|
| Code review | passed | Floating point paths inspected |
| Tests | not run | Results supplied by author |
| Build | not run | No local build performed |
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, and docs/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.
ligmaSec
left a comment
There was a problem hiding this comment.
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused GuestSceV2NumGetChar fixture passed.
AI-assisted: yes.
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 feat(libc): implement the std::__sce_v2 num_get virtuals for char integers, bool and pointers #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 feat(libc): implement the std::__sce_v2 num_get virtuals for wchar_t integers, bool and pointers #16924, which builds on feat(libc): implement the std::__sce_v2 num_get virtuals for char integers, bool and pointers #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(feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526, feat(libc): wire the codecvt<wchar_t,char> facet vtable #11172, feat(libc): export the money_put facet vtable as data #12518, feat(libc): export the wide time_put facet vtable as data #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)