feat(libSceIcu): implement the code point set exports #11122

Merged
mantavisual merged 26 commits from upstream-pr/11122 into main 2026-11-04 04:49:02 +00:00
mantavisual commented 2026-10-25 18:46:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mantavisual on 2026-10-25T18:46:15Z.


What

Implements eight of the uset_ exports that firmware 13.42's libSceIcu has (BunnyFl's export list): uset_openEmpty, uset_close, uset_add, uset_addRange, uset_addAll, uset_contains, uset_getItemCount and uset_getItem. These build and query sets of code points and need no Unicode data. uset_openPattern, the ninth, needs property data and is not part of this PR.

Behaviour follows ICU 78.1's uset.cpp C wrappers and the UnicodeSet methods they call in uniset.cpp:

  • uset_add pins the code point to 0..10FFFF first (pinCodePoint), so −5 adds U+0000 and 0x200000 adds U+10FFFF.
  • uset_addRange pins both ends and adds the range when the pinned start is not above the pinned end. As in UnicodeSet::add(start, end), a range that lies entirely below 0 or above 10FFFF adds the single code point it pins to, and a reversed range adds nothing.
  • Ranges are kept as ICU's inversion list keeps them: sorted, with overlapping and adjacent ranges merged. So uset_getItemCount is the number of maximal runs, and uset_getItem returns each run's inclusive start and end.
  • uset_addAll is the union and leaves the added set unchanged; adding a set to itself changes nothing.
  • uset_contains is not pinned: anything outside 0..10FFFF is not a member.
  • uset_getItem follows the wrapper's order: an error that is already set returns 0 untouched; then a negative index sets U_ILLEGAL_ARGUMENT_ERROR and returns −1, before the set is read; then an index past the items sets U_INDEX_OUTOFBOUNDS_ERROR and returns −1. For a range item it returns 0 and does not touch the string buffer.

Sets hold no strings, because no export here can add one. ICU's string items come only from patterns and string adds. The debt entry records that, and that allocation failure throws where UnicodeSet would become bogus. ICU casts the handle without checking it. Here the handle is a host object with a magic value in its first four bytes, so null or foreign sets, and null range outputs or error pointers, throw APS5_INVALID_ARG_EX where ICU would dereference them. uset_close(nullptr) does nothing, as delete of null does in ICU.

Depends on #11118 (stacked on it). The agreed ICU order is #11013 → #10961 → … → #10967 → #11088 → #11115 → #11118, and this PR comes after #11118. Until those merge, the diff also shows their commits. This PR's own change is the last commit, 3d3b228b9f.

Tested

Windows 11 Pro 23H2, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on #11118 (c65ef82953).

  • New guest_icu_set:
    • The empty set, single code points merging into runs, and pinning of −5, 0x200000 and INT32_MIN/INT32_MAX range ends.
    • Reversed ranges, ranges entirely below 0 or above 10FFFF, overlapping, adjacent and gap-filling ranges, and the full 0..10FFFF set.
    • Union into another set, into itself and into an empty set.
    • Every uset_getItem branch, including a negative index on a null set.
    • The null and foreign handle rejections.
    • A seeded random sequence of 400 adds and range adds, compared against a 0x110000-entry bitmap: uset_contains for every code point and the item list against the bitmap's maximal runs.
  • ctest -R "guest_icu_|patched_libraries": all 6 pass. The NID-patched libSceIcu.prx builds.
  • tools/progress.py --module libSceIcu: 46 implemented, 0 stubs. tools/check_test_registration.py build: 1345 test executables, none built and not run.
  • python3 tools/check_conventions.py --base origin/main passes. Overlap: no open PR implements or names any uset_ function (checked 2026-10-25).

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: #11118
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007606249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11122). Originally posted by [mantavisual](https://github.com/mantavisual) on 2026-10-25T18:46:15Z. --- ### What Implements eight of the `uset_` exports that firmware 13.42's `libSceIcu` has ([BunnyFl's export list](https://github.com/boykopovar/AnyPS5/pull/11013#issuecomment-6401310351)): `uset_openEmpty`, `uset_close`, `uset_add`, `uset_addRange`, `uset_addAll`, `uset_contains`, `uset_getItemCount` and `uset_getItem`. These build and query sets of code points and need no Unicode data. `uset_openPattern`, the ninth, needs property data and is not part of this PR. Behaviour follows ICU 78.1's [uset.cpp](https://github.com/unicode-org/icu/blob/release-78.1/icu4c/source/common/uset.cpp) C wrappers and the `UnicodeSet` methods they call in [uniset.cpp](https://github.com/unicode-org/icu/blob/release-78.1/icu4c/source/common/uniset.cpp): - `uset_add` pins the code point to 0..10FFFF first (`pinCodePoint`), so −5 adds U+0000 and 0x200000 adds U+10FFFF. - `uset_addRange` pins both ends and adds the range when the pinned start is not above the pinned end. As in `UnicodeSet::add(start, end)`, a range that lies entirely below 0 or above 10FFFF adds the single code point it pins to, and a reversed range adds nothing. - Ranges are kept as ICU's inversion list keeps them: sorted, with overlapping and adjacent ranges merged. So `uset_getItemCount` is the number of maximal runs, and `uset_getItem` returns each run's inclusive start and end. - `uset_addAll` is the union and leaves the added set unchanged; adding a set to itself changes nothing. - `uset_contains` is not pinned: anything outside 0..10FFFF is not a member. - `uset_getItem` follows the wrapper's order: an error that is already set returns 0 untouched; then a negative index sets `U_ILLEGAL_ARGUMENT_ERROR` and returns −1, before the set is read; then an index past the items sets `U_INDEX_OUTOFBOUNDS_ERROR` and returns −1. For a range item it returns 0 and does not touch the string buffer. Sets hold no strings, because no export here can add one. ICU's string items come only from patterns and string adds. The debt entry records that, and that allocation failure throws where `UnicodeSet` would become bogus. ICU casts the handle without checking it. Here the handle is a host object with a magic value in its first four bytes, so null or foreign sets, and null range outputs or error pointers, throw `APS5_INVALID_ARG_EX` where ICU would dereference them. `uset_close(nullptr)` does nothing, as `delete` of null does in ICU. **Depends on #11118** (stacked on it). The [agreed ICU order](https://github.com/boykopovar/AnyPS5/pull/11088#issuecomment-6401396662) is #11013 → #10961 → … → #10967 → #11088 → #11115 → #11118, and this PR comes after #11118. Until those merge, the diff also shows their commits. This PR's own change is the last commit, `3d3b228b9f`. ### Tested Windows 11 Pro 23H2, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on #11118 (`c65ef82953`). - New `guest_icu_set`: - The empty set, single code points merging into runs, and pinning of −5, 0x200000 and `INT32_MIN`/`INT32_MAX` range ends. - Reversed ranges, ranges entirely below 0 or above 10FFFF, overlapping, adjacent and gap-filling ranges, and the full 0..10FFFF set. - Union into another set, into itself and into an empty set. - Every `uset_getItem` branch, including a negative index on a null set. - The null and foreign handle rejections. - A seeded random sequence of 400 adds and range adds, compared against a 0x110000-entry bitmap: `uset_contains` for every code point and the item list against the bitmap's maximal runs. - `ctest -R "guest_icu_|patched_libraries"`: all 6 pass. The NID-patched `libSceIcu.prx` builds. - `tools/progress.py --module libSceIcu`: 46 implemented, 0 stubs. `tools/check_test_registration.py build`: 1345 test executables, none built and not run. - `python3 tools/check_conventions.py --base origin/main` passes. Overlap: no open PR implements or names any `uset_` function (checked 2026-10-25). ### 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: #11118 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 18:49:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T18:49:23Z.

Review: CHANGES_REQUESTED


I compared this against the pinned ICU 78.1 UnicodeSet::add(start, end) in uniset.cpp and found a semantic mismatch in the range insertion path. ICU calls pinCodePoint on both endpoints and inserts only when pinCodePoint(start) < pinCodePoint(end) (the source is at uniset.cpp around line 765); uset_addRange forwards directly to that method in uset.cpp. This PR instead uses start <= end after pinning and inserts an equal-endpoint range. Consequently uset_addRange(set, 5, 5) should add nothing, and ranges wholly below 0 or wholly above U+10FFFF also pin to equal endpoints and should add nothing. The PR body and current tests claim those out-of-range intervals add a singleton, contrary to ICU. Please change the condition to strict < and update/add tests for equal endpoints and both wholly out-of-range intervals. Cross-boundary ranges whose pinned endpoints differ should still add normally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644715859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11122#pullrequestreview-5644715859). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:49:23Z. **Review:** CHANGES_REQUESTED --- I compared this against the pinned ICU 78.1 `UnicodeSet::add(start, end)` in `uniset.cpp` and found a semantic mismatch in the range insertion path. ICU calls `pinCodePoint` on both endpoints and inserts only when `pinCodePoint(start) < pinCodePoint(end)` (the source is at `uniset.cpp` around line 765); `uset_addRange` forwards directly to that method in `uset.cpp`. This PR instead uses `start <= end` after pinning and inserts an equal-endpoint range. Consequently `uset_addRange(set, 5, 5)` should add nothing, and ranges wholly below 0 or wholly above U+10FFFF also pin to equal endpoints and should add nothing. The PR body and current tests claim those out-of-range intervals add a singleton, contrary to ICU. Please change the condition to strict `<` and update/add tests for equal endpoints and both wholly out-of-range intervals. Cross-boundary ranges whose pinned endpoints differ should still add normally.
MarcZX10 commented 2026-10-25 18:56:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T18:56:40Z.

Review: CHANGES_REQUESTED


Reviewed the updated head 0bcb2ae1aa002a2534c77cb4cf84394e3cb12ba5. The new tests still encode the mismatch: they expect uset_addRange(0x41, 0x41) and fully out-of-range ranges to add singleton code points. In the pinned ICU 78.1 source, uset_addRange forwards to UnicodeSet::add(start, end), which inserts only when pinCodePoint(start) < pinCodePoint(end) (uniset.cpp:765-767). The implementation on this head still uses start <= end, so the behavior and new expectations remain inconsistent with the cited source. I compiled and ran Set.cpp with GuestIcuSet.cpp on GCC 12.2; it passes because the test currently asserts the implementation’s behavior, which does not validate ICU equivalence. Please use strict <, change the equal/out-of-range expectations to empty, and add the corrected cases.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644750544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11122#pullrequestreview-5644750544). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:56:40Z. **Review:** CHANGES_REQUESTED --- Reviewed the updated head `0bcb2ae1aa002a2534c77cb4cf84394e3cb12ba5`. The new tests still encode the mismatch: they expect `uset_addRange(0x41, 0x41)` and fully out-of-range ranges to add singleton code points. In the pinned ICU 78.1 source, `uset_addRange` forwards to `UnicodeSet::add(start, end)`, which inserts only when `pinCodePoint(start) < pinCodePoint(end)` (`uniset.cpp:765-767`). The implementation on this head still uses `start <= end`, so the behavior and new expectations remain inconsistent with the cited source. I compiled and ran `Set.cpp` with `GuestIcuSet.cpp` on GCC 12.2; it passes because the test currently asserts the implementation’s behavior, which does not validate ICU equivalence. Please use strict `<`, change the equal/out-of-range expectations to empty, and add the corrected cases.
MarcZX10 commented 2026-10-25 19:00:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:00:57Z.

Review: APPROVED


Correction to my two earlier reviews: I missed the else if (start == end) { add(start); } branch in pinned ICU 78.1 UnicodeSet::add(start, end) (uniset.cpp:801-802). Since pinCodePoint mutates both references before that check, equal endpoints after clamping correctly add one code point. The implementation and added tests on 0bcb2ae1aa match this behavior; my earlier claim that equality and wholly out-of-range intervals should add nothing was wrong. I rechecked the forwarding wrapper in uset.cpp; it delegates directly to this method. The focused guest_icu_set test and ctest -R "guest_icu_|patched_libraries" results reported in the PR are consistent with the source.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644764378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11122#pullrequestreview-5644764378). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:00:57Z. **Review:** APPROVED --- Correction to my two earlier reviews: I missed the `else if (start == end) { add(start); }` branch in pinned ICU 78.1 `UnicodeSet::add(start, end)` (`uniset.cpp:801-802`). Since `pinCodePoint` mutates both references before that check, equal endpoints after clamping correctly add one code point. The implementation and added tests on `0bcb2ae1aa` match this behavior; my earlier claim that equality and wholly out-of-range intervals should add nothing was wrong. I rechecked the forwarding wrapper in `uset.cpp`; it delegates directly to this method. The focused `guest_icu_set` test and `ctest -R "guest_icu_|patched_libraries"` results reported in the PR are consistent with the source.
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!11122
No description provided.