feat(libc): implement collate<wchar_t>::_Getcat for the C locale #4409

Closed
ahmad3a4 wants to merge 1 commit from upstream-pr/4409 into main
ahmad3a4 commented 2026-10-12 09:48:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmad3a4 on 2026-10-12T09:48:11Z.


What

std::collate<wchar_t>::_Getcat was a NotImplemented stub, so use_facet<collate<wchar_t>> (and anything built on it, such as wide std::regex or std::locale::operator() on wstring) stopped the title.

It now does what the narrow collate<char>::_Getcat already does: for the C locale it allocates a CollateFacet with operator new and returns category 1. Any other locale name throws, as on the narrow side. The facet gets a wide vtable that reuses the narrow destroy, delete, retain and release entries. Guest wchar_t is char16_t:

  • do_compare orders UTF-16 code units lexicographically and returns -1, 0 or 1, the same code-unit order as the narrow memcmp path.
  • do_transform copies the range into the guest wstring: inline up to 7 code units, otherwise a (length + 1) * 2 byte operator new block. The narrow facet's limits apply: embedded nulls throw, and a result whose buffer would reach the 0x1000-byte large-allocation path (2047 code units or more) throws instead of guessing that allocator.
  • do_hash is the narrow FNV-1a over code units, so a single-byte-ASCII string hashes the same in both facets.

GuestLocale.hpp gains WideString and WideCollateVtable, with static_asserts on the offsets the guest reads.

guest_collate now also covers the wide facet: _Getcat with a null and an existing facet, a non-C locale, compare with equal, prefix, accented, non-BMP surrogate and embedded-null ranges, invalid ranges, hash, transform at 0, 5, 7 and 8 code units and at 2046 and 2047, embedded nulls, a null result, and retain, release and delete of the facet.

Tested

Windows 11, WinLibs GCC 15.2.0 (UCRT), Release, BUILD_TESTING=ON, based on main 9aa5fd29: full build and full ctest pass (943 tests, 6 of them skipped by their own environment checks), and the NID patch of libc.prx succeeds. Linux not tested. No title or homebrew run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4827689156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4409). Originally posted by [ahmad3a4](https://github.com/ahmad3a4) on 2026-10-12T09:48:11Z. --- ### What `std::collate<wchar_t>::_Getcat` was a `NotImplemented` stub, so `use_facet<collate<wchar_t>>` (and anything built on it, such as wide `std::regex` or `std::locale::operator()` on `wstring`) stopped the title. It now does what the narrow `collate<char>::_Getcat` already does: for the C locale it allocates a `CollateFacet` with `operator new` and returns category 1. Any other locale name throws, as on the narrow side. The facet gets a wide vtable that reuses the narrow destroy, delete, retain and release entries. Guest `wchar_t` is `char16_t`: - `do_compare` orders UTF-16 code units lexicographically and returns -1, 0 or 1, the same code-unit order as the narrow `memcmp` path. - `do_transform` copies the range into the guest `wstring`: inline up to 7 code units, otherwise a `(length + 1) * 2` byte `operator new` block. The narrow facet's limits apply: embedded nulls throw, and a result whose buffer would reach the 0x1000-byte large-allocation path (2047 code units or more) throws instead of guessing that allocator. - `do_hash` is the narrow FNV-1a over code units, so a single-byte-ASCII string hashes the same in both facets. `GuestLocale.hpp` gains `WideString` and `WideCollateVtable`, with `static_assert`s on the offsets the guest reads. `guest_collate` now also covers the wide facet: `_Getcat` with a null and an existing facet, a non-C locale, compare with equal, prefix, accented, non-BMP surrogate and embedded-null ranges, invalid ranges, hash, transform at 0, 5, 7 and 8 code units and at 2046 and 2047, embedded nulls, a null result, and retain, release and delete of the facet. ### Tested Windows 11, WinLibs GCC 15.2.0 (UCRT), Release, `BUILD_TESTING=ON`, based on `main` `9aa5fd29`: full build and full `ctest` pass (943 tests, 6 of them skipped by their own environment checks), and the NID patch of `libc.prx` succeeds. Linux not tested. No title or homebrew run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-13 00:22:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:22:00Z.


Closing: Unblocks is none, and nothing shows a title stopping at collate<wchar_t>::_Getcat on main; the wide vtable and wstring layout also come with no source. The code can come back as it is once there is a title ID and its log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135194720 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4409#issuecomment-6135194720). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T00:22:00Z. --- Closing: Unblocks is none, and nothing shows a title stopping at `collate<wchar_t>::_Getcat` on main; the wide vtable and `wstring` layout also come with no source. The code can come back as it is once there is a title ID and its log line.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4409
No description provided.