feat(libc): implement the std::__sce_v2 num_get virtuals for char integers, bool and pointers #16919
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16919"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
mainmerged in. Until they merge, only commit3012780ad71is this PR's change.Implement eight of the eleven
do_getvirtuals ofstd::__sce_v2::num_get<char>, which_Makelocbuilds:bool,unsigned short,unsigned int,long,unsigned long,long long,unsigned long longandvoid*. Before this PR, each of them threwNotImplemented_nid_no_patch. Thefloat,doubleandlong doubleslots 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.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), vtable0x18C5F0, read from its disassembly and run:_Getifld(0xD3270) reads it. Thousands separators before and after the sign are skipped and mark the grouping bad. A leading0picks octal when the base field is empty, and0xor0Xpicks hex when the base field is empty orhex. Digits come fromctype<char>::widenof0123456789ABCDEFabcdef-+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 againstnumpunct::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._Stollx,_Stoullxand_Stoulxand store the value even when they fail. A bad grouping setsfailbitand keeps the value, except forunsigned int, which stores 0.unsigned shortparses without the sign, fails above 65535 with 65535, and negates a-.longandunsigned longcall thelong longfunctions directly, not through the vtable. A failure assignsfailbitto the state rather than adding it, and reaching the end addseofbit.boolconverts with_Stolx: 0 and 1 succeed, other values storetrueand fail, and a field that does not convert storestrueand fails. Withboolalpha, the input is matched against"\0" falsename "\0" truenameas the module's_Getloctxtdoes: 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.streambuf's pointers and count, and falls back tounderflowanduflow.The
_Makelocdebt entry names what works now, and a newnum_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 mergesmain4204951e771). Not run on Linux or macOS, not run in a title.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,boolnames, held characters, the direct area and the virtual fallback, equal iterators, a replacedctypefacet, andlongbypassing thelong longvirtual. It passes, as doguest_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_integerandpublic_headers(13 of 13)._Makeloc: random texts of digits, signs, prefixes, separators, names and other bytes, random base fields andboolalpha, grouping strings, separators,boolnames, initial states, get areas of every size including none and negative counts, held characters, a null first buffer, an equal last iterator, a failinguflow, a replacedctypefacet, 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 thenumpunct,ctype,underflowanduflowcalls._Sto*xredirected to this library's: 400,000 calls over 2 seeds, 0 differences._Sto*x: 200,000 calls, 0 differences.boolnames always start with the terminator, and the signed and unsigned range checks ofboolagree on every value_Stolxreturned in these runs), and keeping 30 instead of 31 characters cannot be observed because a field that long overflows either way.length_errorandbad_allocpaths of the grouping strings.check_conventions,git diff --check: clean.pr_overlapreports no open PR with the same functions; it could not compare 40 PRs that conflict withmainon shared files. Of those, the 5 that touchLocaleSupport.cpp(#7081, #9526, #11172, #12518, #12704) do not add these virtuals. #15830 implements the publicgetmembers of the unversionednum_getin libSceLibcInternal, not these virtuals.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:15:53Z.
Review: COMMENTED
Read
a29de8f1beagainstmain. Only3012780ad7and the final merge are this PR's;93cdfce4daand39c2543bf4are a parallel copy of themainmerge and the string-constant fix and leave no diff against #16560's head.Slots and layout. The eleven
do_getare in Dinkumware's order (bool, unsigned short, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, void*; microsoft/STLstl/inc/xlocnum:341-617ate1ed302); libc++ putslongandlong longbefore the unsigned ones, so it isn't the reference.istreambuf_iteratoras {streambuf*, bool, char} in 16 bytes,_IGnext/_IGcountat 0x38/0x50, andunderflow/uflowin vtable slots 7 and 8 match Dinkumware'sbasic_streambuf.Field parsing.
GetSceV2IntegerFieldfollows_Getifldstep by step as microsoft/STL keeps it in_Parse_int_with_locale(xlocnum:653-789): separators around the sign,0xonly 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.GetSceV2LocaleTextis_Getloctxt(stl/inc/xlocale:3272-3315) with the case-sensitive compare, and failures setfailbitwitheofbitadded afterwards, as the reference does.Test gap.
unsigned int(LocaleSupport.cpp:2469) casts the_Stoulxresult to 32 bits with no range check of its own;"4294967296"fails today only because the versioned_Stoulxworks 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_Stoulxturning it into 0 with no failbit.Not run here; this is from reading the code.
AI-assisted: yes.
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
1eee72b4d7e4d8986c9c4260fa42796c8dfbfd99using the prepared diff andrepo_read.py; no build or tests were run by me.Results
Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:2767casts the signed parsed bool value touint64_tbefore checking whether it exceeds 1. Thus-1becomes 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-1to 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.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:43:55Z.
Review: COMMENTED
guest_sce_v2_num_get_charpassed with1eee72b4d7and 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.