feat(libc): implement the std::__sce_v2 ctype, numpunct and num_put virtuals for wchar_t #16560
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16560"
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-07T05:25:52Z.
What
Builds on #16516: this branch contains its commits, and through it #16214, #16178 and #15923. Until they merge, only the last commit is this PR's change.
Implement the
wchar_tvirtuals ofstd::__sce_v2::num_put, and of the two facets it reads,ctypeandnumpunct, all of which_Makewlocbuilds. Before this PR, each of them threwNotImplemented_nid_no_patch. These slots are not exports: guest code reaches them through the facets' vtables, so this PR adds no NID.The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6):ctype<wchar_t>0x18CD30do_is(two),do_scan_is,do_scan_not,do_tolower(two),do_toupper(two),do_widen(two),do_narrow(two)numpunct<wchar_t>0x18CE78do_decimal_point,do_thousands_sep,do_grouping,do_falsename,do_truenamenum_put<wchar_t>0x18CEE8do_putasnum_put<char>num_put<wchar_t>is thenum_put<char>of #16516 with 16-bit characters, so that code is now a template on the character type and both facets share it. The differences:overflowargument are 16 bits, and the put pointer moves by two bytes. Theintcount still counts characters.numpunct<wchar_t>returns its names in a 16-bit string with 7 inline characters, andgroupingstays a narrow string.do_widenfor a range, so a replacedctypefacet is honored.In
ctype<wchar_t>:do_islooks up the table withdo_narrow(c, 0)through the vtable, anddo_scan_isanddo_scan_notcalldo_isthrough the vtable.do_widencallsmbrtowcwith a clean state for one byte and gives0xFFFFif that fails.do_narrowcallswcrtomband gives the fallback unless the result is one byte.The
unsigned shortfacets and the other versioned virtuals still throw. The_Makelocdebt entry names what works now, and thenum_putentry covers both facets and one new gap: along doublewithout its explicit integer bit printsnanwhere the module prints digits.Tested
Windows 11, MinGW GCC 15.2, Release, head on top of #16516. Not run on Linux or macOS, not run in a title.
guest_sce_v2_num_put_wide: every slot of the three facets, flags, adjustment, grouping, non-ASCII fill and separators, non-finite values, names inline, on the heap and in a large allocation, the put count,overflowand failure paths, invalid bytes, fallbacks, and virtual dispatch. It passes, as doguest_sce_v2_num_put_char,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_exceptionsandpublic_headers(11 of 11)._Makewloc: random flags, widths, fills, precisions, grouping strings, names of up to 3,000 characters, separators, buffer states, a locale without facets, everychar16_tclass including surrogates and invalid bytes. It compares the written characters, the count, the returned iterator or pointer,width,flags,precision,errnoforctype, string size and capacity, allocation sizes, and the order of thectypeandnumpunctvirtual calls.sprintf_sredirected to this library's, so only these facets are compared: 400,000 calls over 2 seeds (about 300,000num_put, 50,000ctype, 50,000numpunct), 0 differences.sprintf_s: 3,031 of 200,000 calls differ, 586doubleand 2,445long double; integer,bool, pointer,ctypeandnumpunctcalls do not differ. Of these, 1,846 arelong doublevalues without the explicit integer bit, printed asnanhere, which is the new debt line. By the classification I ran, the other 1,185 keep the samenanstate and I read samples that differ in digits, as the%e, %f and %gdebt entry describes.charregression after the refactor, on the harnesses of #16516 and #16214: 200,000num_put<char>calls and 100,256ctype,numpunctandcodecvtcalls, 0 differences.do_scan_not, the one that ran only against the test. Theshowpointclear on a non-finite value stays unobservable here, as #16516 explains, and is not in this list.length_errorpaths and thebad_allocpath.check_conventions,git diff --check: clean. Merges cleanly withmain4ba64592376.pr_overlapreports no open PR with the same functions; it could not compare 43 PRs that conflict withmainon shared files. Of those, the 5 that touchLocaleSupport.cpporGuestLocale.hpp(#7081, #9526, #11172, #12518, #12704) do not add these virtuals. No open PR found by searching for the versionedwchar_tfacets.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 gabichuuuuu on 2026-11-07T23:15:51Z.
Review: COMMENTED
Read
8ac2d3a15dagainstmain. Onlyf9b29a9a5aand the merge on top of #16516's head are this PR's.Character width. A 16-bit
wchar_tagrees with the rest of libc, which declares the wide stdio andmbrtowc/wcrtombonchar16_t/uint16_tinApi.hpp.SceV2BasicString<char16_t>keeps the 0x20 layout with 7 inline characters and capacitylength | 7, Dinkumware's allocation mask for 2-byte elements, and an overflow result is compared with -1, the same WEOF the wide stdio here uses.Slots.
ctype<wchar_t>has its 12 virtuals in declaration order,numpunct<wchar_t>keepsgroupingnarrow, and thecharinstantiation of the templatednum_putbehaves as #16516's did. The put pointer moves bysizeof(Text)and the count counts characters.Question, not blocking.
do_isclassifies throughdo_narrow(c, 0)and the 256-entry table, so a character that doesn't narrow to one byte gets the class of'\0', where the public Dinkumware source calls_Getwctype(microsoft/STLstl/inc/xlocale:2940-2942). The description says the module does the table lookup and the harness covered everychar16_tclass, so I'm only noting that this departs from the public source on purpose.Not run here; this is from reading the code.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:26:45Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the source reviewed; the checks reported by the author were not run here.
What I ran
Reviewed head
e9662cf7b67b52da526ce24a8340c50d95f9ee86from the prepared diff and pinned reader. The description reports a clean merge withmainat4ba64592376. No commands or tests were run in this review.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
Build, tests, and the differential harness were not run in this review. The reported Windows 11 and MinGW GCC 15.2 results, console behavior, other host operating systems, and the excluded
length_errorandbad_allocpaths were not independently verified. All seven changed files marked included in the manifest were 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/GuestSceV2NumPutChar.cpp,core/libs/tests/GuestSceV2NumPutWide.cpp, anddocs/dev/debt/libc.md. No changed files were excluded by the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:44Z.
Review: COMMENTED
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused
GuestSceV2NumPutWidefixture 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.