feat(libc): implement std::_Throw(const std::bad_array_new_length&) #10927
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10927"
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 edubox on 2026-10-25T10:42:44Z.
What
Implement
_ZSt6_ThrowRKSt20bad_array_new_length(1cKlQv7Kvmg), imported by Star Wars Racer (PPSA28416) fromlibc.The
libc.prxbundled with PRAGMATA PPSA02530 exports it as a 52-byte function at0xcb2d0(static disassembly): it ignores its argument, allocates the 8-byte exception object, installs the static_ZTVSt20bad_array_new_length, and calls__cxa_throw. The implementation reusesLibcException::ThrowPlainwith that vtable, the same path as__cxa_throw_bad_array_new_length; the argument is deliberately unused, as on the console. A guest test checks the type record, base (std::bad_alloc), vtable and that the call throws, and the debt entry records the console evidence.Overlap: #9416 adds a
void*placeholder for_ZSt6_ThrowRKSt20bad_array_new_lengthtolibc/Export.cppthat throwsstd::runtime_error; I asked its author to drop it (https://github.com/boykopovar/AnyPS5/pull/9416#issuecomment-6396798596). This PR is the real implementation and does not build on #9416, but the two exports cannot both land. #9416 also already conflicts with currentmainon theErrorCodelayout (pre-existing, not caused by this PR). The otherdocs/dev/debt/libc.mdandCMakeLists.txtoverlaps are unrelated entries.Tested
Linux, CachyOS 7.3.0, GCC 16.2.1,
mainb2c7a38840+ this PR:guest_throw_bad_array_new_lengthpasses.guest_bad_optional_accesspasses.python3 tools/check_conventions.py --base origin/mainpasses.The console evidence is static disassembly of the retail
libc.prx, not a live console measurement; the title itself was not run.Checklist
main; no other open PR implements itNotImplemented_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 MarcZX10 on 2026-10-25T13:40:21Z.
Review: DISMISSED
Reviewed exact head
5710c87e1aad77032f6d0e0484494220a8ddfb3a. The export body reuses the existingThrowPlainpath with_ZTVSt20bad_array_new_length, and the type record correctly derives frombad_alloc; the static console evidence and scope are clearly described. I rang++ -std=c++20 -Wall -Wextra -Werror -Icore/libs -fsyntax-only core/libs/tests/GuestThrowBadArrayNewLength.cpp,tools/check_conventions.py --base upstream/main --head HEAD, andgit diff --check upstream/main...HEAD; all passed. I could not run the linked CTest target in this checkout because the third-party submodules are uninitialized.One test gap:
GuestThrowBadArrayNewLength.cppcatches..., so it passes if the export throws a different exception type (for example,bad_alloc) even though the purpose of this symbol is to throwstd::bad_array_new_length. Please assert the caught dynamic type, and fail if a different exception is caught; retaining the RTTI/vtable layout checks is useful but does not verify the type thrown by this entry point.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:39:24Z.
Review: APPROVED
Reviewed — approved
The export is correct (NID
1cKlQv7Kvmgmatches the name, it throwsstd::bad_array_new_lengththrough the existingThrowPlainpath), it merges cleanly onto currentmain, and the new test passes and fails under two negative controls. I have one non-blocking note on the wording of the debt entry.What I ran
Head
f94297b8c2138ef9b963c8e25f9df7f40ab132damerged (--no-ff) ontomaind71fe2fa87f8d74b14ad86506b5f0ed916b33a70in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, Release, Ninja,BUILD_TESTING=ON.Results
maincore/libs/prx/libc/CMakeLists.txtauto-merged)git diff --checkcheck_conventions.py --base origin/mainlibsand the three test targets)guest_throw_bad_array_new_lengthguest_bad_optional_access,exception_runtime_ZSt6_ThrowRKSt20bad_array_new_length1cKlQv7Kvmg, matches the description and debt entrylibc.prx0000000000108020 T 1cKlQv7Kvmgctest
Negative control
core/libs/prx/libc/include/Api.hppandcore/libs/prx/libc/src/exception/StandardExceptions.cppfrommain. The test no longer compiles (_ZSt6_ThrowRKSt20bad_array_new_length_nid_postfixnot declared). This matches the Windows result reported earlier in the thread.std::bad_alloc(ThrowPlain(_ZTVSt9bad_alloc_nid_postfix)) and rebuilt.guest_throw_bad_array_new_lengththen fails (Subprocess aborted). This confirms the fix for the earlier review'scatch (...)gap: the test now rejects the base type. With the file restored, the test passes again.Findings
Blocking
None.
Non-blocking
docs/dev/debt/libc.md:194: the entry describes the console function and the implementation but never names a gap. CONTRIBUTING.md asks that an entry "states the gap first (what differs from the console, what is unverified, what throws)". The open point is that the evidence is static disassembly of thelibc.prxbundled with PPSA02530, while the importer is PPSA28416, and it was not checked at runtime. Suggested wording: lead with "Unverified at runtime; follows static disassembly of thelibc.prxbundled with PPSA02530 …". Alternatively, if maintainers consider the behaviour settled, drop the entry and keep the evidence in the PR body.Not verified
libc.prx(PPSA02530,0xcb2d0). I have no copy and took the description's reading as given.