feat(libc): implement the std::__sce_v2 collate and moneypunct virtuals #17277
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17277"
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-08T17:08:21Z.
What
Builds on #16975: this branch contains its commits, and through them #16949, #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current
main. It needs none of their code, only their place inLocaleSupport.cpp, so it stacks to avoid conflicts. Until they merge, only the last commit is this PR's change.Implement the virtuals of
std::__sce_v2::collate<char>,collate<wchar_t>and the fourmoneypunct<char, Intl>andmoneypunct<wchar_t, Intl>facets, which_Makelocbuilds anduse_facethands tomoney_get,money_put,regexand any caller that sorts or hashes strings by locale. Before this PR, each of their 24 slots threwNotImplemented_nid_no_patch. These slots are not exports, so this PR adds no NID.The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6), vtables0x18C868and0x18CF70(collate),0x18CB30,0x18C9C8,0x18D1A8and0x18D088(moneypunct):collate::do_comparecalls_Strcollor_Wcscoll, which in this module ignore the collation data: they compare the common prefix as unsigned code units, then the lengths. The facet returns -1, 0 or 1.collate::do_transformgrows the result with_Strxfrmor_Wcsxfrm, which copy the range when it fits. The result is the range itself, null bytes included, with the capacity a direct construction gives. Awchar_trange of an odd byte count yields that many characters rounded down, all zero, because the copy never fits.collate::do_hashis 64-bit FNV-1a over the range's bytes. Forwchar_tthat is both bytes of each character, not the character values.moneypunctreturns its fields:do_decimal_pointanddo_thousands_septhe characters at0x18and0x19(0x1aforwchar_t),do_groupingastringof the bytes at0x10,do_curr_symbol,do_positive_signanddo_negative_signa string of the facet's type from0x20,0x28and0x30,do_frac_digitsthe word at0x38, anddo_pos_formatanddo_neg_formatthe four pattern bytes at0x3cand0x40. BothInternationalvalues share these functions.AssignSceV2StringandAssignSceV2WideStringnow share the layout code with the transform throughReserveSceV2String; their output is unchanged. The_Makelocdebt entry lists the new facets among the working ones, and a new entry records the one difference: the module truncates collation lengths to 32 bits.Tested
Windows 11, MinGW GCC 15.2, Release, head on top of #16975. Not run on Linux or macOS, not run in a title.
guest_sce_v2_collate_moneypunct: ordering, unsigned code units, prefixes and null bytes indo_compare; short, long, empty and odd-sized ranges indo_transform, with their capacities; pinned FNV-1a values indo_hash; everymoneypunctslot for both character types and bothInternationalvalues, on the C locale's facets and on facets with set fields._Makelocand the module's own_Strcoll,_Strxfrm,_Wcscolland_Wcsxfrm. Inputs: random ranges up to 4,200 code units with null bytes, high bytes, shared prefixes, odd byte counts forwchar_tand null pointers for empty ranges; andmoneypunctfacets whose fields are set to random characters, strings up to 4,200 units, digit counts and patterns. It compares results, the returned string's 32 bytes, contents and terminator, and the allocations each side makes.moneypunctslots: 36 calls, 0 differences.collatecalls (with about 179,000 heap-allocated results and all three orderings) and 225,000moneypunctcalls.guest_sce_v2_*, locale, string andpublic_headerstest): all pass.do_hashper character, the mutated code steps past the end of an odd-sized range and the harness crashes before its first comparison.check_conventions,git diff --check: clean. Merges cleanly withmain.pr_overlapreports no open PR with the same functions or conflicting code; it could not compare 45 PRs that conflict withmainon shared files, and of the 4 that touchLocaleSupport.cpp(#9526, #11172, #12518, #12704) none adds 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 PrivacyOnion on 2026-11-08T18:30:27Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a8263bfa80:tools/check_conventions.pypassed;git diff --checkclean.guest_sce_v2_char_facet_virtuals_tests,guest_sce_v2_codecvt_wide_tests,guest_sce_v2_collate_moneypunct_tests,guest_sce_v2_facet_ids_tests,guest_sce_v2_makeloc_tests,guest_sce_v2_num_get_char_tests,guest_sce_v2_num_get_wide_tests,guest_sce_v2_num_put_char_tests,guest_sce_v2_num_put_wide_testsfailed to build.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T22:02:26Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3701c28f26:tools/check_conventions.pypassed;git diff --checkclean.guest_sce_v2_char_facet_virtuals_tests,guest_sce_v2_codecvt_wide_tests,guest_sce_v2_collate_moneypunct_tests,guest_sce_v2_facet_ids_tests,guest_sce_v2_makeloc_tests,guest_sce_v2_num_get_char_tests,guest_sce_v2_num_get_wide_tests,guest_sce_v2_num_put_char_tests,guest_sce_v2_num_put_wide_testsfailed to build.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T21:09:25Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
225eb97633:tools/check_conventions.pypassed;git diff --checkclean.guest_sce_v2_char_facet_virtuals_tests,guest_sce_v2_codecvt_wide_tests,guest_sce_v2_collate_moneypunct_tests,guest_sce_v2_facet_ids_tests,guest_sce_v2_makeloc_tests,guest_sce_v2_num_get_char_tests,guest_sce_v2_num_get_wide_tests,guest_sce_v2_num_put_char_tests,guest_sce_v2_num_put_wide_testsbuilt cleanly.guest_sce_v2_makeloc,guest_sce_v2_char_facet_virtuals,guest_sce_v2_num_put_char,guest_sce_v2_num_put_wide,guest_sce_v2_codecvt_wide,guest_sce_v2_collate_moneypunct,guest_sce_v2_num_get_char,guest_sce_v2_num_get_wide,guest_sce_v2_facet_ids):core/libs/prx/libc/include/Api.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T21:40:27Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
a8ba18cdfdea3ce9cd911872908dc4402b32ca26, basemain. The diff is the whole stack againstmain, not only the last commit (see Findings).description.md,commits.md,manifest.json,files.json, and all ofdiff.patch(13 reviewed files, no exclusions) in paged reads.Results
mainRaw reader output
Findings
Blocking
None.
Non-blocking
The char and wchar_t money and numpunct facets ignore parts of localeconv that the unsigned short facets copy.
core/libs/prx/libc/src/LocaleSupport.cpp:1653sets thecharnegative sign tog_sceV2Minusand the positive sign to empty, and:1593sets grouping to empty. The unsigned short facets readmonetary[5],monetary[6]andgroupingfrom localeconv (:1689,:1621). The tests pin the empty currency forchar(core/libs/tests/GuestSceV2Makeloc.cpp,TestConventions) but not the signs or the grouping under a non-C localeconv. Confirm against the module, or add a case. Failure scenario: a locale whosemonetarynegative sign is(, wheremoneypunct<char>::do_negative_signreturns-and the unsigned short facet returns(.Wide ctype table ownership differs from narrow.
core/libs/prx/libc/src/LocaleSupport.cpp:752frees the table for any nonzerodeleteMode. The narrow destructor at:746-747frees for> 0and calls the array delete for< 0.GuestSceV2Makeloc.cppsets-1on the wide facet and expects a plain free. If the module distinguishes the two, a wide facet built with the array mode would be released withfree. Not verified against the module.The diff is larger than the description says. The description states that only the last commit is this PR's change while the others merge.
diff.patchagainstmainincludes the ctype, numpunct, num_put, num_get and codecvt virtuals and the facet framework (core/libs/prx/libc/src/LocaleSupport.cpp:647onward), roughly 4,000 added lines beyond the collate and moneypunct work. A reviewer who trusts the description would review the wrong scope. Either the description or the base should change before merge.Not verified
$+xvdefault pattern, facet ids and vtable slot indices) were checked for internal consistency between the tests and the code, not againstlibc.prx.UseSceV2Facetand the per-call cost of its locking and grouping copy were not measured.files/was not opened; every reviewed file was read through its hunks indiff.patch.To get this to a good state
Nothing is required. The non-blocking points above are optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T12:21:20Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
c3dfec0334f9bb794ecd816826f8acfd1015eddd. I read the prepared description, commit list, diff, manifest, and the changed implementation ranges for thecollateandmoneypunctvirtuals. I did not run commands or tests; the description reports Windows 11/MinGW GCC 15.2 tests and a clean merge withmain.Results
Findings
Blocking
None identified in the inspected implementation.
Non-blocking
None.
Not verified
I read the changed ranges in
core/libs/prx/libc/src/LocaleSupport.cppthat implement the target virtuals, plus the description, commits, manifest, and diff. I did not read every changed file listed in the manifest, including the complete test files, and did not run tests or independently verify the reported behavior. The review bundle’s file manifest indicates 11 changed files; complete changed-file coverage was not established.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:18:02Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
8b870d3f838d4765325df1807e178a16b96afd0cfrom the prepared patch and pinned repository reader. No tests or build commands were run.Results
Findings
Blocking
None found in the inspected code.
Non-blocking
SceV2CollationLengthdivides the byte distance bysizeof(Text)before comparing. That matches the stated behavior for valid ranges; malformed ranges withlast < firstare not guarded, and their behavior was not established by the review.Not verified
No programmatic checks were run. I read all files marked included in the manifest:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cpp, the seven addedcore/libs/tests/GuestSceV2*.cppfiles, anddocs/dev/debt/libc.md. No changed files were excluded. The reported Windows build, tests, differential harness, negative control, merge check, and console behavior were not independently verified.To get this to a good state
Nothing is required. The author-reported checks provide useful supporting evidence; no additional action is required for this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:12:36Z.
Review: COMMENTED
Built the branch’s locale implementation and matching headers against the existing Linux runtime. The focused
GuestSceV2CollateMoneypunctfixture passed.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.