feat(libc): wire the codecvt<wchar_t,char> facet vtable #11172
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11172"
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 00xDisaster on 2026-10-25T20:33:21Z.
What
Wire the exported
codecvt<wchar_t,char,_Mbstatet>vtable. #10180 added the thirteen-slot_ZTVSt7codecvtIwc9_MbstatetE_nid_postfixdata object (NIDH-TDszhsYuY,st_size104) with every slot zero, so a title that resolved the object and calledin,outorunshiftfaulted. Slots 2 through 11 now hold the same facet methods and conversion virtuals that the console uses; slot 12 (length) throws.The slot order and the conversion behaviour come from the
libc.prxbundled with PPSA03446; the size and facet layout were already recorded from PPSA26344 andlibSceLibcInternal.sprx. Slots 2 to 5 are the facet destructor, deleting destructor, retain and release; slot 6 returns false foralways_noconv; slot 7 returns 6 formax_length; slot 8 returns 0 forencoding; slots 9 to 12 arein,out,unshiftandlength. The console'sinandoutdelegate to its_Mbtowcxand_Wctombx, so this port does the same through the guest UTF-8 helpers:indecodes one- to three-byte UTF-8,outencodes one to three bytes, four-byte leads are invalid, a partial output buffer returnspartial, an invalid sequence returnserror, andunshiftclears the state.The
lengthslot throws instead of returning a character count. Standarddo_lengthconsumes input bytes rather than wide characters, and no disassembly or console run established this module's return value or its state effect, so the slot stays unsupported until that evidence exists. The debt entry records the gap._Mbtowcxand_Wctombxpreviously used the hostmbrtowc/wcrtomb, which depends on the host C locale and cannot produce the guest's three-byte UTF-8. They now use the guest helpers, and_Getpmbstateand_Getpwcstatereserve the 16-byte conversion state those helpers read and write. Slots 0 and 1 remain zero, as they were; the debt entry records that and the console's relocated offset-to-top and typeinfo entries.This does not change the narrow
codecvt<char>object in #10165, thenum_putwork in #11054, thecollate<char>object in #11166, or thefgetwcsurrogate handling in #10929, and no open PR implements these wide conversion virtuals. The only overlap is textual: #10165 resizes and moves the adjacent narrow codecvt declaration, so whichever lands second needs a rebase; this PR is listed after #10165 so the older change can land first.Tested
Linux CachyOS 7.3.0-4-cachyos, GCC 16.2.1. Base
upstream/main0836dfdf4fecb1e0326100c490476e15d3a74da5; head597258ffad.cmake --build build --target guest_locale_tests guest_multibyte_locale_tests guest_wide_conversion_tests guest_wide_formatting_tests guest_wide_string_tests guest_wide_stream_scan_tests --parallel: passed.ctest --test-dir build -R '^(guest_locale|guest_multibyte_locale|guest_wide_formatting|guest_wide_strings|guest_wide_conversion|guest_wide_stream_scan)$' --output-on-failure: 6/6 passed after the rebase.guest_localecalls the exported vtable'sin,outandunshift, checks ASCII, two- and three-byte UTF-8, an incomplete lead completed by the next call, a partial output buffer, an invalid four-byte lead, the facet retain/release slots, and that slots 0 and 1 stay zero. It callslengthand asserts that it throws.tools/check_conventions.py --base upstream/main --head HEADandgit diff --check upstream/main..HEAD: clean.write-watchjobs fail before building this PR:core/libs/tests/write_watch/CMakeLists.txtregisterswrite_watch_execute-faultandwrite_watch_read-faulttwice. The same duplicate loop is present onupstream/main; this PR does not touch that file, so it is a base-branch CI issue rather than an effect of this change.guest_localepassed in a joint 160/160 run of the libc, CesCs, Font, FreeType, LibreSsl3 and NpUniversalDataSystem suites. That run predates the refresh; the refreshed head is tested on Linux above. Not run on a PS5.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-10-25T20:42:10Z.
Review: COMMENTED
I reviewed head
6ad55bff263cb8a47ce17a2c9391b9eacc4bfbba, including the wide facet slot layout, UTF-8 conversion loops, partial-input continuation, output buffer handling, and the 16-byte guest conversion-state storage. The new tests exercise the vtable and the relevant one-, two-, and three-byte cases. I did not find a concrete correctness issue in the reviewed changes.Independent checks here: C++20 syntax compilation of
LocaleSupport.cppandGuestLocale.cpp, plusgit diff --check upstream/main...HEAD, passed. The author reports the six focused locale suites passed. Hosted conventions, labels, and report checks now pass; I do not see hosted product-build results on this head. I’m leaving a comment-only review pending runtime/build evidence rather than approving without it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T07:12:11Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes still requested
The independent Windows
guest_localeresult is helpful, but both the PR and that result use base74ac0e7912, while currentmainchanged the locale implementation, tests, and debt file.What I ran
6ad55bff26against currentmainedf6804cf52c62eacafc592dd6142cb4efe5bd05.git merge-base,git merge-tree --write-tree,git diff --name-statusfor shared paths, andgit diff --check.Results
74ac0e7912/edf6804cf57dbdf8329a4897de163318daeca6595e2599c8e9LocaleSupport.cpp,GuestLocale.cpp, anddocs/dev/debt/libc.mdguest_localepasses as part of the 160-test locale/library suite on the PR head, but its integration base predates currentmainUnedited available command output
Negative control
Findings
Blocking
mainand rerunguest_localeon the exact refreshed base and head. Main changed the locale implementation and the shared regression test since74ac0e7912, so the earlier result does not verify the current integration.Non-blocking
Sources
Not verified
main.To get this to a good state
guest_localeon current base and change, and update the exact commit hashes in the description.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:34:57Z.
Review: APPROVED
Reviewed — approved
The refreshed head merges cleanly into current
main, builds, passes the six locale suites, and the newguest_localechecks fail againstmain'sLocaleSupport.cpp. I found nothing blocking.What I ran
Head
fdc62fb1048cd66e6969b1e4819f53d979ec1ca3merged with--no-ffintomainba5b5330b37724bca4b99f30faab504653635a04in a clean worktree. Release, GCC 16.2.1, Ninja,BUILD_TESTING=ON. Arch Linux 7.2.11-zen, Intel Core i9-14900KF.Results
maingit diff --checkcheck_conventions.pyAll conventions checks passed.libclibsguest_localeagainstmain'sLocaleSupport.cpp)ctest, merged tree
MarcZX10's blocking item on
6ad55bff26asked for a rebase and a rerun ofguest_localeon currentmain. This head is rebased, and the run above is on the merge with currentmainba5b5330b3, so that item is resolved.Negative control
I restored only
core/libs/prx/libc/src/LocaleSupport.cppfromorigin/mainand kept the PR'sGuestLocale.cpp. After a rebuild,guest_localeaborted withSubprocess aborted(the test'sGuest locale check failed). With the merged file restored, it passes again.ctest, negative control
Findings
Blocking
None.
Non-blocking
_Mbtowcxstill throws where the description says the console returns a code. SeeLocaleSupport.cpp:864-871. The description says the console'sindelegates to_Mbtowcxand maps its results topartialanderror. If so, the console's_Mbtowcxreturns -2 for incomplete input and -1 for invalid input instead of aborting. The PR now routes_Mbtowcxthrough the guest helper, but it still throws on both results. The new tests atGuestLocale.cpp:244-253lock in the throws for"\xe2", a four-byte lead and"\xc3\x28". The port'sincallsmbrtowc_nid_postfixdirectly, so the facet is unaffected, but a guest that calls_Mbtowcxon a split UTF-8 sequence will abort. The throws were already there before this PR, anddocs/dev/debt/libc.mddoes not list them. Suggested fix: if the PPSA03446 disassembly confirms the codes, return -2 and -1 as the console does and assert those values in the test. Otherwise, add a debt entry for the throwing paths. This can be a follow-up.lengthreturns a character count.WideCodecvtLengthreturns the number of wide characters, and the test expects 3 for six bytes of input (GuestLocale.cpp:93). The standarddo_lengthreturns the number of bytes consumed. Older Dinkumware libraries did count characters, so this may well match the console. The debt entry says "counts characters", but it does not say that this differs from the standard. One sentence there, stating that the console behaviour was confirmed, would keep someone from "fixing" it to return bytes later.mainwithout #10165. Listing it under Depends on may hold this PR back behind an open PR it does not need. Considernone, and keep the rebase note in the text.Not verified
max_lengthvalue of 6,partialversusokwheninfills the output after converting some characters, and the character-countlength. I have no PPSA03446libc.prxdisassembly to compare against.wchar_tpaths). I ran on Linux only.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T23:34:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new
lengthimplementation and test pin a character-count result even though the PR records that the console behavior was not verified.What I ran
Reviewed exact head
c5f43513fbc745807c08b1a0d3513b476ab8c16eagainst PR baseb44985a3ea80f1e9618f7d925292229bf8f051a7. The individual merge preview against currentmainfc7c353fbcbc974d6b8af027c2769f9f63357b07was clean. The reported test base7fcab08f71e463b1768730a626a0f5472d336708is the merge base of this head and currentmain; a comparison across the 106 intervening commits found no changes to the locale source, test, debt, or multibyte helper files. Environment: Debian Linux 6.1.0-54-amd64, x86-64, Python 3.11.2; no compiler or project build was run.I also inspected the exact-head
WideCodecvtLength, its test assertions, the updated debt entry, the precheck's convention warning, and the author-reported test scope.Results
mainchanges.230cc7a59d44c2e6e9001fbae32036d466578216, plus an ASanguest_localerun. I did not independently run them. The current head adds a debt-file update after that code commit.lengthbehaviorlength(..., max=2)to return2for the six-byte inputAé€, andmax=4to return3. The pinned C++ draft defines the result as the number of external characters consumed and specifies the state effect as ifdo_inwere called. The PR's debt entry says the consolelengthbehavior was not disassembled.Unedited output from relevant checks
Precheck convention output:
Precheck aggregate result:
The precheck's ABI and test-quality helpers were unavailable in its isolated snapshot (
tools/pr_abi_audit.pyandtools/pr_test_quality.pywere not present there); those helper failures do not establish a PR defect. The source and test were inspected directly.Stack preview:
Hosted checks:
Findings
Blocking
WideCodecvtLengthreturns the number of decoded wide characters and leaves the caller's state unchanged by using a local copy. The new test locks in that behavior. The author’s latest comment acknowledges that the character-count behavior is unverified on the console, while the exact-head implementation and tests still assert it. This remains an unmeasured target-specific assertion, and it differs from the standardcodecvt::do_lengthcontract. Please either provide pinned binary/console evidence for the target's return value and state behavior and test those results, or leave this slot throwing and record the unresolved behavior until it is verified, as the repository requires for unknown behavior.Non-blocking
The debt entry exceeds the convention's 1,000-character guidance and the checker asks that it lead with the unresolved gap. This is a warning, not a check failure.
Sources
lengthimplementation at the reviewed headcodecvt::do_length, pinned to commitd4d6f38143c1b495aa33b2e5de0e0ec2daa173caNot verified
I did not build or run C++ tests locally or test on a PS5. The six focused suite results and ASan run are author-reported; the current hosted macOS jobs were still pending when checked.
To get this to a good state
Please verify
lengthagainst the pinned target binary or console, or keep this slot unsupported until its behavior is known. I will rerun the relevant checks against the new head.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:25:43Z.
Review: APPROVED
Re-checked — approved
Since
fdc62fb104, thelengthslot throws instead of returning an unverified character count, the debt entry records that gap, and the checklist now readsDepends on: none. The merged tree builds, the six locale suites pass, andguest_localestill fails againstmain'sLocaleSupport.cpp.What changed since my last review
597258ffad:WideCodecvtLengthnow only throws (codecvt<wchar_t,char>::length: console behavior unverified). The test no longer expects2/3forAé€; it now requires the slot to throw.6d06d26606: the debt entry leads with thelengthgap, names PPSA03446'slibc.prxas the source of the layout and of the_Mbtowcx/_Wctombxdelegation, and notes that offset-to-top and typeinfo stay zero.mainresolve conflicts indocs/dev/debt/libc.mdandLocaleSupport.cpp. Thein/out/unshiftcode and its tests are unchanged.Depends on: none(previously #10165), and a new Windows rerun by maskym ond7562dcc1d(guest_localepassed 3 runs; author-reported).lengthto throw until it is measured, which is now done. oneandonlydean then asked for theRequireExceptiononlengthto be removed from the test; that has not been done (see below).What I ran
Head
d7562dcc1d873ad19809c9b31d350de94db517c9merged with--no-ffintomain096c45570f516de76a43bbe1b97781381c84f55f(merged tree4d8e99a644e1bb9ff664b93f011e943a152cd705). Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.git diff --checkcheck_conventions.pyAll conventions checks passed.libs(script)main(none are locale tests)guest_localeaborts withmain'sLocaleSupport.cppand passes again with the merged file restored. The worktree is clean afterwardsctest, negative control
Previous findings
lengthreturns a character count: Resolved.WideCodecvtLengthnow throws. The debt entry states that the return value and state effect are unverified and that the standarddo_lengthconsumes input bytes. This also answers MarcZX10's blocking item onc5f43513fb.none, and the description keeps the textual rebase note. The PR merges and passes on currentmainwithout #10165._Mbtowcxthrows on incomplete or invalid input: Still open, non-blocking.LocaleSupport.cpp:932-937still throws on the -1 and -2 results.GuestLocale.cpp:243-252still asserts those throws. The debt entry saysin/outdelegate to_Mbtowcx/_Wctombxon the console, which suggests the console returns codes there, but it does not list the throwing paths. Suggested fix: add the throws to the debt entry, or return the console's codes once they are confirmed. This can be a follow-up.New findings
Blocking
None.
Non-blocking
lengthslot to throw. AtGuestLocale.cpp:92,RequireException([&] { vtable->length(...); })is still present at this head, although oneandonlydean asked on597258ffadfor it to be removed. Whoever later implementslengthwould have to delete it. I agree with their request: drop that line and keep the positivein/out/unshiftchecks and the state checks. This is not blocking because no written rule in CONTRIBUTING.md or AGENTS.md forbids it.Not verified
max_length6, thepartial/errormapping andlength. I have no PPSA03446libc.prxdisassembly.wchar_t) and ASan runs. Both are author- or contributor-reported only (maskym's Windows rerun ond7562dcc1d; the author's ASan run on an earlier head).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:51:52Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make the wide codecvt state reset safe for the guest state object.
What I ran
Inspected the prepared diff and changed source at head
d7562dcc1d873ad19809c9b31d350de94db517c9, plus the UTF-8 helper andGuestLocalevtable definitions throughrepo_read.py. No build or tests were run during this review; the test results in the PR description are author-reported.Results
Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:359clears 16 bytes through thestatepointer passed tounshift. The codecvt vtable contract declares this state asstd::uint64_t*, while the changed thread-local buffers in this file are 16 bytes; callers can also pass an ordinarymbstate_tobject. The implementation therefore writes beyond a state object when it is smaller than 16 bytes, corrupting adjacent memory. Reset only the state size guaranteed by the actual guest ABI, or use a correctly sized guest state object consistently.Non-blocking
None.
Not verified
No build, tests, or PS5 execution were performed. The reported Linux and earlier Windows test runs are author-supplied. Reviewed all three changed files:
core/libs/prx/libc/src/LocaleSupport.cpp,core/libs/tests/GuestLocale.cpp, anddocs/dev/debt/libc.md; none were excluded.To get this to a good state
Correct the
unshiftstate reset and rerun the relevant guest locale and wide conversion checks on the updated head.Pull request closed