fix(libc): return the console's class bits from the ctype functions #10387

Merged
JJenkx merged 2 commits from upstream-pr/10387 into main 2026-10-26 01:28:15 +00:00
JJenkx commented 2026-10-23 20:36:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T20:36:31Z.


What

The ctype classifiers (isalnum, isalpha, isblank, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit) return 1 for a match. The libc.prx that titles ship returns the matching bits of its classification table instead. For example:

  • isdigit('0') is 0x20;
  • isupper('A') is 0x02 and islower('a') is 0x10;
  • isspace(' ') is 0x04 and isspace('\t') is 0x40;
  • isblank('\t') is 0x400;
  • iscntrl gives 0x80 and ispunct gives 0x08.

Which characters match is the same on both sides. Only the nonzero values differ, which shows in code like count += isdigit(c) or a table indexed by the result.

That table is the one _Getpctype already exports, in the same bit layout, with one difference: the console marks tab with 0x400 as well (0x4c0), and main had 0xc0. The classifiers now return the exported table's bits under the console's masks, and the table gains the tab bit:

Function Mask
isalnum 0x32
isalpha 0x12
isblank 0x404
iscntrl 0x80
isdigit 0x20
isgraph 0x3a
islower 0x10
isprint 0x3e
ispunct 0x08
isspace 0x44
isupper 0x02
isxdigit 0x01

EOF still gives 0, and out-of-range values still throw as before.

Tested

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main 40564ce897.

  • Comparison: a scratch loader runs the decrypted libc.prx of eleven titles natively: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169.
    • For all twelve classifiers on EOF and every byte, all eleven print identical values.
    • That table and those masks reproduce all 3,084 values.
    • _Getpctype's tab entry is 0x4c0 there.
    • Against main's libc.prx DLL, the values differ on 438 of the 3,084, and the true/false sets on none.
    • With this PR's libc.prx DLL, all 3,084 values and all 257 _Getpctype entries match PPSA07923's and PPSA13934's.
  • guest_character: the new CheckConsoleClassValues checks spot values from the console and every input against the console's table and masks. The existing truthiness checks still pass.
  • guest_locale: the _Getpctype tab expectation is now the console's 0x4c0.
  • guest_character, guest_locale and guest_rune_locale pass in three runs out of three on the exact head.
  • Negative control: with main's LocaleSupport.cpp and these tests, guest_character and guest_locale abort in a Require, while guest_rune_locale still passes.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Not tested: a console, Linux and macOS (the change is target-independent), non-C guest locales, and the wide isw* functions.

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: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4988940774 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10387). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-23T20:36:31Z. --- ### What The ctype classifiers (`isalnum`, `isalpha`, `isblank`, `iscntrl`, `isdigit`, `isgraph`, `islower`, `isprint`, `ispunct`, `isspace`, `isupper`, `isxdigit`) return 1 for a match. The `libc.prx` that titles ship returns the matching bits of its classification table instead. For example: - `isdigit('0')` is `0x20`; - `isupper('A')` is `0x02` and `islower('a')` is `0x10`; - `isspace(' ')` is `0x04` and `isspace('\t')` is `0x40`; - `isblank('\t')` is `0x400`; - `iscntrl` gives `0x80` and `ispunct` gives `0x08`. Which characters match is the same on both sides. Only the nonzero values differ, which shows in code like `count += isdigit(c)` or a table indexed by the result. That table is the one `_Getpctype` already exports, in the same bit layout, with one difference: the console marks tab with `0x400` as well (`0x4c0`), and `main` had `0xc0`. The classifiers now return the exported table's bits under the console's masks, and the table gains the tab bit: | Function | Mask | |---|---| | `isalnum` | `0x32` | | `isalpha` | `0x12` | | `isblank` | `0x404` | | `iscntrl` | `0x80` | | `isdigit` | `0x20` | | `isgraph` | `0x3a` | | `islower` | `0x10` | | `isprint` | `0x3e` | | `ispunct` | `0x08` | | `isspace` | `0x44` | | `isupper` | `0x02` | | `isxdigit` | `0x01` | `EOF` still gives 0, and out-of-range values still throw as before. ### Tested Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`, `main` 40564ce897. - **Comparison:** a scratch loader runs the decrypted `libc.prx` of eleven titles natively: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169. - For all twelve classifiers on `EOF` and every byte, all eleven print identical values. - That table and those masks reproduce all 3,084 values. - `_Getpctype`'s tab entry is `0x4c0` there. - Against `main`'s `libc.prx` DLL, the values differ on 438 of the 3,084, and the true/false sets on none. - With this PR's `libc.prx` DLL, all 3,084 values and all 257 `_Getpctype` entries match PPSA07923's and PPSA13934's. - **`guest_character`:** the new `CheckConsoleClassValues` checks spot values from the console and every input against the console's table and masks. The existing truthiness checks still pass. - **`guest_locale`:** the `_Getpctype` tab expectation is now the console's `0x4c0`. - `guest_character`, `guest_locale` and `guest_rune_locale` pass in three runs out of three on the exact head. - **Negative control:** with `main`'s `LocaleSupport.cpp` and these tests, `guest_character` and `guest_locale` abort in a `Require`, while `guest_rune_locale` still passes. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - **Not tested:** a console, Linux and macOS (the change is target-independent), non-C guest locales, and the wide `isw*` functions. ### 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: none - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code).
MarcZX10 commented 2026-10-23 21:20:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T21:20:18Z.

Review: APPROVED


Reviewed the implementation and test diff. The title-binary comparison across eleven libc.prx versions is strong evidence for the exact return masks and tab classification change; the per-byte test checks the exported table against those masks, and EOF/range behavior is preserved. I also checked the overlapping open isascii/toascii PR (#8919): it adds separate exports and tests without overlapping these classifier changes.\n\nCI on this head passed conventions, intake, eligibility, labels, Ubuntu/Windows relinker, macOS x86_64 relinker, ASan relinker, and register-context/write-watch jobs. The macos-latest relinker job failed in unrelated conventions fixture and NID database cache tests; Linux and Windows product jobs were skipped by workflow policy, so those are not validated by hosted CI here. The PR's local Windows test evidence covers guest_character, guest_locale, and guest_rune_locale, but no console/hardware or non-Windows runtime validation is reported. I found no blocking issue in the changed behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5634566925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10387#pullrequestreview-5634566925). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T21:20:18Z. **Review:** APPROVED --- Reviewed the implementation and test diff. The title-binary comparison across eleven libc.prx versions is strong evidence for the exact return masks and tab classification change; the per-byte test checks the exported table against those masks, and EOF/range behavior is preserved. I also checked the overlapping open isascii/toascii PR (#8919): it adds separate exports and tests without overlapping these classifier changes.\n\nCI on this head passed conventions, intake, eligibility, labels, Ubuntu/Windows relinker, macOS x86_64 relinker, ASan relinker, and register-context/write-watch jobs. The macos-latest relinker job failed in unrelated conventions fixture and NID database cache tests; Linux and Windows product jobs were skipped by workflow policy, so those are not validated by hosted CI here. The PR's local Windows test evidence covers guest_character, guest_locale, and guest_rune_locale, but no console/hardware or non-Windows runtime validation is reported. I found no blocking issue in the changed behavior.
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!10387
No description provided.