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

Merged
Fishybeing merged 1 commit from upstream-pr/1126 into main 2026-10-08 09:09:25 +00:00
Fishybeing commented 2026-10-07 13:14:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Fishybeing on 2026-10-07T13:14:19Z.


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 #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 #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: #1116
  • AI-assisted: No
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4773176225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1126). Originally posted by [Fishybeing](https://github.com/Fishybeing) on 2026-10-07T13:14:19Z. --- ### 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 #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 #1116 applied, including `guest_wide_strings` and `guest_wide_formatting`. GPU tests not run. - Not tested on Linux. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #1116 - [x] AI-assisted: No
github-actions[bot] commented 2026-10-07 13:54:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T13:54:58Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6039475126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1126#issuecomment-6039475126). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T13:54:58Z. --- <!-- pr-overlap --> 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`<br>`wcscmp_nid_postfix`<br>`wcscoll_nid_postfix`<br>`wcscpy_nid_postfix`<br>`wcslen_nid_postfix`<br>`wcsncmp_nid_postfix`<br>`wcsrchr_nid_postfix`<br>`wcsspn_nid_postfix`<br>`wcstod_nid_postfix`<br>`wcstof_nid_postfix`<br>`wmemchr_nid_postfix`<br>`wmemcmp_nid_postfix`<br>`wmemset_nid_postfix` | |
fisherjoey commented 2026-10-08 05:24:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T05:24:39Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052972870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1126#issuecomment-6052972870). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T05:24:39Z. --- 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.
adriadam10 commented 2026-10-08 08:48:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:48:48Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056231753 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1126#issuecomment-6056231753). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T08:48:48Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1126
No description provided.