feat(libSceIcu): implement u_strCompareIter and u_getUnicodeVersion #13457

Merged
KernelPanicNT merged 1 commit from upstream-pr/13457 into main 2026-10-30 21:50:15 +00:00
KernelPanicNT commented 2026-10-30 15:49:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-10-30T15:49:21Z.


Source of the behaviour

Not measured on a device. Both exports follow ICU 78.1 (release-78.1, commit 049e0d6), the ICU version the tree already follows for libSceIcu. The code is written from ICU's contract, not copied.

Export Input Result
u_strCompareIter(iter1, iter2, codePointOrder) either iterator null, or both the same pointer 0, no callback called
otherwise move(iter, 0, UITER_START) on iter1 then iter2, then next on each in turn until the units differ; both -1 (end) gives 0
units differ, both at least 0xD800 and codePointOrder nonzero a unit outside a surrogate pair is lowered by 0x2800 (a lead checks current, a trail calls previous twice), iter1 first
the difference of the two units
u_getUnicodeVersion(version) null nothing
otherwise writes 17, 0, 0, 0

Where ICU's behaviour is undefined, the export does not invent a result: a null callback that ICU would call throws std::invalid_argument (ICU dereferences it), and the final difference wraps as two's-complement arithmetic instead of overflowing. codePointOrder is read as one byte, nonzero meaning true.

In-tree lines that change: the two throwing placeholders in Export.cpp (zGuhKwXM9I0, TNZrG2iXikw), the end of Version.cpp, libSceIcu.hpp and the debt file.

What

u_strCompareIter (TNZrG2iXikw) and u_getUnicodeVersion (zGuhKwXM9I0) no longer throw; they behave as the table above shows. u_strCompareIter drives caller-owned UCharIterators only through their function pointers, called with the guest ABI, in ICU's order, so a caller's own iterator sees the same calls. The 112-byte UCharIterator layout and the UCharIteratorOrigin constants go in a new Iterator.hpp, with one function pointer type per callback as uiter.h declares them.

Relation to open pull requests:

  • #11136 (string and UTF-8 iterators) does not implement either export. It also adds its own core/libs/prx/libSceIcu/Iterator.hpp declaring the same public ICU struct, and adds u_getVersion next to the same lines of Version.cpp and Version.hpp, as #11115 does. This branch's Iterator.hpp was written separately from uiter.h; the file name is the same on purpose, so the two conflict as files and can never both be built with two definitions of UCharIterator, and whichever merges second keeps one header. #11136's uiter_setString/uiter_setUTF8 iterators can be compared with this export once both are in.
  • #13410 only renames the two placeholders to named stubs that still throw; whichever merges second drops them.
  • #12320 does not implement u_strCompareIter, and #11115 adds u_getVersion (not u_getUnicodeVersion) next to the same lines of Version.cpp and Version.hpp.

A new debt entry records that neither export was compared with a console and the cases above where ICU is undefined.

Tested

  • Linux (GitHub codespace), current main with this branch applied: the new guest_icu_compare_iter passes, and the other six guest_icu_* tests still pass. The test drives the export through a guest-ABI iterator that records every callback, and checks: null and identical iterators (no calls), that iterators starting mid-text are reset, equal texts, empty texts, prefixes, code unit order, code point order with a supplementary character on either side, lone leads and trails, pairs that differ in the trail, units above 0xFFFF, a codePointOrder of 0x80, the exact callback sequence of each case, a null move, next, current or previous (throws only when ICU would call it), and wrapping at INT32_MIN/INT32_MAX. u_getUnicodeVersion writes 17, 0, 0, 0 and nothing past four bytes, and accepts null.
  • Negative control: with both bodies replaced by NotImplemented_nid_no_patch, the test fails with u_strCompareIter_nid_postfix not implemented; with only u_getUnicodeVersion reverted it fails with u_getUnicodeVersion_nid_postfix not implemented.
  • python3 tools/check_conventions.py --base origin/main passes. tools/progress.py against main: +2 implemented functions (u_getUnicodeVersion, u_strCompareIter); libSceIcu 25/124 to 27/124.
  • tools/pr_overlap.py: reports #11136 (same new file Iterator.hpp) and #13410 (renames the same placeholders), both explained above; the other ICU pull requests it could not compare were checked by hand and implement neither export.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5087095246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13457). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-10-30T15:49:21Z. --- ### Source of the behaviour Not measured on a device. Both exports follow ICU 78.1 (release-78.1, commit 049e0d6), the ICU version the tree already follows for libSceIcu. The code is written from ICU's contract, not copied. - `u_strCompareIter`: [ustring.cpp L828-L882](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/ustring.cpp#L828-L882); the iterator layout and callback order from [uiter.h L341-L475](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/unicode/uiter.h#L341-L475), with `UITER_START` at [L52](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/unicode/uiter.h#L52). - `u_getUnicodeVersion`: [uchar.cpp L484-L489](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/uchar.cpp#L484-L489) copies [`dataVersion` {0x11, 0, 0, 0}](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/uchar_props_data.h#L12), which matches [`U_UNICODE_VERSION "17.0"`](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/unicode/uchar.h#L64). | Export | Input | Result | | --- | --- | --- | | `u_strCompareIter(iter1, iter2, codePointOrder)` | either iterator null, or both the same pointer | 0, no callback called | | | otherwise | `move(iter, 0, UITER_START)` on iter1 then iter2, then `next` on each in turn until the units differ; both `-1` (end) gives 0 | | | units differ, both at least 0xD800 and `codePointOrder` nonzero | a unit outside a surrogate pair is lowered by 0x2800 (a lead checks `current`, a trail calls `previous` twice), iter1 first | | | | the difference of the two units | | `u_getUnicodeVersion(version)` | null | nothing | | | otherwise | writes 17, 0, 0, 0 | Where ICU's behaviour is undefined, the export does not invent a result: a null callback that ICU would call throws `std::invalid_argument` (ICU dereferences it), and the final difference wraps as two's-complement arithmetic instead of overflowing. `codePointOrder` is read as one byte, nonzero meaning true. In-tree lines that change: the two throwing placeholders in Export.cpp ([zGuhKwXM9I0](https://github.com/boykopovar/AnyPS5/blob/ed1e0ed08f/core/libs/prx/libSceIcu/Export.cpp#L249-L252), [TNZrG2iXikw](https://github.com/boykopovar/AnyPS5/blob/ed1e0ed08f/core/libs/prx/libSceIcu/Export.cpp#L419-L422)), the end of [Version.cpp](https://github.com/boykopovar/AnyPS5/blob/ed1e0ed08f/core/libs/prx/libSceIcu/Version.cpp#L67-L69), [libSceIcu.hpp](https://github.com/boykopovar/AnyPS5/blob/ed1e0ed08f/core/libs/prx/libSceIcu/libSceIcu.hpp#L2) and the [debt file](https://github.com/boykopovar/AnyPS5/blob/ed1e0ed08f/docs/dev/debt/libSceIcu.md#L21). ### What `u_strCompareIter` (TNZrG2iXikw) and `u_getUnicodeVersion` (zGuhKwXM9I0) no longer throw; they behave as the table above shows. `u_strCompareIter` drives caller-owned `UCharIterator`s only through their function pointers, called with the guest ABI, in ICU's order, so a caller's own iterator sees the same calls. The 112-byte `UCharIterator` layout and the `UCharIteratorOrigin` constants go in a new `Iterator.hpp`, with one function pointer type per callback as uiter.h declares them. Relation to open pull requests: - #11136 (string and UTF-8 iterators) does not implement either export. It also adds its own `core/libs/prx/libSceIcu/Iterator.hpp` declaring the same public ICU struct, and adds `u_getVersion` next to the same lines of Version.cpp and Version.hpp, as #11115 does. This branch's `Iterator.hpp` was written separately from uiter.h; the file name is the same on purpose, so the two conflict as files and can never both be built with two definitions of `UCharIterator`, and whichever merges second keeps one header. #11136's `uiter_setString`/`uiter_setUTF8` iterators can be compared with this export once both are in. - #13410 only renames the two placeholders to named stubs that still throw; whichever merges second drops them. - #12320 does not implement `u_strCompareIter`, and #11115 adds `u_getVersion` (not `u_getUnicodeVersion`) next to the same lines of Version.cpp and Version.hpp. A new debt entry records that neither export was compared with a console and the cases above where ICU is undefined. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Linux (GitHub codespace), current `main` with this branch applied: the new `guest_icu_compare_iter` passes, and the other six `guest_icu_*` tests still pass. The test drives the export through a guest-ABI iterator that records every callback, and checks: null and identical iterators (no calls), that iterators starting mid-text are reset, equal texts, empty texts, prefixes, code unit order, code point order with a supplementary character on either side, lone leads and trails, pairs that differ in the trail, units above 0xFFFF, a `codePointOrder` of 0x80, the exact callback sequence of each case, a null `move`, `next`, `current` or `previous` (throws only when ICU would call it), and wrapping at `INT32_MIN`/`INT32_MAX`. `u_getUnicodeVersion` writes 17, 0, 0, 0 and nothing past four bytes, and accepts null. - Negative control: with both bodies replaced by `NotImplemented_nid_no_patch`, the test fails with `u_strCompareIter_nid_postfix not implemented`; with only `u_getUnicodeVersion` reverted it fails with `u_getUnicodeVersion_nid_postfix not implemented`. - `python3 tools/check_conventions.py --base origin/main` passes. `tools/progress.py` against `main`: +2 implemented functions (`u_getUnicodeVersion`, `u_strCompareIter`); libSceIcu 25/124 to 27/124. - `tools/pr_overlap.py`: reports #11136 (same new file `Iterator.hpp`) and #13410 (renames the same placeholders), both explained above; the other ICU pull requests it could not compare were checked by hand and implement neither export. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-30 16:18:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T16:18:08Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The ICU implementation and focused test are internally consistent, but integration order for overlapping open ICU PRs has not been agreed or recorded.

What I ran

Reviewed head d1499225373ff23a47ec40f71fff70dcb0bd46e4 against PR base 9f748f4d8e36ce3714f3b95f3386316e110a9b22. A read-only merge preview onto current main 9304896d89f070f65b8f38bd3a8024d5c19f8fe1 was clean (tree 32a2c10ad0b45aa84831510d0817260601510a7e). Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0.

git diff --check 9f748f4d8e36ce3714f3b95f3386316e110a9b22...d1499225373ff23a47ec40f71fff70dcb0bd46e4
python3 tools/check_conventions.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head d1499225373ff23a47ec40f71fff70dcb0bd46e4
python3 tools/pr_abi_audit.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head d1499225373ff23a47ec40f71fff70dcb0bd46e4 --json > /tmp/anyps5-pr13457-abi.json
python3 - <<'PY'
import sys
sys.path.insert(0, 'tools')
import nid_names
for name in ('u_strCompareIter', 'u_getUnicodeVersion'):
    print(name, nid_names.compute_nid(name))
PY
python3 -c 'import json; d=json.load(open("/tmp/anyps5-pr13457-abi.json")); print("status:", d.get("status")); print("symbols:", len(d.get("symbols", []))); print("findings:", d.get("findings", []))'
python3 tools/pr_test_quality.py --root . core/libs/prx/libSceIcu/tests/CompareIter.cpp
git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/review/pr-13457
python3 tools/pr_precheck.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head refs/remotes/review/pr-13457 --no-negative-controls --output-dir /tmp/anyps5-pr13457-precheck

Results

Check Result
Diff check and conventions Passed
ABI audit Passed with two warnings for removed legacy stub names; replacement names compute to the same NIDs
Test-quality heuristic Warned that it could not find the test path literally; I verified registration in the PR-head CMake file through ${CMAKE_CURRENT_SOURCE_DIR}
Current-main merge preview Clean
Aggregate no-build precheck Its isolated copy lacked local-only, untracked audit scripts; I ran the relevant checks directly from the workspace
Unedited output from the direct checks
All conventions checks passed.
core/libs/prx/libSceIcu/tests/CompareIter.cpp:1: possible-unregistered-cpp-test: Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage.
Heuristic findings require manual interpretation.
status: passed_with_warnings
symbols: 105
findings: [{'symbol': 'sceIcuUnknown_TNZrG2iXikw_nid_no_patch', 'kind': 'export-removed', 'message': 'This APS5_VABI declaration, definition, or explicit alias appeared in the changed base files but not in the corresponding head files; verify that removing it is intentional.'}, {'symbol': 'sceIcuUnknown_zGuhKwXM9I0_nid_no_patch', 'kind': 'export-removed', 'message': 'This APS5_VABI declaration, definition, or explicit alias appeared in the changed base files but not in the corresponding head files; verify that removing it is intentional.'}]
All conventions checks passed.
u_strCompareIter TNZrG2iXikw
u_getUnicodeVersion zGuhKwXM9I0
git diff --check produced no output.
</details>

<details>
<summary>Aggregate precheck helper limitation</summary>

```text
/usr/bin/python3: can't open file '/tmp/anyps5-pr13457-precheck/head-d1499225373f-dc2c2885/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr13457-precheck/head-d1499225373f-dc2c2885/tools/pr_test_quality.py': [Errno 2] No such file or directory

Negative control

Not run locally: exercising the new C++ assertions requires building the exact PR head. The author reports a negative control in the PR description; I did not independently reproduce it.

Findings

Blocking

The new Iterator.hpp overlaps with #11136, which adds a different declaration of the same public UCharIterator type. The headers are not drop-in interchangeable: #11136 types the move origin as int32_t and omits UCharIteratorOrigin, while this PR uses an enum type; combining the PRs requires reconciling the callback assignments and callers. #13410 also changes the same two export entries that this PR replaces. The repository asks authors to agree on order for overlapping files/exports and record the required Depends on relationship. Please coordinate with those authors, settle the shared header/export order, and update the checklist accordingly.

Non-blocking

The implementation follows the cited ICU algorithm, but no console comparison is available; that limitation is recorded in the debt file.

Sources

Not verified

I did not build or run the C++ tests locally. Hosted checks were queued at the final refresh. I did not independently verify the PR author's reported Linux test, negative controls, or console behavior.

To get this to a good state

Please coordinate the shared-header and export landing order with #11136 and #13410, then update Depends on to reflect the agreement. I will rerun the same relevant checks on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5715243035 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13457#pullrequestreview-5715243035). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T16:18:08Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The ICU implementation and focused test are internally consistent, but integration order for overlapping open ICU PRs has not been agreed or recorded. ## What I ran Reviewed head `d1499225373ff23a47ec40f71fff70dcb0bd46e4` against PR base `9f748f4d8e36ce3714f3b95f3386316e110a9b22`. A read-only merge preview onto current `main` `9304896d89f070f65b8f38bd3a8024d5c19f8fe1` was clean (tree `32a2c10ad0b45aa84831510d0817260601510a7e`). Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. ```sh git diff --check 9f748f4d8e36ce3714f3b95f3386316e110a9b22...d1499225373ff23a47ec40f71fff70dcb0bd46e4 python3 tools/check_conventions.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head d1499225373ff23a47ec40f71fff70dcb0bd46e4 python3 tools/pr_abi_audit.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head d1499225373ff23a47ec40f71fff70dcb0bd46e4 --json > /tmp/anyps5-pr13457-abi.json python3 - <<'PY' import sys sys.path.insert(0, 'tools') import nid_names for name in ('u_strCompareIter', 'u_getUnicodeVersion'): print(name, nid_names.compute_nid(name)) PY python3 -c 'import json; d=json.load(open("/tmp/anyps5-pr13457-abi.json")); print("status:", d.get("status")); print("symbols:", len(d.get("symbols", []))); print("findings:", d.get("findings", []))' python3 tools/pr_test_quality.py --root . core/libs/prx/libSceIcu/tests/CompareIter.cpp git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/review/pr-13457 python3 tools/pr_precheck.py --base 9f748f4d8e36ce3714f3b95f3386316e110a9b22 --head refs/remotes/review/pr-13457 --no-negative-controls --output-dir /tmp/anyps5-pr13457-precheck ``` ## Results | Check | Result | | --- | --- | | Diff check and conventions | Passed | | ABI audit | Passed with two warnings for removed legacy stub names; replacement names compute to the same NIDs | | Test-quality heuristic | Warned that it could not find the test path literally; I verified registration in the PR-head CMake file through `${CMAKE_CURRENT_SOURCE_DIR}` | | Current-main merge preview | Clean | | Aggregate no-build precheck | Its isolated copy lacked local-only, untracked audit scripts; I ran the relevant checks directly from the workspace | <details> <summary>Unedited output from the direct checks</summary> ```text All conventions checks passed. core/libs/prx/libSceIcu/tests/CompareIter.cpp:1: possible-unregistered-cpp-test: Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage. Heuristic findings require manual interpretation. status: passed_with_warnings symbols: 105 findings: [{'symbol': 'sceIcuUnknown_TNZrG2iXikw_nid_no_patch', 'kind': 'export-removed', 'message': 'This APS5_VABI declaration, definition, or explicit alias appeared in the changed base files but not in the corresponding head files; verify that removing it is intentional.'}, {'symbol': 'sceIcuUnknown_zGuhKwXM9I0_nid_no_patch', 'kind': 'export-removed', 'message': 'This APS5_VABI declaration, definition, or explicit alias appeared in the changed base files but not in the corresponding head files; verify that removing it is intentional.'}] All conventions checks passed. u_strCompareIter TNZrG2iXikw u_getUnicodeVersion zGuhKwXM9I0 git diff --check produced no output. </details> <details> <summary>Aggregate precheck helper limitation</summary> ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr13457-precheck/head-d1499225373f-dc2c2885/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr13457-precheck/head-d1499225373f-dc2c2885/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` </details> ## Negative control Not run locally: exercising the new C++ assertions requires building the exact PR head. The author reports a negative control in the PR description; I did not independently reproduce it. ## Findings ### Blocking The new `Iterator.hpp` overlaps with #11136, which adds a different declaration of the same public `UCharIterator` type. The headers are not drop-in interchangeable: #11136 types the `move` origin as `int32_t` and omits `UCharIteratorOrigin`, while this PR uses an enum type; combining the PRs requires reconciling the callback assignments and callers. #13410 also changes the same two export entries that this PR replaces. The repository asks authors to agree on order for overlapping files/exports and record the required `Depends on` relationship. Please coordinate with those authors, settle the shared header/export order, and update the checklist accordingly. ### Non-blocking The implementation follows the cited ICU algorithm, but no console comparison is available; that limitation is recorded in the debt file. ## Sources - [ICU 78.1 `u_strCompareIter`, pinned to commit 049e0d6a4206](https://github.com/unicode-org/icu/blob/049e0d6a4206/icu4c/source/common/ustring.cpp#L828-L882) - [#11136 `Iterator.hpp` at head 53768b8910a0d540408c4ca9e362bb27599b5fae](https://github.com/boykopovar/AnyPS5/blob/53768b8910a0d540408c4ca9e362bb27599b5fae/core/libs/prx/libSceIcu/Iterator.hpp) - [#13457 `Iterator.hpp` at reviewed head](https://github.com/boykopovar/AnyPS5/blob/d1499225373ff23a47ec40f71fff70dcb0bd46e4/core/libs/prx/libSceIcu/Iterator.hpp) - [#13410 export changes at head c538dc458b454d2037d00e4da8566c319b326627](https://github.com/boykopovar/AnyPS5/blob/c538dc458b454d2037d00e4da8566c319b326627/core/libs/prx/libSceIcu/Export.cpp) - [Contribution rules at main commit 9304896d89f070f65b8f38bd3a8024d5c19f8fe1](https://github.com/boykopovar/AnyPS5/blob/9304896d89f070f65b8f38bd3a8024d5c19f8fe1/CONTRIBUTING.md) ## Not verified I did not build or run the C++ tests locally. Hosted checks were queued at the final refresh. I did not independently verify the PR author's reported Linux test, negative controls, or console behavior. ## To get this to a good state Please coordinate the shared-header and export landing order with #11136 and #13410, then update `Depends on` to reflect the agreement. I will rerun the same relevant checks on the new head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13457
No description provided.