feat(libSceIcu): implement the string and UTF-8 character iterators #11136
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11136"
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 mantavisual on 2026-10-25T19:23:07Z.
What
Implements
uiter_setStringanduiter_setUTF8, two exports that firmware 13.42'slibSceIcuhas (BunnyFl's export list). They fill a caller-ownedUCharIterator, ICU's C character iterator, which callers then drive through its function pointers:getIndex,move,hasNext,hasPrevious,current,next,previous,getStateandsetState. 13.42 also exportsucol_strcollIter, which consumes such iterators.The code is a port of ICU 78.1's uiter.cpp: the no-op,
char16_tstring and UTF-8 iterators. They are installed into the public 112-byteUCharIteratorlayout from uiter.h. The callbacks use the guest ABI, so guest code can call them, and they carry the_nid_no_patchsuffix because they are helpers, not exports.u_strlen's orstrlen's 32-bit result. Anything else installs the no-op iterator: index 0,U_SENTINELfor code units,UITER_NO_STATE, andsetStatereportsU_UNSUPPORTED_ERROR. A null iterator is ignored.UPRV_NO_SANITIZE_UNDEFINEDfunctions.moveclamps to start/limit, an unknown origin returns −1, the state is the index, andsetStatechecks the error, the iterator and the bounds in ICU's order.reservedFieldbetween them.byte offset << 1 | inside-pair, andsetStatevalidates it as ICU does.movefollows ICU's shortcuts and itsUITER_UNKNOWN_INDEXresults. That includes one quirk, which is kept: when an unknown-index forward move reaches the end, the index ICU has just computed is overwritten by the running position.U8_NEXT_OR_FFFDand fromU8_PREV_OR_FFFD'sutf8_prevCharSafeBody(..., -3)in utf8.h and utf_impl.cpp, with their validity bit tables.A callback given a null iterator, and the no-op
setStategiven a null error pointer, throwAPS5_INVALID_ARG_EX, since ICU dereferences them. The string and UTF-8setStateaccept a null error pointer as ICU does. The new debt entry records the port and that nothing is compared with a console.Depends on #11132 (stacked on it). The agreed ICU order is #11013 → #10961 → … → #10967 → #11088 → #11115 → #11118 → #11122 → #11132, and this PR comes after #11132. Until those merge, the diff also shows their commits. This PR's own change is the last commit,
428dab7efa.Tested
Windows 11 Pro 23H2, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, on #11132 (c1d9fa2f64).guest_icu_iterator, which drives every iterator only through its function pointers:setState's error, iterator and bound checks. Also explicit lengths with embedded NULs and the empty string.setStaterejections.getState/setStateround trip must restore it.E0lead accept80..9Ftrail bytes fails the forward comparison, and dropping the truncated four-byte case in the backward decoder fails the backward comparison.ctest -R "guest_icu_|patched_libraries": all 8 pass. The NID-patchedlibSceIcu.prxbuilds.tools/progress.py --module libSceIcu: 52 implemented, 0 stubs (+2; the callbacks are not counted).tools/check_test_registration.py build: 1347 test executables, none built and not run.python3 tools/check_conventions.py --base origin/mainpasses. Overlap: no open PR implements or names anyuiter_function (checked 2026-10-25).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 MarcZX10 on 2026-10-25T19:27:25Z.
Review: APPROVED
Reviewed the PR-specific iterator commit
428dab7on its declared stack after #11132. Compared the string and UTF-8 iterator setup, callbacks, lazy UTF-16 indexing, surrogate-pair state, and malformed UTF-8 handling with ICU 78.1uiter.cppanduiter.h. The 112-byte guest layout, callback signatures, state/error ordering, and iterator behavior match the referenced implementation.Local checks on this commit:
g++ -std=c++20 -Icore/libs -Icore/libs/prx/libc/include -fsyntax-onlyforIterator.cppandGuestIcuIterator.cpp: passed.GuestIcuIterator.cppwithIterator.cppdirectly: passed, including the seeded malformed UTF-8 and state/movement cases.python3 tools/check_conventions.py --base upstream/main --head HEAD: passed.The PR reports the full ICU suite and NID-patched library build on Windows; this host run covered the new iterator test only. Hosted eligibility, conventions, intake, labels and report checks pass; product build/test jobs are skipped. The declared dependency on #11132 remains part of the agreed ICU merge order.