feat(libc): implement collate<char>::_Getcat #885
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/885"
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 adriadam10 on 2026-10-06T12:54:31Z.
What
Implements
std::collate<char>::_Getcat(libc,BSVJqITGCyI), which was aNotImplementedstub. Astro's Playroom imports it.collate<wchar_t>::_Getcatstill throws.Everything below comes from the disassembly of the console's
libc.prx(the copy in Astro's Playroom'ssce_module/). No emulator implements this function:_Getcat(const facet** ppf, const locale* ploc)returns 1 (_X_COLLATE). It builds a facet only whenppfis non-null and*ppfis null. The facet is a 0x20-byteoperator newallocation: vtable, reference count 0, then two pointers to libc's collation state at 0x10 and 0x18.operator delete),_Incref(lock xadd +1),_Decref(lock xadd -1, which returnsthiswhen the old count was 1), thendo_compare,do_transformanddo_hash.do_comparecompares the two ranges one null-terminated segment at a time with the locale'sstrcolland returns -1, 0 or 1. In the C localestrcollisstrcmp, so the result is the lexicographic order of the unsigned bytes, with the shorter range first on a tie. The tests cover embedded nulls,0x80, and a prefix of the other range.do_hashis 64-bit FNV-1a over the bytes, the same as MS STL'scollate::do_hash, which comes from the same Dinkumware line. The tests check it against the FNV reference vectors ("","a","foobar").do_transformreturns a gueststd::string: 0x28 bytes, with a 16-byte inline buffer at 0x8, the size at 0x18 and the capacity at 0x20. Results longer than 15 characters are allocated withoperator new(capacity + 1). In the C locale the result is a copy of the input.What still throws, listed in TechnicalDebt: locales other than "C";
do_transformon input with embedded nulls, which the console drops depending on the output buffer size; anddo_transformresults of 4095 characters or more. For those, the guest's string deallocation expects the over-aligned large-allocation header (it reads the real pointer fromp[-1]whencapacity + 1 >= 0x1000). The two collation-state pointers are left null, because only the facet's own functions read them.Tested
Linux, new
guest_collatectest (core/libs/tests/GuestCollate.cpp). It installs an allocator throughApplicationHeapRegisterand calls through the facet's vtable the way guest code does. It covers_Getcat(nullppf, an existing facet left alone, a non-C locale rejected, the allocation size), compare, hash, and transform (inline, exactly 15 characters, heap, 4094 characters, rejected inputs). It also covers the Incref/Decref pair down to the deleting destructor. The test fails onmain, where the stub throws. All 17 mutations of the implementation make it fail. Full Release build (GCC) andctest -R 'guest_|collate|locale|application_heap'pass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T12:54:56Z.
Progress report (
5895ea7→a546bbe)📈 System libraries: 87.07% (+0.07%, +8 implemented functions)
✅ 8 implemented
CollateCompareCollateHashCollateTransformDeleteCollateDestroyCollateReleaseFacetRetainFacet_ZNSt7collateIcE7_GetcatEPPKNSt6locale5facetEPKS1__nid_postfix