fix(libc): convert wcsrtombs using guest characters #1507
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1507"
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 ArjenS-LA on 2026-10-08T10:26:31Z.
What
wcsrtombspassed guest strings and conversion state directly to the host CRT. On Windows, an invalid character such as U+0100 returned hostEILSEQ=42instead of guest86. On Linux, the host's 32-bitwchar_talso disagrees with the guest's 16-bit characters.The export now lives beside the other guest multibyte conversions and uses
wcrtombwith 16-bit guest characters. Partial conversions leave the source at the next unconverted character; a stored terminator sets it to null. Length queries ignore capacity and preserve the source pointer. Invalid characters report guestEILSEQand preserve the converted prefix.Adds the registered
guest_wcsrtombsregression test and updates the existing technical-debt entry. Conversion follows the existing guest single-byte C locale; other encodings and shift states remain unsupported. The restart and length-query behavior follows the C working draft, section 7.31.6.4.2.Tested
Windows validation of PR head
74e1a6f5c4ba8c1f4cf805ba23965199bd473407, rebased onto main6b56175a4290a03ab28ebc6697beeffe6fe9be8d.The rebase resolves the TechnicalDebt.md conflict by preserving upstream's SPIRV-Tools and Windows host-import entries alongside the corrected wide-character note. The note's leading link now points to Multibyte.cpp as requested in review. The implementation and regression-test patch are unchanged.
Windows 11 Enterprise 10.0.26200; WinLibs MinGW-w64 GCC 15.2.0 r2 UCRT/posix/SEH, Ninja Release,
BUILD_TESTING=ON, SPIRV-Tools disabled. This uses the installed r2 toolchain, not CI's r7 package.The libc library and all four selected test targets rebuilt successfully after the rebase:
guest_wcsrtombsguest_wcsrtombs_sguest_wide_stringsguest_locale4/4 passed, 0 failed, 0 skipped. The new test covers full, empty, partial and resumed conversions; exact and zero capacity; high-byte characters; explicit and null state pointers; length queries; source-pointer positions; output boundaries; and guest error numbers.
Before the fix, the new regression test was compiled directly against the original
Strings.cppfrom8763483811950f6e150201e664e771ec0dac0794, with a test-only errno accessor. It failed atinvalid character uses guest EILSEQ. The same standalone test passed after the replacement. This is a focused reproduction, not a full baseline-versus-PR suite comparison.The committed-head conventions check, diff whitespace check, and test-registration check passed. The registration check found no newly unregistered test executables.
These local results cover the pinned PR revision. Linux, the full registered CTest suite, the complete default/libs build, games, and the eventual merged tree were not rerun locally for this rebase. No performance or game-compatibility conclusion is claimed.
Independent validation of the earlier head: Dextroid17 reported 462/462 Linux tests passing after integrating it with main
fd5342b6(CachyOS, GCC 16.2.1, Release, SPIRV-Tools enabled). Reverting only the implementation made the new test fail atfull conversion length. Those are the reviewer's results for that earlier integration, not a Linux run of the rebased head above.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 klosixgaming-arch on 2026-10-08T10:55:21Z.
Review: COMMENTED
Solid fix for wcsrtombs with excellent test coverage. The comprehensive edge case testing (partial conversions, exact capacity, invalid characters, length queries) is thorough and follows C11 standards properly.
Note: This overlaps with #1511 and #1512 on the TechnicalDebt.md line - all three address wide-character conversion issues. Coordination between these PRs would be helpful to avoid merge conflicts.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:26:41Z.
Review: APPROVED
Good implementation of
wcsrtombsusing the guest's single-byte C locale throughwcrtomb. This fixes the issue where on Linux (where host wchar_t is 32 bits), guest strings were misread and miswritten.Strengths:
wcrtombinfrastructureTechnical notes:
This will improve compatibility with titles that use
wcsrtombs. Ready to merge.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T13:30:02Z.
Ran this on Linux because it has no independent run yet, and it holds up. Details, so the next reader does not have to redo them.
Merged onto current
main(fd5342b6): one conflict, indocs/dev/TechnicalDebt.md, and only becausemainadded an unrelated SPIRV-Tools entry next to the one you edited — keep both.Result (CachyOS, GCC 16.2.1, Release,
-DANYPS5_ENABLE_SPIRV_TOOLS=ON):The test bites — reverted only the implementation (
Strings.cppandMultibyte.cppback tomain, test and registration kept):That failure is worth quoting in the description, because it is stronger than "misreads non-ASCII": on
mainthe very first assertion fails, so every guest string of two or more characters fails to convert, not only the ones with a character above0x7f. A change that fixes every caller rather than one title's case is the shape that gets merged here.Semantics cross-checked against the platform's own
wcsrtombs(same cases, C locale, hostwchar_t, so the reference is the same function implemented correctly):Every one matches yours, including the two that are easy to get wrong (the terminator-not-stored case and the length query leaving
sourcealone). Theerrnohalf is complete throughwcrtomb, which sets86itself — I checked, because the plain function has to set it and it is not obvious from the call site.One nit: the debt entry's first link still points at
Strings.cppalthoughwcsrtombsnow lives inMultibyte.cpp; pointing that link atMultibyte.cpp(and leaving theswprintfone) would match the tree after this change.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T19:54:50Z.
Linux run, since the bug is Linux-specific (32-bit host
wchar_t): Ubuntu 24.04.5, glibc 2.39, GCC 13.3.0, Release. Head74e1a6f5merged onto main4b6ab6bb.guest_wcsrtombs,guest_wcsrtombs_s,guest_wide_stringsandguest_localepass.Strings.cppandMultibyte.cppto main and kept the new test. On Linux,guest_wcsrtombsthen fails at its first check,full conversion length, not at the EILSEQ check where it failed on Windows. So on Linux the old host-wchar_tpath already gets the plain ASCII conversion wrong.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T20:16:14Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libc/src/Strings.cppL455-458docs/dev/TechnicalDebt.mdL259Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:05:53Z.
Checked the build and the four libc wide-string tests (
guest_wcsrtombs,guest_wcsrtombs_s,guest_wide_strings,guest_locale) on Linux;guest_wcsrtombsfails without the implementation. Restart, length-query and EILSEQ paths match the description; TechnicalDebt entry is accurate. CI is green; merging.