feat(libc): implement the std::__sce_v2 num_put virtuals for char #16516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16516"
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-06T23:53:04Z.
What
Builds on #16214: this branch contains its commits, and through it #16178 and #15923. Until they merge, only the last commit is this PR's change.
Implement the eight
do_putvirtuals of the versionedstd::__sce_v2::num_put<char>facet that_Makelocbuilds. Before this PR, each of them threwNotImplemented_nid_no_patch. 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), vtable0x18C700:0x20do_put(bool)boolalpha, calls thelongslot with the byte zero-extended; with it,do_truenameordo_falsename0x28,0x30do_put(long),do_put(unsigned long)%[+][#]l+d/u,o,x/X0x38,0x40do_put(long long),do_put(unsigned long long)ll0x48,0x50do_put(double),do_put(long double)%[+][#].*[L]+g/G,e/E,f,a/A0x58do_put(const void*)%pWhere the versioned facet differs from the existing unversioned
num_put<char>, so it has its own code:ios_baselayout and flag bits differ:flagsat0x18, 64-bitprecisionat0x20andwidthat0x28; uppercase0x4, showbase0x8, showpoint0x10, showpos0x20, left0x40, internal0x100, oct0x400, hex0x800, scientific0x1000, fixed0x2000, boolalpha0x4000.SceV2IosBasenow names these fields.intcount that the buffer holds a pointer to at0x58, and decrements it. Otherwise the character goes throughoverflow. A null buffer or a rejectedoverflowsetsfailed, keeps the buffer and keeps writing..*with precision -1. For the other fields the precision passes through unchanged, and only its low 32 bits size the buffer.0x20bytes, not the0x28ofGuestLocale::String, so the numpunct strings have their own reader.sprintf_s, as in the module, notsnprintf.UseSceV2Facet, which falls back to the global locale and then a cached default as the module does.The other versioned virtuals still throw, including the wide and
unsigned shortnum_put, and the classic_Locimpstays without facets. The_Makelocdebt entry now namesnum_put<char>, and a new entry lists the gaps:sprintf_slength_errorbad_allocTested
Windows 11, MinGW GCC 15.2, Release, head on top of #16214. Not run on Linux or macOS, not run in a title.
guest_sce_v2_num_put_char: every slot, flags, adjustment, grouping, non-finite values, the put count,overflowand failure paths. It passes, as doguest_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_exceptionsandpublic_headers(10 of 10)._Makeloc: random flags, widths, fills, precisions (including values with large or negative low 32 bits), grouping strings, truename and falsename lengths, separators, buffer states, and a locale without facets. It compares the written bytes, the count, the returned iterator,width,flags,precision, and the order of thectypeandnumpunctvirtual calls.sprintf_sredirected to this library's, so onlynum_putis compared: 400,000 calls over 2 seeds, 0 differences.sprintf_s: 4,076 of 200,000 calls differ, 794doubleand 3,282long double, and the integer,booland pointer slots do not differ. The samples I read differ in digits, as the%e, %f and %gdebt entry describes.#does not changeinfornanunder this library's formatter, so the module's flag clear is kept but not observable here.length_errorpaths and thebad_allocpath.check_conventions,git diff --check: clean. Merges cleanly withmain0e297f14250and with each of my 20 open PRs.pr_overlapfinds no open PR with the same functions. It could not compare 38 PRs that conflict withmain, on the sharedCMakeLists.txt,docs/dev/debt/libc.md,Api.hpporLocaleSupport.cpp. No open PR found by searching for__sce_v2 num_put.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:49Z.
Review: COMMENTED
Read
13fc6e65e0againstmain. Only the commits on top of #16214's head2ffd07f90bare this PR's.Reference. The guest library is Dinkumware (
_Makeloc,_Locimp,_Sto*x), not libc++, so I compared against its public descendant in microsoft/STL (stl/inc/xlocnumate1ed302). libc++ would give the wrong slot order: it declareslong longbeforeunsigned long(libcxx/include/locale:1227-1234atllvmorg-19.1.0).Slots and layout. The eight
do_putare in Dinkumware's order (bool, long, unsigned long, long long, unsigned long long, double, long double, const void*; xlocnum:1278-1448). TheSceV2IosBaseoffsets (flags 0x18, precision 0x20, width 0x28), the flag bits,ostreambuf_iteratoras {bool, streambuf*}, and_IPnext/_IPcountat 0x40/0x58 withoverflowin vtable slot 4 all match it.Formatting.
PutSceV2Fieldputs fill where_Iputdoes for left, internal and default adjustment (xlocnum:1561-1581). For integers the0xprefix counts only under basefield hex (xlocnum:1619-1623), for floating point only under hexfloat, after the sign (xlocnum:1519-1528). Non-finite values clear showpoint (xlocnum:1396-1397) and skip grouping, andboolwithout boolalpha goes through the vtable'slongslot, so an override is honoured.Nothing to change that I could find.
Not run here; this is from reading the code.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:56:20Z.
Review: APPROVED
Reviewed — looks good
The implementation and all changed files listed for review were inspected at head
a08bbb5e78e732d7596ec361990a6a38a16e5ed4; no verified blocking defect was found, and the author reports successful Windows 11 tests and differential checks.What I ran
No commands or tests were run in this review. The prepared diff was reviewed at the exact head above; the base was not independently checked.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, tests, negative control, merged-preview check, or physical-console behavior was run or independently confirmed. The author reports 10 passing tests, differential results, and clean merge checks in the PR description; these remain author-reported. No files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:43:55Z.
Review: COMMENTED
guest_sce_v2_num_put_charpassed witha08bbb5e78and its prerequisite stack integrated into a Linux release build. The test calls the guest facet through its vtable and covers the new chardo_putimplementations through the repository's native target.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.