feat(libc): implement collate<wchar_t>::_Getcat #5662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5662"
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 Roojool on 2026-10-14T05:13:58Z.
What
collate<wchar_t>::_Getcatis implemented, so the guest wide collation facet is built instead of throwing.The implementation is the narrow one, copied from
_ZNSt7collateIcE7_GetcatEPPKNSt6locale5facetEPKS1_that sits next to it in the same file: allocate aGuestLocale::CollateFacet(0x20 bytes) through the guest'soperator new, leave the two collation-table words at offsets 0x10 and 0x18 null, publish the base facet with a zero reference count, and throwstd::invalid_argument("collate::_Getcat: only the C locale is supported")for a null locale, a null implementation, a null name or any name other than"C". Both entry points returnsize_tand answer 1, which is the facet id the C locale's single category uses.GuestLocalemodels one facet layout and oneCollateVtablefor both element types, so the wide facet carries the narrow vtable and acollate<wchar_t>comparison, transform or hash runs the narrowdo_compare,do_transformanddo_hashover the guest's 16-bit characters read as bytes. The console'slibc.prxexports both_Getcat(NIDs2wz4rthdiy8andBSVJqITGCyI) over the same facet, but its wide vtable is not reproduced here; the debt entry records this, the console's null collation-table pointers, and that no module of the PPSA59322, PPSA76677 or PPSA97358 dumps in this tree imports either symbol, so nothing here has been exercised by a title.std::_Atomic_assert(_ZSt14_Atomic_assertPKcS0_, NIDu2tMGOLaqnE) is not part of this PR. The search for its definition came back empty: GCC'slibstdc++has no_Atomic_assertin any release from 4.5.4 to 16.2 or in its ChangeLog from 2007 to 2022, and neither does LLVM'slibc++fromrelease/3.2.xto current. It stays theNotImplemented_nid_no_patchstub rather than gaining an invented message shape.Tested
guest_collategrowsCheckWideGetcat, which mirrors the narrow case: a nullfacetargument returns 1 without allocating, an existing facet is left alone, a non-C name, a null name and a null implementation all throw without allocating, the C locale allocates exactly one 0x20-byte facet whose vtable is the narrow one and whose two collation words are null, compare and hash answer through that vtable, an invalid character range throws, and retain/release/destroy/deleteObject behave as for the narrow facet. On unmodifiedmain(0aa4cb1c2) with only this test file applied the test fails withstd::runtime_error: _ZNSt7collateIwE7_GetcatEPPKNSt6locale5facetEPKS1__nid_postfix not implemented; with the change it passes.guest_collatepasses 3 runs, and the neighbour suites pass 10/10 (guest_locale,guest_rune_locale,guest_strftime,guest_time_conversion,guest_wcsrtombs,guest_wcsrtombs_s,guest_wide_conversion,guest_generic_category,guest_character). The exception ABI suites pass 22/22;guest_exception_handlerreports "Not Run" on this branch and on the base alike because the focused Windows runs built only the named targets, not its test binary; it is not a regression.guest_collatepasses 1/1 and the same ten neighbour suites pass 10/10 twice.python tools/check_conventions.py --base refs/remotes/upstream/mainpasses;python tools/check_test_registration.py build-g15reports 786 test executables with none unregistered.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-14T05:14:03Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T05:15:01Z.
Progress report (
d92a8da→3dffc8c)📈 System libraries: 88.75% (+0.04%, +4 implemented functions)
✅ 4 implemented
WideCollateCompareWideCollateHashWideCollateTransform_ZNSt7collateIwE7_GetcatEPPKNSt6locale5facetEPKS1__nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:46:52Z.
Review: CHANGES_REQUESTED
Thanks for the PR. One blocking point:
core/libs/prx/libc/src/LocaleSupport.cpp:278: the wide facet is published with the narrowg_collateVtable, so anycollate<wchar_t>compare/transform/hashruns the narrow code over 16-bit characters read as bytes. That returns plausible but wrong results instead of throwing (e.g. little-endian byte order gives a different ordering for characters above 0xFF,hashdiffers from a wide hash, anddo_transformthrows on the zero high byte of every ASCII wide character). Exact-or-throw applies (CONTRIBUTING): either add a wide vtable with 16-bitdo_compare/do_transform/do_hash, or make the wide vtable entries throw until they are implemented, and document that in the debt entry.core/libs/tests/GuestCollate.cpp:101-108: the wide test only compares narrow ASCII strings through the narrow vtable, so it pins the behaviour above. Once the wide vtable exists, add rows withwchar_t-width data (a character >0xFF, an embedded high byte).Welcome to push again with that addressed.
Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-14T18:31:54Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T19:24:43Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL62-63docs/dev/debt/libc.mdL62-63core/libs/prx/libc/src/LocaleSupport.cppL273-275Some 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.
docs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestCollate.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-15T05:40:36Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-15T05:41:01Z.
Addressed with the real wide vtable (option 1), pushed as a second commit.
collate<wchar_t>now publishesg_wideCollateVtablewith 16-bitdo_compare(lexicographic wchar ordering, then length),do_transform(character copy) anddo_hash(one FNV-1a round per character, so wide text below 0x100 hashes like its narrow spelling). The dispatch convention was verified first: ranges arriving at the vtable are guest 16-bitwchar_twith character counts — the old narrow-vtable behavior proves it (do_transformthrew on every ASCII wide string via the null high byte;do_compare(u"\u0100", u"\u0001")returned -1 on bytes0x00vs0x01).The new test rows pin exactly your cases: a character above 0xFF (ordering now differs from byte-wise), an embedded high byte, and wide hash/transform. They fail on the previous head and pass with the fix (Windows + WSL, plus 9 locale neighbours on both). The debt entry keeps the derived-not-measured honesty, including the hash-widening judgement call and the byte-sized wide-string limitation.
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T08:59:20Z.
Windows run of head
3dffc8ca9alone, merged ontomaind92a8dad3(clean merge; it also merges cleanly onto the newerdb81992c5, not built).libspass with 0 errors. No warnings in the files this PR touches; the 5 warnings in the build are the same as onmain.--repeat until-fail:3:guest_collate: 3/3.core/libs/prx/libc/CMakeLists.txt(locale, wide-string, strftime, exception-vtable and the rest): 282/282 runs.guest_collate_tests.exewithmain'slibc.prxaborts withwhat(): _ZNSt7collateIwE7_GetcatEPPKNSt6locale5facetEPKS1__nid_postfix not implemented; with this PR'slibc.prxit passes.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 813/814.hardware_oracle_comparehit its 20 s timeout while the host was busy and passed when rerun alone.tools/check_conventions.pyandgit diff --checkpass.Titles: catalog homebrew, each relinked with that side's own relinker and libs, 60 s in a window (
ANYPS5_REQUIRE_DISPLAY=1) with no input.maind92a8dad3ccleste | FPS: 79.14 (3586), no stop lineccleste | FPS: 65.85 (4394), no stop lineRommPS | FPS: 43.63 (1909), no stop lineRommPS | FPS: 27.82 (1876), no stop line0xC0000409, no frame0xC0000409, no frameXPSemu stops the same way on both sides. Its own log (
data/xemu/xemu.log) ends with:That is the geometry-VGPR stop of #5604, not a
collatestop. None of the three titles imports2wz4rthdiy8orBSVJqITGCyI(each loads its ownlibc.prx), as the PR body says, so the title runs only show that nothing regressed.The second commit addresses both points of @adriadam10's review: the wide facet now has its own vtable (the test checks it differs from the narrow one), and there are rows with characters above 0xFF, an embedded high byte, and wide hash and transform.
One thing I would check before merging.
WideCollateTransformsizes the result in bytes: foru"abc"the test expectssize == 6andcapacity == 14. The narrow transform next to it follows the Dinkumware/MSVCbasic_stringlayout exactly (inline capacity 15,length | 15, the 0x1000 threshold with 0x27 padding). In that layout, size and capacity count elements. For a 2-byte element the inline buffer holds 8 elements, the small-string capacity is 7 and the round-up mask is 7, and the string counts as heap-allocated once capacity exceeds 7 (MSVC STL_String_val::_BUF_SIZE,_Alloc_maskand_Large_mode_engaged). A gueststd::wstringlaid out like that would treat capacity 14 as a heap string, read the first 8 bytes ofabcas its pointer, and reportsize()6. If the wide string uses the same library as the narrow one, the values would besize = 3, capacity 7 inline, andlength | 7with(capacity + 1) * 2bytes on the heap. I have not checked this on a console, and no local title reaches this code.Minor points:
Verdict: on Windows the build, the tests (including the negative control) and the non-GPU suite pass, and the three titles behave as on
main. The review points are addressed. The remaining question is the byte-sized widetransformresult.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:45:04Z.
Review: APPROVED
Checked the new 16-bit
g_wideCollateVtable(LocaleSupport.cpp:160-220): compare by value then length, transform sized in bytes with a 16-bit terminator, hash one round per character. The wide rows inguest_collate(characters above 0xFF, embedded high byte) fail on main without the change and pass here; local build + ctest 105/105 green, and the Windows run by @screamm covers MinGW. Merging.