feat(libc): implement the std::__sce_v2 num_get virtuals for char integers, bool and pointers #16919

Open
Danigamer05 wants to merge 16 commits from upstream-pr/16919 into main
Danigamer05 commented 2026-11-07 22:31:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-07T22:31:28Z.


What

Builds on #16560: this branch contains its commits, and through it #16516, #16214, #16178 and #15923, with current main merged in. Until they merge, only commit 3012780ad71 is this PR's change.

Implement eight of the eleven do_get virtuals of std::__sce_v2::num_get<char>, which _Makeloc builds: bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long and void*. Before this PR, each of them threw NotImplemented_nid_no_patch. The float, double and long double slots still throw. These slots are not exports: guest code reaches them through the facet's vtable, so this PR adds no NID.

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), vtable 0x18C5F0, read from its disassembly and run:

  • The field is read as the module's _Getifld (0xD3270) reads it. Thousands separators before and after the sign are skipped and mark the grouping bad. A leading 0 picks octal when the base field is empty, and 0x or 0X picks hex when the base field is empty or hex. Digits come from ctype<char>::widen of 0123456789ABCDEFabcdef-+Xx, leading zeros are dropped and at most 31 characters are kept. Two separators in a row and a trailing separator mark the grouping bad but are still consumed. The groups are checked against numpunct::grouping() from the last group: a size outside 1 to 126 skips the group, the last size repeats, and the first group may be shorter.
  • The integer slots convert with _Stollx, _Stoullx and _Stoulx and store the value even when they fail. A bad grouping sets failbit and keeps the value, except for unsigned int, which stores 0. unsigned short parses without the sign, fails above 65535 with 65535, and negates a -. long and unsigned long call the long long functions directly, not through the vtable. A failure assigns failbit to the state rather than adding it, and reaching the end adds eofbit.
  • Numeric bool converts with _Stolx: 0 and 1 succeed, other values store true and fail, and a field that does not convert stores true and fails. With boolalpha, the input is matched against "\0" falsename "\0" truename as the module's _Getloctxt does: the longest name wins, case-sensitively.
  • void* reads a hex field whatever the flags say, converts with _Stoullx, and stores null when the conversion fails.
  • The iterator reads the get area through the streambuf's pointers and count, and falls back to underflow and uflow.

The _Makeloc debt entry names what works now, and a new num_get<char> entry lists the floating-point slots and the gaps.

Tested

Windows 11, MinGW GCC 15.2, Release, head on top of #16560 (8ac2d3a15dc, which merges main 4204951e771). Not run on Linux or macOS, not run in a title.

  • New test guest_sce_v2_num_get_char: every implemented slot, bases and prefixes, signs, leading zeros, empty and partial input, grouping with good and bad groups and the 127 cap, the state rules, bool names, held characters, the direct area and the virtual fallback, equal iterators, a replaced ctype facet, and long bypassing the long long virtual. It passes, as do guest_sce_v2_num_put_char, guest_sce_v2_num_put_wide, guest_sce_v2_char_facet_virtuals, guest_sce_v2_makeloc, guest_sce_v2_locale, guest_sce_v2_locale_basics, guest_sce_v2_locimp_references, guest_sce_v2_facet_ids, guest_locale, guest_sce_v2_exceptions, guest_sce_v2_string_to_integer and public_headers (13 of 13).
  • Differential harness against the module's own code, loaded and relocated, on the same inputs with facets from each side's _Makeloc: random texts of digits, signs, prefixes, separators, names and other bytes, random base fields and boolalpha, grouping strings, separators, bool names, initial states, get areas of every size including none and negative counts, held characters, a null first buffer, an equal last iterator, a failing uflow, a replaced ctype facet, and a locale without facets. It compares the 16 bytes around the value, the state, the get pointer, count and fallback position, the returned iterator, the stream's fields, and the order of the numpunct, ctype, underflow and uflow calls.
    • With the module's _Sto*x redirected to this library's: 400,000 calls over 2 seeds, 0 differences.
    • With the module's own _Sto*x: 200,000 calls, 0 differences.
  • After the final merge: 100,000 more harness calls on a third seed, 0 differences, and the harnesses of #16516 and #16560 at 50,000 calls each, 0 differences.
  • Negative control: 37 single-change mutations of the implementation. 33 fail the final test and 30 fail the harness. The first run showed that the test missed 4 that the harness caught, so the test was strengthened and those were rerun. Neither catches the other 4: three are equivalent here (a trailing separator marks the grouping bad before the group count matters, bool names always start with the terminator, and the signed and unsigned range checks of bool agree on every value _Stolx returned in these runs), and keeping 30 instead of 31 characters cannot be observed because a field that long overflows either way.
  • Not reached: the length_error and bad_alloc paths of the grouping strings.
  • check_conventions, git diff --check: clean. pr_overlap reports no open PR with the same functions; it could not compare 40 PRs that conflict with main on shared files. Of those, the 5 that touch LocaleSupport.cpp (#7081, #9526, #11172, #12518, #12704) do not add these virtuals. #15830 implements the public get members of the unversioned num_get in libSceLibcInternal, not these virtuals.

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: #16560
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5206448605 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16919). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-07T22:31:28Z. --- ### What Builds on #16560: this branch contains its commits, and through it #16516, #16214, #16178 and #15923, with current `main` merged in. Until they merge, only commit `3012780ad71` is this PR's change. Implement eight of the eleven `do_get` virtuals of `std::__sce_v2::num_get<char>`, which `_Makeloc` builds: `bool`, `unsigned short`, `unsigned int`, `long`, `unsigned long`, `long long`, `unsigned long long` and `void*`. Before this PR, each of them threw `NotImplemented_nid_no_patch`. The `float`, `double` and `long double` slots still throw. These slots are not exports: guest code reaches them through the facet's vtable, so this PR adds no NID. The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`), vtable `0x18C5F0`, read from its disassembly and run: - The field is read as the module's `_Getifld` (`0xD3270`) reads it. Thousands separators before and after the sign are skipped and mark the grouping bad. A leading `0` picks octal when the base field is empty, and `0x` or `0X` picks hex when the base field is empty or `hex`. Digits come from `ctype<char>::widen` of `0123456789ABCDEFabcdef-+Xx`, leading zeros are dropped and at most 31 characters are kept. Two separators in a row and a trailing separator mark the grouping bad but are still consumed. The groups are checked against `numpunct::grouping()` from the last group: a size outside 1 to 126 skips the group, the last size repeats, and the first group may be shorter. - The integer slots convert with `_Stollx`, `_Stoullx` and `_Stoulx` and store the value even when they fail. A bad grouping sets `failbit` and keeps the value, except for `unsigned int`, which stores 0. `unsigned short` parses without the sign, fails above 65535 with 65535, and negates a `-`. `long` and `unsigned long` call the `long long` functions directly, not through the vtable. A failure assigns `failbit` to the state rather than adding it, and reaching the end adds `eofbit`. - Numeric `bool` converts with `_Stolx`: 0 and 1 succeed, other values store `true` and fail, and a field that does not convert stores `true` and fails. With `boolalpha`, the input is matched against `"\0" falsename "\0" truename` as the module's `_Getloctxt` does: the longest name wins, case-sensitively. - `void*` reads a hex field whatever the flags say, converts with `_Stoullx`, and stores null when the conversion fails. - The iterator reads the get area through the `streambuf`'s pointers and count, and falls back to `underflow` and `uflow`. The `_Makeloc` debt entry names what works now, and a new `num_get<char>` entry lists the floating-point slots and the gaps. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW GCC 15.2, Release, head on top of #16560 (`8ac2d3a15dc`, which merges `main` `4204951e771`). Not run on Linux or macOS, not run in a title. - New test `guest_sce_v2_num_get_char`: every implemented slot, bases and prefixes, signs, leading zeros, empty and partial input, grouping with good and bad groups and the 127 cap, the state rules, `bool` names, held characters, the direct area and the virtual fallback, equal iterators, a replaced `ctype` facet, and `long` bypassing the `long long` virtual. It passes, as do `guest_sce_v2_num_put_char`, `guest_sce_v2_num_put_wide`, `guest_sce_v2_char_facet_virtuals`, `guest_sce_v2_makeloc`, `guest_sce_v2_locale`, `guest_sce_v2_locale_basics`, `guest_sce_v2_locimp_references`, `guest_sce_v2_facet_ids`, `guest_locale`, `guest_sce_v2_exceptions`, `guest_sce_v2_string_to_integer` and `public_headers` (13 of 13). - Differential harness against the module's own code, loaded and relocated, on the same inputs with facets from each side's `_Makeloc`: random texts of digits, signs, prefixes, separators, names and other bytes, random base fields and `boolalpha`, grouping strings, separators, `bool` names, initial states, get areas of every size including none and negative counts, held characters, a null first buffer, an equal last iterator, a failing `uflow`, a replaced `ctype` facet, and a locale without facets. It compares the 16 bytes around the value, the state, the get pointer, count and fallback position, the returned iterator, the stream's fields, and the order of the `numpunct`, `ctype`, `underflow` and `uflow` calls. - With the module's `_Sto*x` redirected to this library's: 400,000 calls over 2 seeds, 0 differences. - With the module's own `_Sto*x`: 200,000 calls, 0 differences. - After the final merge: 100,000 more harness calls on a third seed, 0 differences, and the harnesses of #16516 and #16560 at 50,000 calls each, 0 differences. - Negative control: 37 single-change mutations of the implementation. 33 fail the final test and 30 fail the harness. The first run showed that the test missed 4 that the harness caught, so the test was strengthened and those were rerun. Neither catches the other 4: three are equivalent here (a trailing separator marks the grouping bad before the group count matters, `bool` names always start with the terminator, and the signed and unsigned range checks of `bool` agree on every value `_Stolx` returned in these runs), and keeping 30 instead of 31 characters cannot be observed because a field that long overflows either way. - Not reached: the `length_error` and `bad_alloc` paths of the grouping strings. - `check_conventions`, `git diff --check`: clean. `pr_overlap` reports no open PR with the same functions; it could not compare 40 PRs that conflict with `main` on shared files. Of those, the 5 that touch `LocaleSupport.cpp` (#7081, #9526, #11172, #12518, #12704) do not add these virtuals. #15830 implements the public `get` members of the unversioned `num_get` in libSceLibcInternal, not these virtuals. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #16560 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-07 23:15:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:15:53Z.

Review: COMMENTED


Read a29de8f1be against main. Only 3012780ad7 and the final merge are this PR's; 93cdfce4da and 39c2543bf4 are a parallel copy of the main merge and the string-constant fix and leave no diff against #16560's head.

Slots and layout. The eleven do_get are in Dinkumware's order (bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, void*; microsoft/STL stl/inc/xlocnum:341-617 at e1ed302); libc++ puts long and long long before the unsigned ones, so it isn't the reference. istreambuf_iterator as {streambuf*, bool, char} in 16 bytes, _IGnext/_IGcount at 0x38/0x50, and underflow/uflow in vtable slots 7 and 8 match Dinkumware's basic_streambuf.

Field parsing. GetSceV2IntegerField follows _Getifld step by step as microsoft/STL keeps it in _Parse_int_with_locale (xlocnum:653-789): separators around the sign, 0x only for basefield 0 or hex, the 10/8/22 digit limits, the 31-character cap, and the group check from the last group with the last size repeating. GetSceV2LocaleText is _Getloctxt (stl/inc/xlocale:3272-3315) with the case-sensitive compare, and failures set failbit with eofbit added afterwards, as the reference does.

Test gap. unsigned int (LocaleSupport.cpp:2469) casts the _Stoulx result to 32 bits with no range check of its own; "4294967296" fails today only because the versioned _Stoulx works on 32 bits (DinkumwareInternals.cpp:477-479). The test pins "4294967295" but not the value above it. CheckInt(bench, "unsigned int overflow", "4294967296", 4294967295u, FailBit | EofBit); would catch a later 64-bit _Stoulx turning it into 0 with no failbit.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815513897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16919#pullrequestreview-5815513897). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T23:15:53Z. **Review:** COMMENTED --- Read `a29de8f1be` against `main`. Only `3012780ad7` and the final merge are this PR's; `93cdfce4da` and `39c2543bf4` are a parallel copy of the `main` merge and the string-constant fix and leave no diff against #16560's head. **Slots and layout.** The eleven `do_get` are in Dinkumware's order (bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, void*; microsoft/STL `stl/inc/xlocnum:341-617` at `e1ed302`); libc++ puts `long` and `long long` before the unsigned ones, so it isn't the reference. `istreambuf_iterator` as {streambuf*, bool, char} in 16 bytes, `_IGnext`/`_IGcount` at 0x38/0x50, and `underflow`/`uflow` in vtable slots 7 and 8 match Dinkumware's `basic_streambuf`. **Field parsing.** `GetSceV2IntegerField` follows `_Getifld` step by step as microsoft/STL keeps it in `_Parse_int_with_locale` (xlocnum:653-789): separators around the sign, `0x` only for basefield 0 or hex, the 10/8/22 digit limits, the 31-character cap, and the group check from the last group with the last size repeating. `GetSceV2LocaleText` is `_Getloctxt` (`stl/inc/xlocale:3272-3315`) with the case-sensitive compare, and failures set `failbit` with `eofbit` added afterwards, as the reference does. **Test gap.** `unsigned int` (`LocaleSupport.cpp:2469`) casts the `_Stoulx` result to 32 bits with no range check of its own; `"4294967296"` fails today only because the versioned `_Stoulx` works on 32 bits (`DinkumwareInternals.cpp:477-479`). The test pins `"4294967295"` but not the value above it. `CheckInt(bench, "unsigned int overflow", "4294967296", 4294967295u, FailBit | EofBit);` would catch a later 64-bit `_Stoulx` turning it into 0 with no failbit. Not run here; this is from reading the code. AI-assisted: yes.
MarcZX10 commented 2026-11-22 12:23:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:23:54Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: correct numeric bool parsing for negative values.

What I ran

Reviewed head 1eee72b4d7e4d8986c9c4260fa42796c8dfbfd99 using the prepared diff and repo_read.py; no build or tests were run by me.

Results

Check Result Note
Source review failed One verified bool parsing defect
Build and tests not run Author-reported checks not rerun

Findings

Blocking

  • core/libs/prx/libc/src/LocaleSupport.cpp:2767 casts the signed parsed bool value to uint64_t before checking whether it exceeds 1. Thus -1 becomes a large unsigned value and is flagged as a conversion failure, although the described behavior says only values other than 0 and 1 fail. The new test explicitly expects -1 to fail (GuestSceV2NumGetChar.cpp:1451), so it currently locks in this behavior. Check the signed result against the valid bool values without unsigned conversion.

Non-blocking

None.

Not verified

Did not run the author-reported Windows test suite or differential harness, and did not verify Linux, macOS, or console behavior. Reviewed the prepared changed files shown in the bundle; no files were excluded by the manifest.

To get this to a good state

Correct the signed bool range check and update its test to match the intended behavior, then rerun the affected test and relevant suite on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012192089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16919#pullrequestreview-6012192089). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T12:23:54Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: correct numeric bool parsing for negative values. ## What I ran Reviewed head `1eee72b4d7e4d8986c9c4260fa42796c8dfbfd99` using the prepared diff and `repo_read.py`; no build or tests were run by me. ## Results | Check | Result | Note | |---|---|---| | Source review | failed | One verified bool parsing defect | | Build and tests | not run | Author-reported checks not rerun | ## Findings ### Blocking - `core/libs/prx/libc/src/LocaleSupport.cpp:2767` casts the signed parsed bool value to `uint64_t` before checking whether it exceeds 1. Thus `-1` becomes a large unsigned value and is flagged as a conversion failure, although the described behavior says only values other than 0 and 1 fail. The new test explicitly expects `-1` to fail (`GuestSceV2NumGetChar.cpp:1451`), so it currently locks in this behavior. Check the signed result against the valid bool values without unsigned conversion. ### Non-blocking None. ## Not verified Did not run the author-reported Windows test suite or differential harness, and did not verify Linux, macOS, or console behavior. Reviewed the prepared changed files shown in the bundle; no files were excluded by the manifest. ## To get this to a good state Correct the signed bool range check and update its test to match the intended behavior, then rerun the affected test and relevant suite on the new head.
ligmaSec commented 2026-12-03 17:43:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:43:55Z.

Review: COMMENTED


guest_sce_v2_num_get_char passed with 1eee72b4d7 and its prerequisite stack integrated into a Linux release build. The fixture exercises the char facet's integer, boolean and pointer slots through the guest vtable, including unsuccessful extraction cases.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6175232777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16919#pullrequestreview-6175232777). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T17:43:55Z. **Review:** COMMENTED --- `guest_sce_v2_num_get_char` passed with `1eee72b4d7` and its prerequisite stack integrated into a Linux release build. The fixture exercises the char facet's integer, boolean and pointer slots through the guest vtable, including unsuccessful extraction cases. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/16919:upstream-pr/16919'
git switch 'upstream-pr/16919'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/16919'
git switch 'upstream-pr/16919'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/16919'
git switch 'upstream-pr/16919'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/16919'
git switch 'main'
git merge --squash 'upstream-pr/16919'
git switch 'main'
git merge --ff-only 'upstream-pr/16919'
git switch 'main'
git merge 'upstream-pr/16919'
git push origin 'main'
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!16919
No description provided.