feat(libc): wire the numpunct<char> facet vtable and its members #21930
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21930"
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 Herolias on 2026-11-16T22:07:28Z.
What
libc exports the
numpunct<char>vtable (_ZTVSt8numpunctIcE, NIDlJnP-cn0cvQ) as elevenuintptr_tslots, and onmainall eleven are zero. The console'slibc.prxalso exports the facet's six constructors, three destructors,_Initand_Tidy(ps5rslibc.txt), andmain's libc exports none of them. This change fills slots 2 to 10 and adds those eleven exports to libc. It is the piece #21537's description listed as missing: "the exportednumpunct<char>constructors are absent, so nothing builds a facet on the exported object yet".How code reaches it: Dinkumware defines all six constructors, the destructor and
_Initinside the class (crt.vc12xlocnumlines 72-228), so a guest that constructs anumpunct<char>, or a class derived from it, writes the exported vtable into the object and calls these members either inline or through the libc imports. Onmainany call through that vtable faults, and the libc imports of the constructors and destructors are absent. I know of no title that does this. None of the eight title import lists (#265-#272) holds one of the twelve NIDs, but those lists name only the NIDs that were new when they were posted, so that shows nothing either way. This PR claims no unblocked title. Like #21170 (messages<char>) and #21537 (ctype<char>), it completes an exported vtable from sourced code.RetainFacetandReleaseFacet(the_Incref/_Decrefof libc's other facets), and thendo_decimal_point,do_thousands_sep,do_grouping,do_falsenameanddo_truename, whichmainalready implements. That is the Itanium order of_Facet_base's virtuals followed bynumpunct's (microsoft/STLxfacetlines 26-36,xlocnumlines 160-222) and the orderGuestLocale::NumpunctVtablealready records. Offset-to-top and typeinfo stay zero, as in the other filled vtables._Init(1LvbNeZZJ-o): follows crt.vc12xlocnumlines 161-188 and microsoft/STL lines 181-202. It nulls the three string pointers, then copieslocaleconv()'s grouping (or""when_Isdefis set),"false"and"true"into new blocks. If an allocation fails it runs_Tidyand rethrows. It then takes.and,when_Isdefis set, and otherwise the first byte oflocaleconv()'s decimal point and thousands separator._Locinfo::_Getlconv,_Getfalseand_Gettrueare inline in both sources and returnlocaleconv(),"false"and"true"(crt.vc12xlocinfolines 125-128 and 165-173), so_Initnever reads the_Locinfoobject itself.main'slocaleconv()is a fixed C-locale table read from Astro's Playroom'slibc.prx(libc.md, localeconv), which holds the same"false"and"true"in its_False/_Truefields.operator new[]and_Tidy(fFnht9SPed8) releases them withoperator delete[], as V6.00's_Maklocstrand_Tidydo (crt.vc12xlocalelines 724-738,xlocnumlines 216-221). microsoft/STL usescallocandfreeinstead (xlocalelines 563-579,xlocnumlines 225-229). The console's libc is Dinkumware's, so I followed the Dinkumware release where the two differ; in this libraryfreeandoperator delete[]both release through the application heap (FileAndHeap.cppline 1001,StdioExtras.cppline 143).TEtyeXjcZ0w/1eVdDzPtzD4(size_t),CDm+TUClE7E/Cb1hI+w9nyU(const _Locinfo&, size_t, bool),WK24j1F3rCU/yIn4l8OO1zA(const char*, size_t, bool)): each stores the vtable and the reference count, truncated to the facet's 32-bit counter (locale::facet(size_t), crt.vc12xlocalelines 160-163), then follows crt.vc12xlocnumlines 107-145:(size_t)builds a default_Locinfo, which is"C"(xlocinfoline 71), runs_Initwith_Isdeffalse and replaces a zero thousands separator with,;(const _Locinfo&, size_t, bool)runs_Initwith the given_Isdef;(const char*, size_t, bool)builds_Locinfofrom the name and runs_Init._BEGIN_LOCINFOis that_Locinfoin a scope (crt.vc12yvals.hlines 762-767).main's_Locinfoaccepts only"C"and throwsstd::invalid_argumentotherwise, so these constructors do too, before allocating anything.The C1 and C2 forms are the same function, as the Itanium ABI allows for a class without virtual bases. The mangled names fix the parameter types (
misunsigned long,bisbool;compute_nidof each name gives its NID).qEob3o53s2MD1,xFva4yxsVW8D2,Lf6h5krl2fAD0):~numpunctruns_Tidy(crt.vc12xlocnumlines 134-137), and the deleting destructor then frees the facet withoperator delete._nid_postfixnames. libSceLibcInternal already defines_ZNSt8numpunctIcEC1EPKcmb,_ZNSt8numpunctIcEC2ERKSt8_Locinfomband_ZNSt8numpunctIcED0Evwith that suffix (InventoryExports6.cpp), whichcheck_conventionsrejects asduplicate-export, and exports D2's NID assceLibcInternalUnknown6_119_xFva4yxsVW8, which it rejects asunknown-nid. Those four are_nid_no_patchbodies exported withAPS5_EXPORT, as libc already does for__cxa_finalize(b8a1cbe42b). libSceLibcInternal is unchanged: libc imports never fall back to it (WindowsEntryStubBuilder.cpplines 180-215), and its ownnumpunct<char>members stay as they are onmain._Getcatis unchanged. It still builds its C-locale facet on libc's internal table with static strings (thelibc.md_Getcatentry), so facets fromuse_facetthrough libc's_Getcatnever reach the new destructors.What still throws, and why:
std::invalid_argument, where the console would fault. This is the host-safety policy of thectype<char>destructors.std::invalid_argumentfor any name other than"C", becausemain's_Locinfodoes.NotImplemented_nid_no_patch.Debt:
docs/dev/debt/changes/feat-numpunct-char-facet.mdchanges thelibc.md"numpunct vtable" entry, which said the slots are zeroed, and adds two Functional entries for_Init/_Tidyand for the constructors and destructors. Each entry is under 1000 characters (914, 897 and 922).Overlap:
tools/pr_overlap.py --namesfor the 67numpunct<char>,numpunct<wchar_t>andcodecvt<wchar_t, char>names found no open PR that implements anumpunct<char>member. #17300 renames libSceLibcInternal'snumpunct<char>stubs, #13449 adds_ZTSSt8numpunctIcE, and #19434 adds a libSceLibcInternal alias of_Getcat. #11172 already wires thecodecvt<wchar_t, char>vtable, so I left that one out.gh search prsfor "numpunct" found 19 open PRs. Their diffs touchnumpunct<char>::id, thestd::__sce_v2facets or other facets. The one that touches_ZTVSt8numpunctIcEis #17610, which moves the zeroed line together with its whole block.tools/pr_overlap.py --branch feat/numpunct-char-facetlists #17300 under "Same exports", because its renamed libSceLibcInternal stubs carry seven of the NIDs that libc now exports. They are different libraries and different symbol names, as with__cxa_finalize.main. I fetched their heads and rangit merge-treeof each againstmainand against this branch, and compared the conflict hunks in every file this branch changes. All 21, and #17300, #17610, #21894, #19434, #13449 and #21220, have the same hunks against both: #7447, #7715, #8150, #8965, #9466, #12717, #12849, #16791, #17345, #17354, #17557, #17558 and #19181 (CMakeLists.txt), #9526 and #11172 (LocaleSupport.cpp,GuestLocale.cpp), #12184 (Api.hpp), #12682, #12688, #12700 and #12965 (CMakeLists.txt,Api.hpp) and #18135 (Api.hpp,GuestLocale.hpp,LocaleSupport.cpp).Not in this PR:
numpunct<char>'s typeinfo_ZTISt8numpunctIcE(ddLNBT9ks2I).mainexports no facet typeinfo,locale::facet's included, and #13449 adds the_ZTSname. A guest class derived fromnumpunct<char>with RTTI needs it.numpunct<wchar_t>vtable (Gtsl8PUl40U), whichmain's libc does not export at all. Both sources take the wide decimal point and separator fromlconv's_W_decimal_pointand_W_thousands_sep(crt.vc12xlocnumlines 154-159, microsoft/STLxlocnumlines 176-179), and the 0x90-bytelconvof the console's libc has no such fields (SonyLconvincore/libs/SceTypes.hpp), so neither source says where the console's_Initgets them.numpunct<char>members.Tested
Fedora Linux 44, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release build with
-DBUILD_TESTING=ON, on913524c1ee(based onmainatec9f142628). No title, no console and no Windows host.tools/select_tests.pyselects 5776 of 5883 tests for this change. 5775 pass and 62 of them skip themselves on this NVIDIA machine. The one failure isagc_driver_image_table_packed_guards("deferred write-back failed: image table ... invalid format"). It fails the same way withmain's copies of this branch's five changed files that exist onmainchecked out and only that test rebuilt, so it comes frommain.guest_numpunct_facet(new) runs_Initand_Tidythrough both entry points with_Isdefset and clear, fails each of the three allocations in turn, and runs every constructor and destructor export, the vtable slots and the null-facet checks against a recording application heap.guest_localenow checks the filled vtable slots on a facet built bynumpunct(size_t)instead of checking that they are zero. Both pass.patched_self_importspasses, andnm -Don the patchedlibc.prxlists all twelve NIDs (the vtable as data, the eleven members as text).LocaleSupport.cpp, each built and run withguest_localeandguest_numpunct_facet. Among them are a zeroed vtable, swapped vtable slots, a missing reference count,_Tidyleaking or reordering,_Initsharing thelconvgrouping, keeping stale pointers, leaking or swallowing a failure, and constructors ignoring_Isdefor the name. 23 fail at least one test. The survivor makesnumpunct(size_t)call_Initwith_Isdefset. That is equivalent here, becausemain'slocaleconv()is a fixed C-locale table (empty grouping and separator,.), so_Initwith_Isdefclear followed by the,fallback builds the same facet. The tests pass again with the code restored.free,operator deleteandoperator delete[]as the same release, so the tests check which blocks are released and in which order, not which of the three functions releases them.x86_64-w64-mingw32-g++16.2.1-fsyntax-onlywith-D_UCRT -D__MSVCRT_VERSION__=0xE00passes forLocaleSupport.cpp,GuestLocale.cppandGuestNumpunctFacet.cpp. Nothing ran on Windows.python3 tools/check_conventions.py --base origin/mainpasses, andpython3 tools/debt_fold.py --checkpasses.Sources
_Incref/_Decreffirstst_size88 measured on PPSA26344'slibc.prx, recorded in thelibc.md"numpunct vtable" entry_Incref,_Decrefand the fivedo_*virtualsstl/inc/xfacetlines 26-36,stl/inc/xlocnumlines 160-222; ganboing/crt.vc12 f1d47126bfsrc/xlocnumlines 134-213_Init: null the strings, copy grouping (or""),"false","true";_Tidyand rethrow on failure;./,with_Isdef, else the first byte of the decimal point and separatorsrc/xlocnumlines 147-188; microsoft/STLstl/inc/xlocnumlines 170-202_Getlconv,_Getfalse,_Gettruereturnlocaleconv(),"false","true"; the default_Locinfois"C"src/xlocinfolines 71, 125-128, 165-173; microsoft/STLstl/inc/xlocinfolines 68, 124-126, 158-164operator new[]blocks released withoperator delete[](microsoft/STL:calloc/free)src/xlocalelines 724-738,src/xlocnumlines 216-221; microsoft/STLstl/inc/xlocalelines 563-579,stl/inc/xlocnumlines 225-229(size_t)with a"C"_Locinfoand the,fallback,(const _Locinfo&),(const char*)src/xlocnumlines 107-145,src/xlocalelines 160-163,src/yvals.hlines 762-767; microsoft/STLstl/inc/xlocnumlines 137-168,stl/inc/xlocalelines 152-154_Tidy; the deleting one then frees the facetsrc/xlocnumlines 134-137; Itanium C++ ABI 5.1.4, "deleting destructor"grouping0x10,decimalPoint0x18,thousandsSep0x19,falsename0x20,truename0x28) and 32-bit reference countGuestLocale::NumpunctFacetandGuestLocale::Facetincore/libs/prx/libc/include/GuestLocale.hpponmain, recorded in thelibc.md_Getcatentry (consolelibc.prx)data/stubs/by_library/libc.txtlines 144, 161, 672, 687, 1074, 1436, 1567, 1983, 2271, 2490, 2801, 2842tools/check_conventions.pycompute_nidgives each listed NID from its namelibc.prximport resolves only in libc among AnyPS5's librariescore/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpplines 180-215APS5_EXPORTfor a NID whose name another library declarescore/libs/prx/libc/Export.cppline 20 (__cxa_finalize,b8a1cbe42b)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-16T22:30:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
913524c1ee:tools/check_conventions.pypassed.guest_locale_tests,guest_numpunct_facet_testsbuilt cleanly.guest_locale,guest_numpunct_facet):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-16T23:21:21Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make allocation failure in
MakeNumpunctStringthrowstd::bad_allocbefore copying.What I ran
Reviewed head
913524c1eec677eae00513422614a0d8cee8ba5ausing the prepared diff and pinned reader; no build or tests were run. The author reports a successful build and tests indescription.md.Results
memcpyas a null pointer.Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:1559—MakeNumpunctStringcalls the throwingoperator new[]wrapper, but that wrapper delegates toAllocate, which returns the application heap result directly. If the heap API returns null without throwing, the nextmemcpydereferences null._Init's catch-and-cleanup path therefore does not handle this failure, despite the statedbad_allocbehavior and the new test expecting it. Check the returned pointer and throwstd::bad_allocbefore copying, or ensure the allocation wrapper translates null to an exception.Non-blocking
None.
Sources
_Initcleanup path are incore/libs/prx/libc/src/LocaleSupport.cpp:1557andcore/libs/prx/libc/src/LocaleSupport.cpp:1584.operator new[]delegates toAllocateincore/libs/prx/libc/src/StdioExtras.cpp:110;Allocatedirectly returns the heap allocation result incore/libs/prx/libc/src/StdioExtras.cpp:25.std::bad_allocincore/libs/tests/GuestNumpunctFacet.cpp:34andcore/libs/tests/GuestNumpunctFacet.cpp:385.Not verified
No commands, build, or tests were run. I read all seven changed files listed in the manifest; no files were excluded by the manifest.
To get this to a good state
Make
MakeNumpunctStringconvert a null allocation result tostd::bad_alloc, then rerunguest_numpunct_facetand the reported build and convention checks on the updated head.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T00:17:59Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2ba615ab6c:tools/check_conventions.pypassed.guest_locale_tests,guest_numpunct_facet_testsbuilt cleanly.guest_locale,guest_numpunct_facet):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._ZTVSt8numpunctIcE_nid_postfixvtable layout incore/libs/prx/libc/src/LocaleSupport.cpp:816-828: slots 0-1 are zero (offset-to-top, RTTI), slots 2-10 correctly mapdestroy,deleteObject,retain,release, and fivedo_*methods matching Dinkumware / libc ABI order.MakeNumpunctStringandNumpunctInit_nid_no_patch(LocaleSupport.cpp:1556-1598): verified exception safety,std::bad_alloccheck on null allocation, and proper cleanup viaNumpunctTidy_nid_no_patchin the catch handler._Init, and_Tidyexports inLocaleSupport.cpp:1571-1632: each properly guardsself == nullptrwithAPS5_INVALID_ARG_EX.ConstructNumpunctBaseand constructors (LocaleSupport.cpp:1564-1622):referencesis properly initialized asuint32_tandvtablepoints to_ZTVSt8numpunctIcE_nid_postfix[2].docs/dev/debt/changes/feat-numpunct-char-facet.mdand test coverage inGuestNumpunctFacet.cppandGuestLocale.cpp, confirming AGENTS.md rules compliance, absence of forbidden code comments, and full heap failure / argument validation tests.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T00:24:46Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation and tests show no verified blocking defect; the reported build and test results were not independently run in this review.
What I ran
Read the prepared diff and review metadata for head
2ba615ab6c64b7ee46e1feb265ff45ff73a00e03, then inspected the changed implementation, declarations, and test code throughrepo_read.py. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run independently. The review folder lists seven changed files, all included. Read:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cpp, and the prepared diff forcore/libs/prx/libc/include/Api.hpp,core/libs/tests/GuestLocale.cpp,core/libs/tests/GuestNumpunctFacet.cpp, anddocs/dev/debt/changes/feat-numpunct-char-facet.md. The full text of every changed file was not read. No files were excluded by the manifest.To get this to a good state
Nothing is required. The build and test results reported in the description remain unverified here.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:36:23Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the checks reported for the exact head support merging, and the source review found no verified blocking defect.
What I ran
Reviewed head
caf99e04ab9ff1499882e4fd81089a68dd660408usingrepo_read.py. No build or tests were run during this review; test results below are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not independently run the build, tests, convention checks, or negative controls, and did not inspect console behavior. Reviewed all seven files listed in
manifest.jsonunderreviewed; none were excluded by rule. Full changed-file texts were not available in the prepared review folder; inspected the relevant implementation range throughrepo_read.pyand the changed lines indiff.patch. Other unchanged callers and contexts were not read.To get this to a good state
Nothing is required.