feat(libc): implement the std::__sce_v2 ctype, numpunct and codecvt virtuals for char #16214
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16214"
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-05T20:53:25Z.
What
Builds on #16178: this branch contains its commits, and through it #16165, #16113 and #15923. Until they merge, only the last commit is this PR's change.
Implement the virtuals of the versioned
std::__sce_v2ctype<char>,numpunct<char>andcodecvt<char>facets that_Makelocbuilds. Before this PR, each of them threwNotImplemented_nid_no_patch. These slots are not exports: guest code reaches them through the facet's vtable, so this PR adds no NIDs.The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6). Vtable offsets are from the start of the module's vtable:ctype<char>0x18C5200x20,0x30do_tolower,do_toupper(character)_Toloweror_Toupperof the unsigned byte0x28,0x38do_tolower,do_toupper(range)0x40,0x50do_widen,do_narrow(character)do_narrowignores the fallback0x48,0x58do_widen,do_narrow(range)numpunct<char>0x18C6900x20,0x28do_decimal_point,do_thousands_sep0x30,0x38,0x40do_grouping,do_falsename,do_truenamecodecvt<char>0x18C7880x20do_always_noconvtrue0x28,0x30do_max_length,do_encoding10x38,0x40do_in,do_outnoconv(3)0x48do_unshiftnext, returnsnoconv(3)0x50do_lengthINT_MAX, then at the count, compared unsigned, so a reversed range returns the countThe versioned string is
0x20bytes: a 16-byte inline buffer or pointer, the size and the capacity. The string slots zero it first, keep up to 15 characters inline, and otherwise allocate(length | 15) + 1bytes through the existingGuestLocale::AllocateStringStorage, which adds the module's aligned header from0x1000bytes up.The unversioned
do_unshiftanddo_lengthdiffer from these:do_unshiftreturns 0 anddo_lengthhas no cap. They are unchanged, so the versioned facet has its own slots.The other virtuals still throw, so stream output through a locale built here still stops at
num_put, and the classic_Locimpstays without facets. The debt entry for_Makelocnow names the three facets whose virtuals work.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, on top of #16178 (5a8306b705d). The branch merges cleanly with main151a2cb6e27. Exact tested commit:37825601e62.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_char_facet_virtualspasses, along withguest_sce_v2_makeloc,guest_sce_v2_locimp_references,guest_sce_v2_locale,guest_sce_v2_locale_basics,guest_sce_v2_facet_ids,guest_locale,guest_sce_v2_exceptionsandpublic_headers.The new test gets the facets from
_Makelocand calls each slot through the vtable. It checks:0x1000allocation limit: size, capacity, text, and zeroed inline bytes;codecvtconstants andnoconvresults, with buffers and state left alone, anddo_lengthat the count, the range, the cap and a reversed range.The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel. The module's heap is not set up outside a console process, so its allocation calls were redirected to the host's.
Side by side with the patched production library, with facets built by each side's
_Makeloc, over two seeds with 200,000 random steps each:0x2000bytes, comparing size, capacity, text, inline bytes, large-block alignment and the sequence of allocation sizes;do_inanddo_out,do_unshift, anddo_lengthwith edge values aroundINT_MAXand reversed ranges.No comparison differed. #16178's side-by-side run also still passes with one seed.
The tests were also run once with the test heap filling each block with
0xDDbefore freeing it, to catch reads of freed memory on Windows. They passed. That change is not committed.Negative control: six lines were altered one at a time:
do_tolowerleft its character unchanged;do_widenrange returned its start;do_truenamereadfalsename;do_unshiftreturned 0;do_lengthlost its cap.CTest failed on each, and the side-by-side run reported differences each time. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,909 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 31 branches that already conflict with main. Merging each of the 31 with this branch and with main usinggit merge-treegives the same conflict blocks in the files this PR touches; the differences it lists for #10253, #11831 and #14212 are in other files and come from main moving since this branch's base. The debt edit adds no conflict over #16178 with any of the 142 open PRs that touch that file. Other open PRs add unversionedctype,numpunctandcodecvtnames, inlibcandlibSceLibcInternal, and none adds these versioned slots. The branch also merges cleanly with all 23 open PRs of this author.Not tested: Linux, macOS, another SDK, a game, GPU or console. The other facet virtuals still throw. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.
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:08:06Z.
Review: APPROVED
Reviewed — looks good
The reviewed code implements the described versioned
charfacet virtuals; I found no concrete defect in the inspected changes.What I ran
Read the prepared diff and changed files at head
9a765a75fc6cd489a6af4b6017176f4c78290427. I did not run build or tests; the checks in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/src/LocaleSupport.cpp,core/libs/tests/GuestSceV2CharFacetVirtuals.cpp, anddocs/dev/debt/libc.md; all four changed files listed in the manifest were included and read. I did not independently verify the bundled module behavior, the reported test/build runs, or behavior on other platforms and consoles.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:21:08Z.
Review: COMMENTED
Built the branch locale implementation and matching headers against the existing Linux runtime. The focused character facet fixture 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.