feat(libc): implement the std::__sce_v2 unsigned short facet virtuals #17607
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17607"
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-09T01:04:04Z.
What
Builds on #17578: this branch contains its commits, and through them #17568, #17539, #17331, #17296, #17277, #16975, #16949, #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current
main. It reuses thewchar_tvirtuals those PRs add, so it cannot stand alone. Until they merge, only the last commit is this PR's change.Implement the virtuals of the thirteen
unsigned shortfacets that_Makeushlocbuilds:ctype,codecvt,num_get,num_put,numpunct,collate,messages,money_get,money_put, bothmoneypunct,time_getandtime_put. Before this PR, each of their slots past the four lifetime ones threwNotImplemented_nid_no_patch. These slots are not exports, so this PR adds no NID. With it, every facet_Makelocbuilds has its virtuals.In the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), theunsigned shortvtables (0x18D450to0x18DAB0) point to a second instantiation of thewchar_tcode. Slot for slot, the functions have the same sizes, and the facets they look up are theunsigned shortctype,numpunctandmoneypunct. So this PR instantiates the existing templates forstd::uint16_t:SceV2TextFacets<std::uint16_t>selects theunsigned shortctypeandnumpunct, andmoney_get,money_puttheunsigned shortmoneypunct.numpunct, bothmoneypunctandtime_getkeep theirunsigned shortdestructors, which free the strings these facets copy.char16_tvirtuals convert to the instantiation's unit type where the two meet.collate<unsigned short>::do_compareis the one virtual whose code differs. The module does not call_Wcscollas thewchar_tfacet does: it walks both ranges unit by unit until an end pointer, then orders a prefix first. This PR does the same. As in the module, a range of an odd byte count therefore reads past its end. The module'sdo_transformof exactly 15 bytes never returns, because its terminator lands on the string's size, and this library returns the 7 zero units it returns for every odd count. The debt entries record both.Tested
Windows 11, MinGW GCC 15.2, Release, head on top of #17578. Not run on Linux or macOS, not run in a title.
guest_sce_v2_ushort_facets:ctype<unsigned short>id and checks thatcodecvt<unsigned short>sits twelve places later, as_Makeushlocregisters them;widenandis,truename,num_putandnum_getof along,collateorder with a prefix,messages::open,money_putandmoney_getof digits,curr_symbol,get_timeand a case-insensitiveget_monthname,time_put's%Yandalways_noconv.wchar_tfacets, run against the module's own code, loaded and relocated.USHORTset, each places, after_Makeloc, everyunsigned shortfacet in the slot of itswchar_ttwin in both libraries' locales. The two libraries register theunsigned shortfacets at the same indices (27 to 39).codecvt,messages,money_get,money_put,num_getwith integers and with floating point,time_getandtime_put: 100,000 calls each, 0 differences.money_get,money_putandtime_putran with the module's_Stod,sprintf_s,strftimeandwcsftimeredirected to this library's, as in their PRs.num_putwithctypeandnumpunct: 300,000 calls over 3 seeds, 0 differences. This harness first built only thewchar_tfacets (_Makewloc), so its first run never reached theunsigned shortones; it now builds every facet with_Makeloc.collateandmoneypunct: 300,000 calls over 3 seeds, 0 differences. The first runs found the walk-until-enddo_compareand hung on the 15-bytedo_transform. Forunsigned short, the harness now givesdo_compareeven byte counts and leaves 15 bytes out ofdo_transform.guest_fopen_errorsskipped.do_compare's prefix ordering is caught by the harness (106 differences in 20,000 calls) and, once the test gained a prefix case, by the test.check_conventions,git diff --check: clean. Merges cleanly withmain.pr_overlapreports no open PR with the same functions or conflicting code. It could not compare 48 PRs that conflict withmainon shared files. None of the 4 that touchLocaleSupport.cpp(#9526, #11172, #12518 and #12704) touches anunsigned shortfacet.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-20T11:51:51Z.
Review: DISMISSED
Reviewed — changes requested
The unsigned short
collate::compareimplementation can read beyond an odd-byte input range and fail to reach its endpoint.What I ran
Reviewed head
1d1de07cc250651d64637f8745d6d7953c31578a. No commands or tests were run; no merged-preview check was performed.Results
Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:770:SceV2UshortCollateCompare_nid_no_patchadvancesuint16_tpointers until they equal the supplied endpoints. For an odd-byte range, advancing by two bytes can pass the endpoint, so the loop can dereference beyond the range and continue beyond its end. Validate and handle the byte lengths before walking units, or otherwise ensure the walk cannot overshoot the supplied range.Non-blocking
core/libs/prx/libc/src/LocaleSupport.cpp:1318has a related odd-bytedo_transformbehavior noted in the description and technical debt; that code returns zero units for odd byte counts.Sources
Not verified
No tests, builds, console behavior, or operating systems were checked. Read the PR description, commits, diff, manifest,
GuestLocale.hpp,LocaleSupport.cppranges 1190–1360 and 2260–2555, andGuestSceV2UshortFacets.cpp. The prepared file listing showed all 17 changed files included; the remaining changed files were not read. No excluded files were reported in the listing.To get this to a good state
Handle odd-byte compare ranges without reading beyond the range, then rerun the relevant facet tests and checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:22:36Z.
Review: COMMENTED
Reviewed — no blocking findings
The unsigned-short facets are wired into the locale, but I did not complete the full review of the implementation and related tests, so approval is not justified.
What I ran
Inspected the prepared diff and targeted source at head
df8b74d141a8e473df55b13465e93eb6477abe98; no commands or tests were run.Results
Findings
Blocking
None established from the inspected sections.
Non-blocking
core/libs/prx/libc/src/LocaleSupport.cpp:1107:codecvt::inignores its caller-provided conversion state and initializes a fresh local state on each call. Please confirm this matches the supported locale behavior, or preserve the supplied state; add a test that splits a stateful multibyte sequence across calls.Not verified
The diff and repository context were read only in part. Read:
review/description.md,review/commits.md,review/manifest.json, the first 700 lines ofreview/diff.patch,core/libs/prx/libc/include/GuestLocale.hpp(changed lines shown in the diff), selected ranges ofcore/libs/prx/libc/src/LocaleSupport.cpp, andcore/libs/tests/GuestSceV2UshortFacets.cpp. The changed files listed as included in the manifest but not read in full includecore/libs/prx/libc/CMakeLists.txt, the remainder ofLocaleSupport.cpp, the other changed test files, anddocs/dev/debt/libc.md. No programmatic checks, negative control, Linux/macOS run, or console run was performed. The description's test results are author-reported, not independently verified.To get this to a good state
Nothing is required. Optional: clarify the intended
codecvt::instate handling and test split multibyte input. Complete the remaining source review before making a formal approval decision.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:39:26Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
77472bedad5e65e612048e5e7a8650b938f640b6using the prepared review bundle and the pinnedrepo_read.pyreader. No commands or tests were run; no merged-preview check was performed. The author reports Windows 11/MinGW GCC 15.2 tests in the description; those results were not independently verified.Results
Findings
Blocking
None verified in the portions inspected. The review is incomplete, so this is not a finding that the unread changes are defect-free.
Non-blocking
Complete review of the remaining changed files before relying on this review for a merge decision.
Not verified
Read:
description.md,commits.md, part ofmanifest.json, the first 300 lines ofdiff.patch, and targeted repository content fromGuestLocale.hpp,LocaleSupport.cpp, anddocs/dev/debt/libc.md. The available output did not expose all requested targeted ranges, so complete content review of these files is not verified.Not read: full texts of
CMakeLists.txt,GuestSceV2CharFacetVirtuals.cpp,GuestSceV2CodecvtWide.cpp,GuestSceV2CollateMoneypunct.cpp,GuestSceV2Messages.cpp,GuestSceV2MoneyGet.cpp,GuestSceV2MoneyPut.cpp,GuestSceV2NumGetChar.cpp,GuestSceV2NumGetWide.cpp,GuestSceV2NumPutChar.cpp,GuestSceV2NumPutWide.cpp,GuestSceV2TimeGet.cpp,GuestSceV2TimePut.cpp, andGuestSceV2UshortFacets.cpp.files.jsonwas not available through the reader; the review-folder listing showed all 16 changed files as included.To get this to a good state
Nothing is required. Optional: finish reading the changed files and run the relevant checks before making a formal merge decision.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:24Z.
Review: COMMENTED
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused
GuestSceV2UshortFacetsfixture 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.