Repository navigation
fix(libc): convert wcsrtombs using guest characters - #1507
Conversation
klosixgaming-arch
left a comment
There was a problem hiding this comment.
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.
klosixgaming-arch
left a comment
There was a problem hiding this comment.
Good implementation of wcsrtombs using the guest's single-byte C locale through wcrtomb. This fixes the issue where on Linux (where host wchar_t is 32 bits), guest strings were misread and miswritten.
Strengths:
- Clean implementation using existing
wcrtombinfrastructure - Comprehensive test coverage including edge cases (partial conversion, invalid characters, zero capacity, length queries)
- Proper error handling with guest EILSEQ errno value (86)
- Good documentation update in TechnicalDebt.md noting remaining limitations
Technical notes:
- The approach of iterating through wide characters and converting each individually is correct for the single-byte C locale
- Proper handling of source pointer updates on both success and failure
- Test cases properly verify all conversion scenarios including resume after partial conversion
This will improve compatibility with titles that use wcsrtombs. Ready to merge.
Remove items that have been completed in recent PRs: - sce::Json::Value::clear (implemented in boykopovar#1204) - libSceNpPartner001 functions (implemented in boykopovar#1517) - swprintf formatting (fixed in boykopovar#1512/boykopovar#1511) - wcsrtombs implementation (completed in boykopovar#1507) - sceNetResolverAbort (implemented in boykopovar#1502) Update remaining entries to reflect current state.
|
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 Result (CachyOS, GCC 16.2.1, Release, The test bites — reverted only the implementation ( That failure is worth quoting in the description, because it is stronger than "misreads non-ASCII": on Semantics cross-checked against the platform's own Every one matches yours, including the two that are easy to get wrong (the terminator-not-stored case and the length query leaving One nit: the debt entry's first link still points at Written with AI assistance. |
This PR updates TechnicalDebt.md to remove items that have been completed in recent PRs: **Removed (completed):** - `sce::Json::Value::clear` - implemented in boykopovar#1204 - libSceNpPartner001 functions (`sceNpEAAccessInitialize`, `sceNpEAAccessTerminate`) - implemented in boykopovar#1517 - swprintf formatting issues - fixed in boykopovar#1512/boykopovar#1511 (now routes through 16-bit guest formatter) - wcsrtombs implementation - completed in boykopovar#1507 (uses guest's single-byte C locale through wcrtomb) - sceNetResolverAbort - implemented in boykopovar#1502 **Updated:** - libSceNpPartner001 entry now reflects the actual implementation status - Wide-character conversions entry updated to reflect wcsrtombs completion - PPSA23566 unknown signatures list updated to remove completed items This keeps the technical debt documentation accurate and up-to-date with recent development.
d7023c9 to
74e1a6f
Compare
|
Linux run, since the bug is Linux-specific (32-bit host
|
|
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.
|
This PR updates TechnicalDebt.md to remove items that have been completed in recent PRs: **Removed (completed):** - `sce::Json::Value::clear` - implemented in boykopovar#1204 - libSceNpPartner001 functions (`sceNpEAAccessInitialize`, `sceNpEAAccessTerminate`) - implemented in boykopovar#1517 - swprintf formatting issues - fixed in boykopovar#1512/boykopovar#1511 (now routes through 16-bit guest formatter) - wcsrtombs implementation - completed in boykopovar#1507 (uses guest's single-byte C locale through wcrtomb) - sceNetResolverAbort - implemented in boykopovar#1502 **Updated:** - libSceNpPartner001 entry now reflects the actual implementation status - Wide-character conversions entry updated to reflect wcsrtombs completion - PPSA23566 unknown signatures list updated to remove completed items This keeps the technical debt documentation accurate and up-to-date with recent development.
Remove entries for functions that have been implemented: - libSceNpPartner001 unknown functions (implemented in boykopovar#1517) - sce::Json::Value::clear (implemented in boykopovar#1204) - sceNetResolverAbort (implemented in boykopovar#1502) - Wide-character conversions: swprintf (fixed in boykopovar#1512/boykopovar#1511), wcsrtombs (completed in boykopovar#1507) Addresses feedback from @Dextroid17 on PR boykopovar#1833 to remove only completed entries rather than replacing the entire file. Written with AI assistance.
Remove only the debt entries that have since been implemented, leaving every other entry in TechnicalDebt.md unchanged: - libSceNpPartner001 EA access functions (implemented in boykopovar#1517) - sce::Json::Value::clear (implemented in boykopovar#1204) - sceNetResolverAbort (implemented in boykopovar#1502) - Wide-character conversions: swprintf (fixed in boykopovar#1511/boykopovar#1512) and wcsrtombs (completed in boykopovar#1507) This is the targeted, reviewable change requested by @Dextroid17 on boykopovar#1539 and boykopovar#1833, instead of replacing the whole file. Written with AI assistance.
Remove only the debt entries that have since been implemented, leaving every other entry in TechnicalDebt.md byte-for-byte unchanged: - libSceNpPartner001 EA access entry (7CxI50-xlCk, pMxXhNozUX8) - boykopovar#1517 - sce::Json::Value::clear - boykopovar#1204 - sceNetResolverAbort - boykopovar#1502 - Wide-character conversions (swprintf / wcsrtombs) - boykopovar#1511/boykopovar#1512 and boykopovar#1507 Content is aligned to this branch's merge base so the PR diff shows only these three removals, per the review request on boykopovar#1539. Written with AI assistance.
…te-exact) Remove only the debt entries that have since been implemented, leaving every other entry byte-for-byte identical to this branch's merge base: - libSceNpPartner001 EA access entry (7CxI50-xlCk, pMxXhNozUX8) - boykopovar#1517 - sce::Json::Value::clear - boykopovar#1204 - sceNetResolverAbort - boykopovar#1502 - Wide-character conversions (swprintf / wcsrtombs) - boykopovar#1511/boykopovar#1512 and boykopovar#1507 Content is aligned to the merge base so the PR diff shows only these three removals, per the review request on boykopovar#1539. Written with AI assistance.
|
Checked the build and the four libc wide-string tests ( |
fix(libc): convert wcsrtombs using guest characters
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)