libc: _WStoul, _Iswctype and swscanf_s are stubs; fix branch ready #3077

Closed
opened 2026-10-10 21:46:24 +00:00 by screamm · 1 comment
screamm commented 2026-10-10 21:46:24 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T21:46:24Z.


In libc (Export.cpp) _WStoul, _Iswctype and swscanf_s are NotImplemented_nid_no_patch stubs. _Iswctype is what Dinkumware's iswalpha and friends expand to, so a title whose C++ runtime classifies wide characters through libc.prx stops on it.

Fix branch ready: screamm:feat/libc-wide-conversions (51fca3ce, on top of the strtol fix 63cce467 from #3075, both on main 262c0316). Depends on #3075. I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are.

  • _WStoul(const wchar_t*, wchar_t**, int) calls the existing wcstoul, which returns 64 bits (the Windows unsigned long pitfall from #2424 cannot apply); base 1, a negative base and a base above 36 throw, because Windows, FreeBSD and Dinkumware disagree there.
  • _Iswctype(wint_t, wctype_t) maps Dinkumware's class numbers 1 to 12 (alnum, alpha, cntrl, digit, graph, lower, print, punct, space, upper, xdigit, blank) onto the checks the existing isw* exports use; the numbering is from Dinkumware's xwcc.h (P.J. Plauger, as shipped in TI's compiler headers). Other numbers throw, including the FreeBSD masks the existing wctype returns.
  • swscanf_s(const wchar_t*, const wchar_t*, ...): a new 16-bit wide scanner in ScanningWide.cpp (the existing ScanGuest reads narrow strings through the host sscanf), reading arguments with the existing LibcDetail::FormatArguments. It handles %d %i %o %u %x %X with all sizes, the float conversions, %s %c %[ narrow or l, %n and %%; the _s size argument is read as unsigned int like the existing sscanf_s, a null buffer, format or target returns EOF, a too-small buffer is a matching failure with a zeroed first element. %p, %S, %C, unknown length modifiers, ranges in [...], %n with * or a width, a zero width and characters above 255 into a narrow target throw. Sources: C11 7.29.2.2 and K.3.9.1, FreeBSD 11 vfwscanf.c for integer truncation.
  • TechnicalDebt records what is unverified on a console (class numbering, the _s size width, the matching-failure choices).
  • New guest_wide_conversion covers values above 32 bits, ERANGE, bases and prefixes, non-ASCII stops and throwing bases for _WStoul; every class 1 to 12 against its isw* function over code points 0 to 0x2FF for _Iswctype; and %d, %ls with a size, a too-small buffer, null arguments, %lc, %l[, %ln, floats including %Lf and the failure cases for swscanf_s.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_wide_conversion, guest_math, guest_wide_strings, guest_rune_locale, guest_scan_count and guest_wide_formatting 3/3; ctest -j8 -E "^agc_|video_out" 389/389; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5795558602 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3077). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T21:46:24Z. --- In libc ([Export.cpp](https://github.com/boykopovar/AnyPS5/blob/main/core/libs/prx/libc/Export.cpp)) `_WStoul`, `_Iswctype` and `swscanf_s` are `NotImplemented_nid_no_patch` stubs. `_Iswctype` is what Dinkumware's `iswalpha` and friends expand to, so a title whose C++ runtime classifies wide characters through libc.prx stops on it. **Fix branch ready:** [`screamm:feat/libc-wide-conversions`](https://github.com/screamm/AnyPS5/tree/feat/libc-wide-conversions) (`51fca3ce`, on top of the strtol fix `63cce467` from #3075, both on `main` `262c0316`). Depends on #3075. I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commits as they are. - `_WStoul(const wchar_t*, wchar_t**, int)` calls the existing `wcstoul`, which returns 64 bits (the Windows `unsigned long` pitfall from #2424 cannot apply); base 1, a negative base and a base above 36 throw, because Windows, FreeBSD and Dinkumware disagree there. - `_Iswctype(wint_t, wctype_t)` maps Dinkumware's class numbers 1 to 12 (alnum, alpha, cntrl, digit, graph, lower, print, punct, space, upper, xdigit, blank) onto the checks the existing `isw*` exports use; the numbering is from Dinkumware's `xwcc.h` (P.J. Plauger, as shipped in TI's compiler headers). Other numbers throw, including the FreeBSD masks the existing `wctype` returns. - `swscanf_s(const wchar_t*, const wchar_t*, ...)`: a new 16-bit wide scanner in `ScanningWide.cpp` (the existing `ScanGuest` reads narrow strings through the host `sscanf`), reading arguments with the existing `LibcDetail::FormatArguments`. It handles `%d %i %o %u %x %X` with all sizes, the float conversions, `%s %c %[` narrow or `l`, `%n` and `%%`; the `_s` size argument is read as `unsigned int` like the existing `sscanf_s`, a null buffer, format or target returns EOF, a too-small buffer is a matching failure with a zeroed first element. `%p`, `%S`, `%C`, unknown length modifiers, ranges in `[...]`, `%n` with `*` or a width, a zero width and characters above 255 into a narrow target throw. Sources: C11 7.29.2.2 and K.3.9.1, FreeBSD 11 `vfwscanf.c` for integer truncation. - TechnicalDebt records what is unverified on a console (class numbering, the `_s` size width, the matching-failure choices). - New `guest_wide_conversion` covers values above 32 bits, ERANGE, bases and prefixes, non-ASCII stops and throwing bases for `_WStoul`; every class 1 to 12 against its `isw*` function over code points 0 to 0x2FF for `_Iswctype`; and `%d`, `%ls` with a size, a too-small buffer, null arguments, `%lc`, `%l[`, `%ln`, floats including `%Lf` and the failure cases for `swscanf_s`. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_wide_conversion`, `guest_math`, `guest_wide_strings`, `guest_rune_locale`, `guest_scan_count` and `guest_wide_formatting` 3/3; `ctest -j8 -E "^agc_|video_out"` 389/389; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
adriadam10 commented 2026-10-10 22:01:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:01:33Z.


Fixed by #3083: _WStoul, _Iswctype and swscanf_s are implemented, covered by guest_wide_conversion.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102638670 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3077#issuecomment-6102638670). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:01:33Z. --- Fixed by #3083: `_WStoul`, `_Iswctype` and `swscanf_s` are implemented, covered by `guest_wide_conversion`.
Sign in to join this conversation.
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#3077
No description provided.