feat(libc): implement the std::__sce_v2 codecvt virtuals for wchar_t #16975
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16975"
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-08T03:18:37Z.
What
Builds on #16949: this branch contains its commits, and through them #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current
main. It needs none of their code, only their place inLocaleSupport.cpp, so it stacks to avoid conflicts. Until they merge, only the last commit is this PR's change.Implement the seven virtuals of
std::__sce_v2::codecvt<wchar_t, char, mbstate_t>, which_Makewlocbuilds and every wide stream uses to convert betweenwchar_tand multibyte text. Before this PR, each of them threwNotImplemented_nid_no_patch. These slots are not exports, so this PR adds no NID.The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), vtable0x18D3D0:do_always_noconvis false.do_max_lengthreturns the first word of the facet's conversion data, anddo_encodingis 1 when that word is 1 and 0 otherwise.do_inconverts withmbrtowcfrom a clean state of its own and leaves the given state untouched. A null byte counts as one byte. It returnspartialwhen the output is full or a sequence is incomplete, anderroron an invalid sequence.do_outconverts withwcrtombon the given state, directly into the output while at least 6 bytes are left. Closer to the end it converts into a buffer and, when the sequence does not fit, restores the state and stops. It returnspartialwhile input is left.do_unshiftconverts a null character and writes the bytes before the terminator. When they do not fit it restores the state and returnspartial.do_lengthconverts at most the given count of characters on the given state, counts a null byte as one, stops at an invalid or incomplete sequence, and returns the bytes read capped atINT_MAX.The module calls its
_Mbrtowcand_Wcrtomb, which wrapmbrtowcandwcrtomb. This library has no such exports, so it callsmbrtowcandwcrtombas its widectypealready does. A new debt entry records that, and the_Makelocentry lists the facet among the working ones.Tested
Windows 11, MinGW GCC 15.2, Release, head on top of #16949. Not run on Linux or macOS, not run in a title.
guest_sce_v2_codecvt_wide: every slot; two- and three-byte sequences; incomplete and invalid input; full output; null bytes; exact and short output room; and a state holding a pending sequence, whichdo_inignores anddo_lengthcontinues. It passes, as doguest_sce_v2_num_get_wide,guest_sce_v2_num_get_char,guest_sce_v2_num_put_char,guest_sce_v2_num_put_wide,guest_sce_v2_char_facet_virtuals,guest_sce_v2_makeloc,guest_sce_v2_locale,guest_sce_v2_locale_basics,guest_sce_v2_locimp_references,guest_sce_v2_facet_ids,guest_locale,guest_sce_v2_exceptions,guest_sce_v2_string_to_integerandpublic_headers(15 of 15)._Makeloc. Inputs: random multibyte text with ASCII, null bytes, valid, truncated, overlong and surrogate sequences; random 16-bit text with surrogates; output rooms from 0 to 63; counts up to 2^64; and initial states that are clean, have one random byte, or are random. It compares the result, both next pointers, the output buffers with two bytes past their end, the state's 32 bytes anderrno.mbrtowcandwcrtombredirected to this library's: 400,000 calls over 2 seeds, 0 differences.do_lengthfrom a nonzero initial state, where the two libraries'mbrtowcread a state they did not write differently.do_in,do_out,do_unshiftanddo_lengthwith output rooms of 0 to 6, as a stream converting piece by piece does: 300,000 chains over 3 more seeds with the redirected functions and 20,000 with the module's own, 0 differences.select_tests_MissingCommandTests, which cannot create a symbolic link without Windows' privilege, andvulkan_validation_gate_commands, a script test this PR does not touch.do_unshiftterminator. The other 4 make no difference with this library's conversions:do_max_lengthis always 1,wcrtombleaves the state unchanged so restoring it has no effect, no 16-bit character needs more than 3 bytes, anddo_unshiftfrom an initial state never runs out of room.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 37 PRs that conflict withmainon shared files, and of the 4 that touchLocaleSupport.cpp(#9526, #11172, #12518, #12704) none adds these virtuals. #11172 wires the exported vtable of the unversionedstd::codecvt<wchar_t, char, _Mbstatet>, a different facet from this one.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-21T07:18:51Z.
Review: COMMENTED
Reviewed — no blocking findings
The codecvt implementation and its focused test were inspected at head
dd05a6107ba07214a6e84ed6f16e68b7533c7839; the review is incomplete, so a formal approval is not justified.What I ran
No commands or tests were run. I read the prepared description, commit list, diff, manifest,
GuestLocale.hpp,LocaleSupport.cpparound the new codecvt implementation, andGuestSceV2CodecvtWide.cpp.Results
Findings
Blocking
None verified in the inspected codecvt implementation.
Non-blocking
None.
Not verified
The remaining six changed files were not read:
CMakeLists.txt, the other five test files, anddocs/dev/debt/libc.md. The submitted Windows test, differential harness, full suite, negative-control mutations, and console behavior were not independently run or confirmed. The prepared description reports that Linux, macOS, and title execution were not tested.To get this to a good state
Nothing is required. Optional: complete review of the six unread changed files and independently run the relevant checks.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:38Z.
Review: COMMENTED
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused
GuestSceV2CodecvtWidefixture 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.