Skip to content

fix(libc): parse and collate guest wide strings as 16-bit units - #1126

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Fishybeing:fix/libc-utf16-conversions
Oct 8, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Fishybeing:fix/libc-utf16-conversions

Conversation

@Fishybeing

@Fishybeing Fishybeing commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Follow-up to #1116, which listed the remaining host-wchar_t wide functions in TechnicalDebt. This moves the parsing and collation ones to 16-bit units:

  • wcstol, wcstoll, wcstoul, wcstoull, wcstod, wcstof, wcstold parse the ASCII prefix of the guest string with the same host parsers the narrow strto* exports use, and map the end pointer back onto the guest string. In the C locale iswspace is true only for the standard white-space characters and iswdigit only for 0-9 (C11 7.30.2.1), so no character outside ASCII can be part of a number. A string with no conversion returns its start, as before.
  • wcscoll compares like wcscmp, as strcoll does with strcmp.
  • wcsxfrm copies the string when it fits and returns its length, the C-locale identity transform strxfrm uses.

wcsrtombs and swprintf stay on the host functions and stay in TechnicalDebt: wcsrtombs needs the guest's multibyte encoding and mbstate_t, and swprintf on Windows goes through FormatWideWindows, so moving it is a separate change.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs 15.2.0posix-14.0.0-ucrt-r7), Release, -DBUILD_TESTING=ON, on current main with fix(libc): read guest wide strings as 16-bit units #1116 applied
  • Strings.cpp and GuestWideStrings.cpp build without warnings, also with -Wall -Wextra.
  • guest_wide_strings now also covers the parsers (sign, white space, hex with base 16 and 0, overflow to ULLONG_MAX, no conversion, U+3000 and U+0661 stopping the parse, end pointers), wcscoll and wcsxfrm.
  • ctest -E 'agc|shader|recompiler|Vulkan|vulkan|video_out': 197/197 passed on e79c971f with fix(libc): read guest wide strings as 16-bit units #1116 applied, including guest_wide_strings and guest_wide_formatting. GPU tests not run.
  • Not tested on Linux.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: fix(libc): read guest wide strings as 16-bit units #1116
  • AI-assisted: No

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#1128 wcschr_nid_postfix
wcscmp_nid_postfix
wcscoll_nid_postfix
wcscpy_nid_postfix
wcslen_nid_postfix
wcsncmp_nid_postfix
wcsrchr_nid_postfix
wcsspn_nid_postfix
wcstod_nid_postfix
wcstof_nid_postfix
wmemchr_nid_postfix
wmemcmp_nid_postfix
wmemset_nid_postfix

@fisherjoey

Copy link
Copy Markdown
Contributor

This looks like the same change as #1116: both add wcslen_nid_postfix, wcscpy_nid_postfix and wmemcpy_nid_postfix to libc/src/Strings.cpp for 16-bit guest wide strings, with a GuestWideStrings.cpp test under the same guest_wide_strings ctest name. Linking so they can be compared.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
wcstod, wcstof, wcstold, wcstol, wcstoll, wcstoul, wcstoull, wcscoll and wcsxfrm still forwarded to the host's wchar_t functions, which use 32-bit units on Linux. The wcsto* functions now parse the ASCII prefix of the guest string with the narrow parsers, as the C locale accepts only ASCII white space and digits. wcscoll compares like wcscmp and wcsxfrm copies, as strcoll and strxfrm do in the C locale.
@adriadam10
adriadam10 force-pushed the fix/libc-utf16-conversions branch from d726e27 to 5b0d283 Compare October 8, 2026 08:48
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main: the first commit was #1116's, already merged and identical to main for Strings.cpp and the test, so I dropped it; resolved the TechnicalDebt conflict (single "Wide-character conversions" line). Checked the wcsto* ASCII-prefix parsing and end pointers, wcscoll/wcsxfrm and the test values; guest_wide_strings fails without the change and the full ctest passes (426/426). Merging once CI is green.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
@adriadam10
adriadam10 merged commit e3d5e79 into boykopovar:main Oct 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants