feat(libSceIcu): implement the UText framework and the UChar string provider #23900
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23900"
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 larpsahur333 on 2026-11-19T21:17:53Z.
What
Twenty-two
libSceIcuexports that answeredNotImplemented_nid_no_patchnow implement the UText framework and the UChar string provider, ported from ICU 68.2'sutext.cpponto the guestUTextlayout:utext_openUChars,utext_setup,utext_cloneutext_getNativeIndex,utext_setNativeIndex,utext_getPreviousNativeIndex,utext_moveIndex32,utext_next32,utext_previous32,utext_next32From,utext_previous32From,utext_current32,utext_char32Atutext_nativeLength,utext_extract,utext_replace,utext_copyutext_equals,utext_isWritable,utext_freeze,utext_hasMetaData,utext_isLengthExpensiveutext_closewas already implemented inUText.cppand still handles the shared close protocol; this branch supplies the accessors and the provider it closes over.The layout is not guessed.
UTextAccess.cppasserts at compile time that theUTextfields land on the offsetsUText.cppalready uses (magic 0, flags 4,extraSize24,chunkNativeStart32,chunkContents48,pFuncs56,pExtra64,context72,a112, 144 bytes total) and thatUTextFuncsputscloseat offset 80, which is the slotutext_closereads. A guest-providedUTextand one the library allocates therefore share one layout, and the provider's function table isAPS5_VABIso guest code can call it through theutext_next32-style macros.Still stubs, on purpose:
utext_openUTF8,utext_openUnicodeString,utext_openConstUnicodeString,utext_openReplaceableandutext_openCharacterIterator. Their providers need the UTF-8 chunker and the guestUnicodeString,ReplaceableandCharacterIteratormodels, which this library does not have yet; implementing them against the host ICU types would repeat the bundle-model mistake.tools/progress.py:libraries 17536/39550 (44.34%)before,17571/39563 (44.41%)after;libSceIcualone291/2759 (10.55%)to326/2772 (11.76%).Overlap with #23859
This branch and #23859 both edit
Export.cpp,include/InventoryExports.hpp,include/LegacyExports.hpp,LegacyExports.cpp,libSceIcu.hppandCMakeLists.txt, but they touch different exports and their hunks do not depend on each other. They conflict textually only; merge either one first and I will rebase the other.Tested
Windows 11 x86-64, MinGW-w64 GCC 15.2.0 (
x86_64-ucrt-posix-seh, WinLibs15.2.0posix-14.0.0-ucrt-r7), CMake 3.29.2, Ninja.guest_icu_utext(new,core/libs/prx/libSceIcu/tests/UTextAccess.cpp) passes on a guest-providedUTextoverA, U+1F600,B:utext_openUCharsfills the supplied struct,utext_nativeLengthis 4, the index starts at 0utext_next32returnsA, then joins the surrogate pair to U+1F600 and leaves the index at 3utext_current32,utext_previous32,utext_setNativeIndex,utext_char32At,utext_getPreviousNativeIndex,utext_moveIndex32,utext_next32Fromandutext_previous32Fromall agree on that textutext_extractreturns the four units plus the terminator, and reports a preflight of 4 with an overflow status for a two-unit bufferutext_clonefills a second supplied struct, copies the length, andutext_equalsis false across different positions and true from the same oneutext_replaceandutext_copyreturnU_NO_WRITE_PERMISSIONon this read-only provider, andutext_freezeclears writability on the cloneU_SENTINELThe whole ICU suite passes:
ctest -R "^guest_icu"reports100% tests passed, 0 tests failed out of 77.python core/libs/tests/test_public_headers.py --compiler g++:413 libraries, 34733 exports: unique declarations and umbrella coverage verified.python3 tools/debt_fold.py --checkpasses.Not tested: no PS5 was involved, so the console's answers are unmeasured. A
UTextthe library allocates takes its storage from the guest heap, which needs the relinked program's process metadata, so the test uses supplied structs; a real program gets the heap path. The UTF-8,UnicodeString,ReplaceableandCharacterIteratoropeners stay stubs.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 repositoryImported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T21:30:54Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
846aacfb8e:tools/check_conventions.pypassed.guest_icu_utext_testsbuilt cleanly.guest_icu_utext):core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp,core/libs/prx/libSceIcu/libSceIcu.hpp,core/libs/prx/libSceIcu/UTextAccess.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 PrivacyOnion on 2026-11-19T21:33:54Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
909f6d41b8:tools/check_conventions.pypassed.guest_icu_utext_testsbuilt cleanly.guest_icu_utext):core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp,core/libs/prx/libSceIcu/libSceIcu.hpp,core/libs/prx/libSceIcu/UTextAccess.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-20T12:02:30Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation has no verified blocking defect; runtime checks were not run in this review.
What I ran
Inspected the prepared diff and relevant code at head
6c44b93a33b3e709d591aad96b1b0086d18996e6usingrepo_read.pyreader tools. No build or tests were run. The author reports Windows tests and checks in the PR description; those results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
length == -1and iteration across the provider’s 32-unit chunk boundary. The added test exercises a known-length short string and does not cover these paths (core/libs/prx/libSceIcu/tests/UTextAccess.cpp:28).Sources
Reviewed the prepared diff and the implementation at the pinned head, including
UText.cppfor the existing close protocol andStatus.hppfor status handling.Not verified
Build and test results reported by the author were not rerun. PS5 behavior and guest-heap allocation were not tested. The full text of
LegacyExports.cppandLegacyExports.hppwas not read; their changed removals were reviewed in the diff. All 10 changed files were listed in the review manifest, and their changed hunks were inspected.To get this to a good state
Nothing is required. Optional: add tests for null-terminated input and chunk-boundary iteration.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:21:01Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: handle empty and boundary positions safely in
utext_extractand the UChar provider access routine.What I ran
Read the prepared diff and all changed files listed as included in the review manifest. Inspected
UText.cpp,Configuration.cpp, andTerminateBuffer.cppfor close, allocation, and extraction behavior. No build or tests were run; the test results in the PR description are author-reported.Results
Findings
Blocking
core/libs/prx/libSceIcu/UTextAccess.cpp:209:StringExtractcallsStringAccessand then readstext->chunkContentsandtext->chunkOffset. For an empty string, or whenstartis beyond the known string length,StringAccesscan return unavailable without setting a valid offset; extraction then readsstring[0]orstring[length]. Clampstartto the known length and return an empty extraction before dereferencing when the requested range has no text.core/libs/prx/libSceIcu/UTextAccess.cpp:163: For a NUL-terminated input shorter than 32 units where a query starts beyond its terminator,StringAccesscan scan past the terminator and read beyond the input. It starts at the cached chunk limit and scans up toindex + 32without first establishing thatindexis within the string. Find/cache the terminator before reading toward an out-of-range index, then clamp the requested index to the discovered length.Non-blocking
None.
Not verified
review/files.jsonwas not available through the review reader. The review folder lists ten changed files, all marked included, and each changed file's added lines were read.To get this to a good state
Fix both out-of-range paths and add regression cases for empty text,
startbeyond a known length, and a NUL-terminated string queried beyond its terminator. Run the new test and the ICU suite on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:34:09Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: keep the existing close protocol valid when a UText is reopened after allocating provider extra space.
What I ran
Reviewed head
62f9fd9d3437969ff6549e3670804a4e28311e31from the prepared diff and pinned reader. No commands or tests were run in this review.Results
Findings
Blocking
core/libs/prx/libSceIcu/UTextAccess.cpp:310— When reopening a caller supplied UText withExtraHeapAllocatedset and a largerextraSpace, setup freespExtrabut does not clearExtraHeapAllocatedbefore attempting the replacement allocation. If allocation fails,utext_closelater sees the stale flag and releases the already-freed pointer again. Clear the flag immediately after releasing the old extra storage, including on allocation failure.Non-blocking
None.
Not verified
The full text of all changed files was included and read:
core/libs/prx/libSceIcu/CMakeLists.txt,Export.cpp,LegacyExports.cpp,UTextAccess.cpp,UTextAccess.hpp,include/InventoryExports.hpp,include/LegacyExports.hpp,libSceIcu.hpp,tests/UTextAccess.cpp, anddocs/dev/debt/changes/feat-libsceicu-utext.md. The prepared diff and manifest were read.files.jsonwas not available in the review folder, so excluded files could not be confirmed from it; the reader file list showed all listed changed files included. Tests reported by the author were not rerun.To get this to a good state
Clear
ExtraHeapAllocatedwhen releasing the priorpExtra, and rerun the ICU tests, including a forced allocation-failure case for reopening a supplied UText.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:10:43Z.
Review: COMMENTED
Built the submitted UText implementation against bundled ICU and ran the exact
UTextAccessfixture on Linux. It passed extraction, cursor, and length checks, including starts at and beyond the 32-unit chunk boundary.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.