Repository navigation
feat(libc): wire the numpunct<char> facet vtable and its members - #21930
Conversation
Fill libc's exported numpunct<char> vtable and export the facet's constructors, destructors, _Init and _Tidy, following Dinkumware's numpunct (crt.vc12 xlocnum, microsoft/STL xlocnum). _Init copies the C-locale grouping and the false and true names into operator new[] blocks, the size_t constructor turns a zero separator into ',', and the destructors release the three blocks before the deleting one frees the facet. Four of the exports go through APS5_EXPORT because libSceLibcInternal already declares their names or exports their NID as an Unknown alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 913524c1ee:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_locale_tests,guest_numpunct_facet_testsbuilt cleanly. - CTest (
guest_locale,guest_numpunct_facet):1/2 Test #1340: guest_locale ..................... Passed 0.02 sec 2/2 Test #1341: guest_numpunct_facet ............. Passed 0.02 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
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. - Code reading:
- Verified _ZTVSt8numpunctIcE_nid_postfix vtable layout (11 slots, slots 0-1 zero, slots 2-10 matching Dinkumware / libc facet ABI order) and NumpunctVtable offsets
- Audited NumpunctInit_nid_no_patch, NumpunctTidy_nid_no_patch, and MakeNumpunctString memory handling and exception safety during heap allocation
- Checked null pointer validation across all new exported constructors, destructors, Init, and Tidy methods (_ZNSt8numpunctIcE* and Numpunct*), verifying APS5_INVALID_ARG_EX guards
- Verified technical debt fragment docs/dev/debt/changes/feat-numpunct-char-facet.md format and documentation of C-locale fallback and invalid_argument behavior
- Audited test coverage in GuestNumpunctFacet.cpp and GuestLocale.cpp covering C1/C2 constructors, D1/destroy/deleteObject destructors, reference counting, allocation failure recovery, and null arguments
Looks Good To Me
Progress report (102cad6 → caf99e0)📈 System libraries: 46.95% (+0.01%, +11 implemented functions) ✅ 11 implemented
Changed libraries (implemented exports)
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: make allocation failure in MakeNumpunctString throw std::bad_alloc before copying.
What I ran
Reviewed head 913524c1eec677eae00513422614a0d8cee8ba5a using the prepared diff and pinned reader; no build or tests were run. The author reports a successful build and tests in description.md.
Results
| Check | Result | Note |
|---|---|---|
| Changed source review | failed | Allocation failure can reach memcpy as a null pointer. |
| Build and tests | not run | Author-reported results only. |
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
- The helper and
_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.- The new failure test configures a null-returning allocator and expects
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 MakeNumpunctString convert a null allocation result to std::bad_alloc, then rerun guest_numpunct_facet and the reported build and convention checks on the updated head.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MakeNumpunctString now throws std::bad_alloc when operator new[] returns null, before memcpy, as review requested. operator new[] already throws there: ApplicationHeapAllocate_nid_no_patch passes the heap callback's result through requireAllocation (ApplicationHeap.cpp lines 106-109), so behaviour does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@MarcZX10 2ba615a adds the check: Behaviour does not change. Checked on this head (Fedora 44, GCC 16.2.1):
|
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 2ba615ab6c:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_locale_tests,guest_numpunct_facet_testsbuilt cleanly. - CTest (
guest_locale,guest_numpunct_facet):1/2 Test #1344: guest_numpunct_facet ............. Passed 0.00 sec 2/2 Test #1343: guest_locale ..................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
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. - Code reading:
- Verified
_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. - Audited dynamic memory handling in
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. - Verified null pointer checks across all newly added constructor, destructor,
_Init, and_Tidyexports inLocaleSupport.cpp:1571-1632: each properly guardsself == nullptrwithAPS5_INVALID_ARG_EX. - Verified reference count truncation and initialization in
ConstructNumpunctBaseand constructors (LocaleSupport.cpp:1564-1622):referencesis properly initialized asuint32_tandvtablepoints to_ZTVSt8numpunctIcE_nid_postfix[2]. - Audited
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.
- Verified
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
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 through repo_read.py. No build or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | No blocking defect verified |
| Build and tests | not run | Results in the PR description are author reported |
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 for core/libs/prx/libc/include/Api.hpp, core/libs/tests/GuestLocale.cpp, core/libs/tests/GuestNumpunctFacet.cpp, and docs/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.
|
Works on Windows and nothing blocks. Merged onto current Existing runs: the author, Herolias, tested on Fedora Linux only and wrote that nothing ran on Windows. PrivacyOnion approved What this run adds
Code
Negative control and mutation Line numbers are at
Tests
Times are in seconds. All runs pass. Host
AI-assisted: yes |
# Conflicts: # core/libs/prx/libc/CMakeLists.txt
MarcZX10
left a comment
There was a problem hiding this comment.
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 caf99e04ab9ff1499882e4fd81089a68dd660408 using repo_read.py. No build or tests were run during this review; test results below are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed implementation and test diff inspected |
| Build and tests | not run | Results supplied in PR description |
| Negative control | not run | Not independently verified |
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.json under reviewed; none were excluded by rule. Full changed-file texts were not available in the prepared review folder; inspected the relevant implementation range through repo_read.py and the changed lines in diff.patch. Other unchanged callers and contexts were not read.
To get this to a good state
Nothing is required.
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(b8a1cbe). 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. refactor(prx): name the libSceLibcInternal export aliases the NID databases resolve #17300 renames libSceLibcInternal'snumpunct<char>stubs, feat(libc): expose 345 read-only runtime data exports #13449 adds_ZTSSt8numpunctIcE, and feat(libSceLibcInternal): forward the firmware libc-internal export surface #19434 adds a libSceLibcInternal alias of_Getcat. feat(libc): wire the codecvt<wchar_t,char> facet vtable #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 feat(libc): fill the std::__sce_v2 classic locale with its facets #17610, which moves the zeroed line together with its whole block.tools/pr_overlap.py --branch feat/numpunct-char-facetlists refactor(prx): name the libSceLibcInternal export aliases the NID databases resolve #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 refactor(prx): name the libSceLibcInternal export aliases the NID databases resolve #17300, feat(libc): fill the std::__sce_v2 classic locale with its facets #17610, feat(libSceLibcInternal): parse numbers in num_get::do_get #21894, feat(libSceLibcInternal): forward the firmware libc-internal export surface #19434, feat(libc): expose 345 read-only runtime data exports #13449 and feat(libc): wire the num_put<char> and codecvt<char> facet vtables #21220, have the same hunks against both: feat(libc): support archive-backed stdio reads #7447, fix(libc): provide ASOBI_ROOT environment variable for title path resolution #7715, fix(libc): support character reads from random device streams #8150, fix(libc): use the Annex K size limit and codes of the PS5 libc, as measured on a PS5 #8965, feat(libc): add the C locale helpers _Getctype, _Getcoll, _Getcvt, _Getdateorder, _Strcoll and _Strxfrm #9466, feat(libc): add SSE2 paths for trivial search and min helpers #12717, fix(libc): optionally reclaim and lazily commit small heap spans #12849, fix(videoout): end shutdown when a host thread cannot unwind #16791, perf(libc): search memrchr by block and memccpy with memchr #17345, perf(libc): find strnlen terminators with memchr #17354, feat(relinker): emit per-NID call hook table #17557, feat(tools): nid_names client for the debugger #17558 and feat(libc,libkernel,agc): name host threads on Linux #19181 (CMakeLists.txt), feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526 and feat(libc): wire the codecvt<wchar_t,char> facet vtable #11172 (LocaleSupport.cpp,GuestLocale.cpp), feat(libc): implement __std_calloc_crt allocation wrapper #12184 (Api.hpp), feat(libkernel): cancel blocked POSIX reads with owned operations #12682, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700 and feat(libkernel): support deferred cancellation in POSIX accept #12965 (CMakeLists.txt,Api.hpp) and feat(libSceLibcInternal): construct the moneypunct facet and answer its members #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 feat(libc): expose 345 read-only runtime data exports #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, b8a1cbe)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)