fix(libc): encode each UTF-16 unit of a narrow %ls on its own, as titles' libc.prx does #9939
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9939"
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 JJenkx on 2026-10-22T22:56:21Z.
What
The narrow printf family (
snprintfand the rest) converts a 16-bit guest string given to%lsor%Sto UTF-8. It joined a surrogate pair into one 4-byte sequence. Thelibc.prxthat titles ship encodes characters in at most 3 bytes, as the console's C locale does (#8855 measures the same 3-byte limit in the firmware's multibyte functions). It therefore writes each surrogate as its own 3-byte sequence:main[%ls]of U+1F6005B ED A0 BD ED B8 80 5D(8)5B F0 9F 98 80 5D(6)%.3lsof U+1F600ED A0 BD(3)%.10lsofA é € U+1F600 ZA é €andED A0 BDA é €andF0 9F 98 80[%-9S]of U+1F600This removes the line in
FormatWindowsthat joined the pair. Every code unit, a surrogate included, now takes the existing 1-to-3-byte path, and the precision still keeps whole code units. Lone surrogates already matched the console. The debt entry no longer calls this unverified.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,mainbd1d3994ce.libc.prxnatively and compares itssnprintfwith this build'ssnprintf_nid_postfix. It uses[%ls],[%.2ls]and[%5ls]on ten strings: ASCII,é,€, U+1F600, a lone high surrogate, a lone low surrogate, a high surrogate followed byA, U+FFFF, U+FFFE, U+0080, and U+07FF U+0800. It also tests[%lc]on six values, and%.*lswith precision 0–13 onA é € U+1F600 Z. Onmain, the U+1F600 cases differ. With this change, every case gives the same bytes and count.guest_formatting:CheckWidePrecisionexpected the 4-byte form, and its expectations for precisions 9, 10 and 11 and for%.3lsof U+1F600 now use the console's results. There are two new checks,[%ls]and[%-9S]of U+1F600. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. Withmain'sWindowsFormatting.hppand this test,guest_formattingfails.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.WindowsFormatting.hpp,core/libs/tests/Formatting.cppanddocs/dev/debt/libc.md, while its behavior is distinct. This PR removes surrogate-pair joining in the narrow wide-string conversion and updatesCheckWidePrecision; #9927 adds floating-point formatting paths andCheckHexFloat/CheckDecimalFloat, plus separate wide-float tests. In either landing order, retain the per-code-unit conversion and all updated/new string expectations here, both floating-point test calls and cases, the separate wide-float implementation/tests, and both debt descriptions. #8855, #9552, #9699 and #9916 also edit neighbouring debt text; reconcile their independent locale, argument-limit and floating-point notes. This is a review of the submitted diffs, not a combined build or test result; Depends on remains none.c2bde4fe3merged cleanly ontomainfcd455870: Ubuntu 26.04 in Docker on Windows, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,BUILD_TESTING=ON. The reviewer reportsguest_formattingandguest_wide_formattingeach passing five runs (--repeat until-fail:5). With this PR's test retained and main's changed production sources restored, the reviewer reports a failure:wide precision 9: expected 9 complete UTF-8 bytes, received 6. This is reviewer-supplied evidence for those revisions, not a local rerun or a latest-main claim.%s(the other direction).Checklist
main; no other open PR changes how%lsencodesNotImplemented_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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:45:22Z.
Review: APPROVED
Reviewed exact head
c2bde4fe30659f922238104ca2302cc4857d42d6. The per-UTF-16-code-unit conversion matches the contributor’s differential against a title-shippedlibc.prx; the added precision and surrogate expectations exercise the changed semantics, with Linux WSL and Windows runs reported and an independent WSL reviewer confirming 5/5 repetitions and a failing-main control. Current-main diff-check and conventions pass, and the branch merges cleanly; the intervening 295 main commits do not touch the three changed paths. Hosted policy and relinker matrix checks pass; full product builds are skipped. I did not rerun the C++ suite locally. Console/title generalization beyond the measured libc and untested%sdirection remain appropriately documented.Pull request closed