feat(libc): implement _Iswctype #1993

Closed
overlordxrz-source wants to merge 1 commit from upstream-pr/1993 into main
overlordxrz-source commented 2026-10-09 04:13:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T04:13:27Z.


What

Implements _Iswctype (CyXs2l-1kNA), which still throws on main as libcCyberUnknown07. Cyberpunk 2077 (PPSA04029, import list in #266) and GTA III Definitive Edition (import list in #267) import it.

_Iswctype(wint_t wc, wctype_t desc) is Dinkumware's internal classifier. desc is not a host wctype_t and not a bit mask. It is a 1-based index into Dinkumware's _Wctype class table. Plauger's own headers and sources (Dinkumware C library V5.00, as shipped in QNX's libc) give the full order:

This agrees with the one value already confirmed in Sony's libc.prx: its _WStoul calls _Iswctype(c, 9) for white space (review of #492).

The classes are tested the same way as the narrow is* exports in LocaleSupport.cpp: ClassifyCharacter with the classic std::ctype<char>, so _Iswctype(c, n) matches the narrow function for every value from EOF to 255. Above 255, and for WEOF, it returns 0, as in Dinkumware's C-locale table (ASCII ranges only) and the narrow table, which classifies nothing above 127. desc 0 returns 0. A desc above 12 throws std::invalid_argument, because Dinkumware would read past its table and the repo loads no locale that could add classes. wc is taken as 32 bits, the same as Dinkumware's comparisons on the full wint_t.

Two known differences from Plauger's 2006 C-locale table, kept on purpose so the wide classes match the narrow ones: that table leaves NUL and DEL out of cntrl, and puts \n, \v, \f and \r in blank. Sony's own table couldn't be checked.

#1498 also replaces this stub, but it treats desc as a bit mask (ClassificationBits(c) & desc), so _Iswctype(c, 9) from _WStoul would test two unrelated mask bits instead of white space. #1783 implements the FreeBSD iswctype/wctype (_CTYPE_* masks), which is a separate export with its own desc meaning. It doesn't overlap with this PR, and the two merge cleanly.

Log

I don't own either title, so I can't paste a stop line from main. The evidence is the import lists in #266 and #267.

Tested

aarch64 Debian 13 host. The full project can't be built here because it needs x86-64.

  • core/libs/tests/GuestCharacter.cpp now checks all 12 classes against the host C-locale is* for EOF..255, desc 0, all classes returning 0 for 256..0xFFFF and above, and the throw for desc 13. It passes natively and under UBSan. Swapping the punct/space entries makes it fail, as it should.
  • LocaleSupport.cpp, Export.cpp and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with -Wall -Wextra (Zig 0.17 clang). The only warning is the existing -Wreturn-type-c-linkage from General.hpp.
  • tools/nid_names.py computes CyXs2l-1kNA for _Iswctype.
  • python3 tools/check_conventions.py --base origin/main passes.
  • Merges cleanly with #1097, #1981 and #1982. It conflicts with #1952 and #1980 in Export.cpp, only because they delete or replace the stubs next to this one. Resolving it means keeping both sides' deletions.
  • Not run with a title.

Checklist

  • Based on current main. The one other open PR that changes this function is #1498, which also changes this stub as part of a larger change; see What
  • 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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4795881572 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1993). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-09T04:13:27Z. --- ### What Implements `_Iswctype` (`CyXs2l-1kNA`), which still throws on `main` as `libcCyberUnknown07`. Cyberpunk 2077 (PPSA04029, import list in #266) and GTA III Definitive Edition (import list in #267) import it. `_Iswctype(wint_t wc, wctype_t desc)` is Dinkumware's internal classifier. `desc` is not a host `wctype_t` and not a bit mask. It is a 1-based index into Dinkumware's `_Wctype` class table. Plauger's own headers and sources (Dinkumware C library V5.00, as shipped in QNX's libc) give the full order: - `xwcc.h` defines `iswalnum` as `_Iswctype(wc, 1)`, then `alpha` 2, `cntrl` 3, `digit` 4, `graph` 5, `lower` 6, `print` 7, `punct` 8, `space` 9, `upper` 10, `xdigit` 11 and `blank` 12: https://github.com/vocho/openqnx/blob/master/trunk/lib/c/public/xwcc.h - `xwctytab.c` builds the table in that order, with entry 0 holding the range-table pointer: https://github.com/vocho/openqnx/blob/master/trunk/lib/c/ansi/xwctytab.c - `wctype.c` searches from index 1 and returns 0 for an unknown name: https://github.com/vocho/openqnx/blob/master/trunk/lib/c/ansi/wctype.c - `xwctype.c` (`_Iswctype` itself) scans the ranges between `table[desc]` and `table[desc + 1]`, so `desc` 0 is an empty range and returns 0: https://github.com/vocho/openqnx/blob/master/trunk/lib/c/ansi/xwctype.c This agrees with the one value already confirmed in Sony's `libc.prx`: its `_WStoul` calls `_Iswctype(c, 9)` for white space (review of #492). The classes are tested the same way as the narrow `is*` exports in `LocaleSupport.cpp`: `ClassifyCharacter` with the classic `std::ctype<char>`, so `_Iswctype(c, n)` matches the narrow function for every value from `EOF` to 255. Above 255, and for `WEOF`, it returns 0, as in Dinkumware's C-locale table (ASCII ranges only) and the narrow table, which classifies nothing above 127. `desc` 0 returns 0. A `desc` above 12 throws `std::invalid_argument`, because Dinkumware would read past its table and the repo loads no locale that could add classes. `wc` is taken as 32 bits, the same as Dinkumware's comparisons on the full `wint_t`. Two known differences from Plauger's 2006 C-locale table, kept on purpose so the wide classes match the narrow ones: that table leaves NUL and DEL out of `cntrl`, and puts `\n`, `\v`, `\f` and `\r` in `blank`. Sony's own table couldn't be checked. #1498 also replaces this stub, but it treats `desc` as a bit mask (`ClassificationBits(c) & desc`), so `_Iswctype(c, 9)` from `_WStoul` would test two unrelated mask bits instead of white space. #1783 implements the FreeBSD `iswctype`/`wctype` (`_CTYPE_*` masks), which is a separate export with its own `desc` meaning. It doesn't overlap with this PR, and the two merge cleanly. ### Log I don't own either title, so I can't paste a stop line from `main`. The evidence is the import lists in #266 and #267. ### Tested aarch64 Debian 13 host. The full project can't be built here because it needs x86-64. - `core/libs/tests/GuestCharacter.cpp` now checks all 12 classes against the host C-locale `is*` for `EOF`..255, `desc` 0, all classes returning 0 for 256..0xFFFF and above, and the throw for `desc` 13. It passes natively and under UBSan. Swapping the `punct`/`space` entries makes it fail, as it should. - `LocaleSupport.cpp`, `Export.cpp` and the test compile for x86_64-linux-gnu and x86_64-windows-gnu with `-Wall -Wextra` (Zig 0.17 clang). The only warning is the existing `-Wreturn-type-c-linkage` from `General.hpp`. - `tools/nid_names.py` computes `CyXs2l-1kNA` for `_Iswctype`. - `python3 tools/check_conventions.py --base origin/main` passes. - Merges cleanly with #1097, #1981 and #1982. It conflicts with #1952 and #1980 in `Export.cpp`, only because they delete or replace the stubs next to this one. Resolving it means keeping both sides' deletions. - Not run with a title. ### Checklist - [x] Based on current `main`. The one other open PR that changes this function is #1498, which also changes this stub as part of a larger change; see What - [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: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 04:13:48 +00:00 (Migrated from github.com)

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


Progress report (f145139 → 2406209)

📈 System libraries: 84.79% (+0.03%, +1 implemented, -1 removed functions)

✅ 1 implemented
Library Name
libc _Iswctype_nid_postfix
🗑️ 1 removed
Library Name
libc libcCyberUnknown07
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074121339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1993#issuecomment-6074121339). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T04:13:48Z. --- <!-- progress-report --> ### Progress report (f145139 → 2406209) 📈 **System libraries**: 84.79% (+0.03%, +1 implemented, -1 removed functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `_Iswctype_nid_postfix` | </details> <details> <summary>🗑️ 1 removed</summary> | Library | Name | | - | - | | libc | `libcCyberUnknown07` | </details>
MarcZX10 commented 2026-10-09 04:20:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:20:49Z.

Review: APPROVED


Reviewed the full diff and the cited Dinkumware sources. The 1-based class ordering and C-locale table behavior match the implementation; the PS5-side _WStoul call to _Iswctype(c, 9) grounds the whitespace descriptor. The tests cover all 12 classes, upper Unicode values, and invalid descriptors, and Linux, Windows, Conventions, and Progress checks pass on this head. The unverified differences are recorded in TechnicalDebt.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465665431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1993#pullrequestreview-5465665431). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T04:20:49Z. **Review:** APPROVED --- Reviewed the full diff and the cited Dinkumware sources. The 1-based class ordering and C-locale table behavior match the implementation; the PS5-side `_WStoul` call to `_Iswctype(c, 9)` grounds the whitespace descriptor. The tests cover all 12 classes, upper Unicode values, and invalid descriptors, and Linux, Windows, Conventions, and Progress checks pass on this head. The unverified differences are recorded in TechnicalDebt.
oneandonlydean commented 2026-10-09 09:30:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:30:50Z.


Closing: only the import lists in #266 and #267 show _Iswctype, with no stop line from main. Reopen with the not implemented line when a title stops here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078246915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1993#issuecomment-6078246915). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:30:50Z. --- Closing: only the import lists in #266 and #267 show `_Iswctype`, with no stop line from main. Reopen with the `not implemented` line when a title stops here.

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