feat(libc): scan 16-bit wide conversions on Linux #5285

Closed
Nixitov wants to merge 1 commit from upstream-pr/5285 into main
Nixitov commented 2026-10-13 16:31:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T16:31:42Z.


What

On Linux the scanf family threw for the 16-bit wide conversions (%ls, %lc, %l[, %S, %C) because glibc would store a 32-bit wchar_t per character into the guest's 16-bit buffer. vsscanf/sscanf now scan them here instead:

  • %ls, %S and %lc, %C decode the input's UTF-8 into the guest's 16-bit buffer independently of the host locale, as the narrow printf family already encodes wide arguments; a code point above U+FFFF becomes a surrogate pair.
  • %l[ is scanned through the host's wide scanset.
  • The scan runs directive by directive, the way the existing ScanGuest already does for the _s forms, so the non-wide conversions keep the host's behaviour and the wide ones no longer reach glibc's wchar_t.

fscanf and the _s forms still throw for wide conversions on Linux; only the buffer scans (vsscanf/sscanf) changed.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.

  • guest_wide_formatting gains CheckScanning: wide strings, two of them, a mixed %d %ls, a field width, %lc, %n, leading whitespace, and (Linux only) accented UTF-8 and a non-BMP code point. It passes, and guest_formatting passes.
  • python tools/check_conventions.py --base origin/main passes.
  • The new Linux scanner is exercised by the Linux CI build; this machine runs the existing Windows path (ScanWindows), so the Linux branch was not run locally. The behaviour is recorded in docs/dev/debt/libc.md.

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 under Silent stubs in their library's technical debt file
  • 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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846333873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5285). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T16:31:42Z. --- ### What On Linux the scanf family threw for the 16-bit wide conversions (`%ls`, `%lc`, `%l[`, `%S`, `%C`) because glibc would store a 32-bit `wchar_t` per character into the guest's 16-bit buffer. `vsscanf`/`sscanf` now scan them here instead: - `%ls`, `%S` and `%lc`, `%C` decode the input's UTF-8 into the guest's 16-bit buffer independently of the host locale, as the narrow printf family already encodes wide arguments; a code point above U+FFFF becomes a surrogate pair. - `%l[` is scanned through the host's wide scanset. - The scan runs directive by directive, the way the existing `ScanGuest` already does for the `_s` forms, so the non-wide conversions keep the host's behaviour and the wide ones no longer reach glibc's `wchar_t`. `fscanf` and the `_s` forms still throw for wide conversions on Linux; only the buffer scans (`vsscanf`/`sscanf`) changed. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. - `guest_wide_formatting` gains `CheckScanning`: wide strings, two of them, a mixed `%d %ls`, a field width, `%lc`, `%n`, leading whitespace, and (Linux only) accented UTF-8 and a non-BMP code point. It passes, and `guest_formatting` passes. - `python tools/check_conventions.py --base origin/main` passes. - The new Linux scanner is exercised by the Linux CI build; this machine runs the existing Windows path (`ScanWindows`), so the Linux branch was not run locally. The behaviour is recorded in `docs/dev/debt/libc.md`. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 16:32:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:32:31Z.


Progress report (016db92 → d2bb74f)

📈 System libraries: 88.22% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libc vsscanf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150302688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5285#issuecomment-6150302688). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T16:32:31Z. --- <!-- progress-report --> ### Progress report (016db92 → d2bb74f) 📈 **System libraries**: 88.22% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `vsscanf_nid_postfix` | </details>
github-actions[bot] commented 2026-10-13 16:35:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T16:35:13Z.


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
#4966 core/libs/prx/libc/src/Formatting.cpp L377, L396
#5222 core/libs/prx/libc/src/Formatting.cpp L11
#5330 core/libs/prx/libc/src/Formatting.cpp L11
#5606 core/libs/prx/libc/src/Formatting.cpp L374, L393, L396
docs/dev/debt/libc.md L56
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150352359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5285#issuecomment-6150352359). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T16:35:13Z. --- <!-- 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 | |---|---|---|---| | #4966 | `core/libs/prx/libc/src/Formatting.cpp` [L377](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L377), [L396](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L396) | | | | #5222 | `core/libs/prx/libc/src/Formatting.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L11) | | | | #5330 | `core/libs/prx/libc/src/Formatting.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L11) | | | | #5606 | `core/libs/prx/libc/src/Formatting.cpp` [L374](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L374), [L393](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L393), [L396](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/core/libs/prx/libc/src/Formatting.cpp#L396)<br>`docs/dev/debt/libc.md` [L56](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libc.md#L56) | | |
Nixitov commented 2026-10-13 17:03:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-13T17:03:26Z.


Thanks bot. This is an adjacent, same-file overlap rather than duplicated logic: this PR adds the Linux 16-bit wide conversions (%ls, %lc, %S, %C) to vsscanf/sscanf in Formatting.cpp and its test. #4966 (suppressed conversions before EOF) and #5222 (EOF stickiness) also touch the scanf code nearby.

Nothing here depends on them; whoever lands second just needs a small rebase. I'm happy to rebase this after either lands, and to reconcile the input-failure/EOF return values with #5222's ScanResultAtEndOfFile so the wide scanner follows the same rule.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150864184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5285#issuecomment-6150864184). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-13T17:03:26Z. --- Thanks bot. This is an adjacent, same-file overlap rather than duplicated logic: this PR adds the Linux 16-bit wide conversions (`%ls`, `%lc`, `%S`, `%C`) to `vsscanf`/`sscanf` in `Formatting.cpp` and its test. #4966 (suppressed conversions before EOF) and #5222 (EOF stickiness) also touch the scanf code nearby. Nothing here depends on them; whoever lands second just needs a small rebase. I'm happy to rebase this after either lands, and to reconcile the input-failure/EOF return values with #5222's `ScanResultAtEndOfFile` so the wide scanner follows the same rule. AI-assisted: yes
oneandonlydean commented 2026-10-14 02:29:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:29:46Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159550750 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5285#issuecomment-6159550750). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:29:46Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5285
No description provided.