feat(libSceIcu): implement uprv_isInvariantString and uprv_isInvariantUString #19998

Closed
MarcZX10 wants to merge 9 commits from upstream-pr/19998 into main
MarcZX10 commented 2026-11-14 10:44:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T10:44:31Z.


What

Two libSceIcu exports are still stubs that throw NotImplemented_nid_no_patch: uprv_isInvariantString and uprv_isInvariantUString. Their ICU 68 names are already used for their NIDs in LegacyExports.cpp.

This PR implements them in a new file, core/libs/prx/libSceIcu/InvariantChars.cpp, following ICU 68.2's common/uinvchar.cpp:
github.com/unicode-org/icu@84e1f26ea7/icu4c/source/common/uinvchar.cpp

Each function is one commit (the first also adds the shared table and the CMake source), then one test commit per behaviour: the invariant set against the ranges that ICU documents, byte-string length and NUL semantics, and UTF-16 length and NUL semantics. The last commit updates docs/dev/debt/libSceIcu.md.

Licence and comments (open)

The file header carries ICU's notice, verbatim, as in the other libSceIcu ICU-derived PRs. This is the same open question as #19951, #19955, #19972 and #19985: AGENTS.md forbids comments in code, while the Unicode licence asks for its notice to stay with copies. This PR does not decide that; it follows the convention already agreed on those PRs, and a maintainer decision applies to all of them.

Tested

  • Environment: Linux x86-64 (Debian 12, GCC 12.2), throwaway archive build of the branch head.
  • ctest -R '^guest_icu': 44 of 44 tests pass, including the new guest_icu_invariant_chars.
  • The set test checks all 256 single bytes against the ranges that ICU's comment documents, not against the table itself.
  • Negative control: not run. On the base the two functions are stubs that throw, so the new tests are expected to abort on base; that expectation has not been checked.
  • tools/check_conventions.py --base upstream/main: passed. git diff --check: empty.

Not run: the console, Windows, macOS. The ASCII charset family is assumed; the debt doc says so.

Overlap

  • No open PR names these functions in its title, body or diff.
  • tools/pr_overlap.py is expected to fail closed on the shared libSceIcu files, as for the other PRs in this series.

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 (licence header open; see above)
  • 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:5310392383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19998). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T10:44:31Z. --- ### What Two libSceIcu exports are still stubs that throw `NotImplemented_nid_no_patch`: `uprv_isInvariantString` and `uprv_isInvariantUString`. Their ICU 68 names are already used for their NIDs in `LegacyExports.cpp`. This PR implements them in a new file, `core/libs/prx/libSceIcu/InvariantChars.cpp`, following ICU 68.2's `common/uinvchar.cpp`: https://github.com/unicode-org/icu/blob/84e1f26ea77152936e70d53178a816dbfbf69989/icu4c/source/common/uinvchar.cpp Each function is one commit (the first also adds the shared table and the CMake source), then one test commit per behaviour: the invariant set against the ranges that ICU documents, byte-string length and NUL semantics, and UTF-16 length and NUL semantics. The last commit updates `docs/dev/debt/libSceIcu.md`. ### Licence and comments (open) The file header carries ICU's notice, verbatim, as in the other libSceIcu ICU-derived PRs. This is the same open question as #19951, #19955, #19972 and #19985: AGENTS.md forbids comments in code, while the Unicode licence asks for its notice to stay with copies. This PR does not decide that; it follows the convention already agreed on those PRs, and a maintainer decision applies to all of them. ### Tested - Environment: Linux x86-64 (Debian 12, GCC 12.2), throwaway archive build of the branch head. - `ctest -R '^guest_icu'`: 44 of 44 tests pass, including the new `guest_icu_invariant_chars`. - The set test checks all 256 single bytes against the ranges that ICU's comment documents, not against the table itself. - Negative control: not run. On the base the two functions are stubs that throw, so the new tests are expected to abort on base; that expectation has not been checked. - `tools/check_conventions.py --base upstream/main`: passed. `git diff --check`: empty. Not run: the console, Windows, macOS. The ASCII charset family is assumed; the debt doc says so. ### Overlap - No open PR names these functions in its title, body or diff. - `tools/pr_overlap.py` is expected to fail closed on the shared libSceIcu files, as for the other PRs in this series. ### Checklist - [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 - [ ] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above) - [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
PrivacyOnion commented 2026-11-14 10:51:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T10:51:28Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c4e428c3ba:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above)
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_icu_invariant_chars_tests built cleanly.
  • CTest (guest_icu_invariant_chars):
    1/1 Test #3424: guest_icu_invariant_chars ........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LegacyExports.cpp, core/libs/prx/libSceIcu/include/LegacyExports.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified uprv_isInvariantString_nid_postfix in core/libs/prx/libSceIcu/InvariantChars.cpp handles both NUL-terminated strings (length < 0 stopping at \0) and length-counted buffers (length >= 0 stopping when length reaches 0) without buffer overrun, safely casting char to std::uint8_t.
    • Verified uprv_isInvariantUString_nid_postfix in core/libs/prx/libSceIcu/InvariantChars.cpp processes char16_t code units correctly, ensuring NUL termination, counted bounds, and immediate rejection of any code units > 0x7F (including high/low surrogates) via IsInvariant.
    • Verified the 4-word invariant character bitmask table InvariantChars in core/libs/prx/libSceIcu/InvariantChars.cpp (0xfffffbffu, 0xffffffe5u, 0x87fffffeu, 0x87fffffeu) against ICU 68.2: c <= 0x7f bounds guard prevents out-of-bounds index on InvariantChars[c >> 5], and shift 1u << (c & 0x1f) correctly identifies variant characters including LF (0x0A), '!', '#', '$', '@', '[', '\', ']', '^', '`', '{', '|', '}', '~'.
    • Verified export declarations and ABI signatures in core/libs/prx/libSceIcu/include/LegacyExports.hpp and InvariantChars.cpp: signatures match std::int8_t return type (ICU UBool) under APS5_VABI and extern "C", and obsolete NotImplemented stubs were cleanly removed from LegacyExports.cpp.
    • Verified test coverage in core/libs/tests/GuestIcuInvariantChars.cpp and CMake registration in core/libs/prx/libSceIcu/CMakeLists.txt: all 256 single byte values are checked against expected invariant ranges, multi-byte length and NUL semantics are tested, and Windows environment configuration is properly set.
    • Verified technical debt tracking in docs/dev/debt/libSceIcu.md: updated functional inventory and documented assumptions regarding ASCII charset family invariance following upstream ICU 68.2.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903937734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19998#pullrequestreview-5903937734). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T10:51:28Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c4e428c3ba`: - **Conventions**: `tools/check_conventions.py` failed; `git diff --check` clean. ``` (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above) 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_icu_invariant_chars_tests` built cleanly. - **CTest** (`guest_icu_invariant_chars`): ``` 1/1 Test #3424: guest_icu_invariant_chars ........ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/LegacyExports.cpp`, `core/libs/prx/libSceIcu/include/LegacyExports.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified uprv_isInvariantString_nid_postfix in core/libs/prx/libSceIcu/InvariantChars.cpp handles both NUL-terminated strings (length < 0 stopping at \0) and length-counted buffers (length >= 0 stopping when length reaches 0) without buffer overrun, safely casting char to std::uint8_t. - Verified uprv_isInvariantUString_nid_postfix in core/libs/prx/libSceIcu/InvariantChars.cpp processes char16_t code units correctly, ensuring NUL termination, counted bounds, and immediate rejection of any code units > 0x7F (including high/low surrogates) via IsInvariant. - Verified the 4-word invariant character bitmask table InvariantChars in core/libs/prx/libSceIcu/InvariantChars.cpp (0xfffffbffu, 0xffffffe5u, 0x87fffffeu, 0x87fffffeu) against ICU 68.2: c <= 0x7f bounds guard prevents out-of-bounds index on InvariantChars[c >> 5], and shift 1u << (c & 0x1f) correctly identifies variant characters including LF (0x0A), '!', '#', '$', '@', '[', '\\', ']', '^', '`', '{', '|', '}', '~'. - Verified export declarations and ABI signatures in core/libs/prx/libSceIcu/include/LegacyExports.hpp and InvariantChars.cpp: signatures match std::int8_t return type (ICU UBool) under APS5_VABI and extern "C", and obsolete NotImplemented stubs were cleanly removed from LegacyExports.cpp. - Verified test coverage in core/libs/tests/GuestIcuInvariantChars.cpp and CMake registration in core/libs/prx/libSceIcu/CMakeLists.txt: all 256 single byte values are checked against expected invariant ranges, multi-byte length and NUL semantics are tested, and Windows environment configuration is properly set. - Verified technical debt tracking in docs/dev/debt/libSceIcu.md: updated functional inventory and documented assumptions regarding ASCII charset family invariance following upstream ICU 68.2. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 00:20:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T00:20:28Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d10d2a4ea5:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above)
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: CMakeLists.txt failed to build.
          HTTP/3(EXPERIMENTAL): OFF
    
    CMake Error at core/libs/prx/libSceIcu/CMakeLists.txt:612:
      Parse error.  Function missing ending ")".  End of file reached.
    
    
    CMake Error at core/libs/CMakeLists.txt:189 (target_link_libraries):
      Cannot specify link libraries for target "libSceIcu" which is not built by
      this project.
    
    
    -- Configuring incomplete, errors occurred!
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5908087033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19998#pullrequestreview-5908087033). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T00:20:28Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d10d2a4ea5`: - **Conventions**: `tools/check_conventions.py` failed; `git diff --check` clean. ``` (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above) 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `CMakeLists.txt` failed to build. ``` HTTP/3(EXPERIMENTAL): OFF CMake Error at core/libs/prx/libSceIcu/CMakeLists.txt:612: Parse error. Function missing ending ")". End of file reached. CMake Error at core/libs/CMakeLists.txt:189 (target_link_libraries): Cannot specify link libraries for target "libSceIcu" which is not built by this project. -- Configuring incomplete, errors occurred! ``` - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 00:44:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T00:44:01Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against f42308ff7a:

  • Conventions: tools/check_conventions.py failed; git diff --check clean.
    (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above)
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_icu_invariant_chars_tests built cleanly.
  • CTest (guest_icu_invariant_chars):
    1/1 Test #3473: guest_icu_invariant_chars ........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LegacyExports.cpp, core/libs/prx/libSceIcu/include/LegacyExports.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceIcu/InvariantChars.cpp: verified IsInvariant guarantees c <= 0x7f before indexing InvariantChars[4], avoiding out-of-bounds array accesses and bit-shift amounts >= 32 for any input code unit or byte.
    • core/libs/prx/libSceIcu/InvariantChars.cpp: verified uprv_isInvariantString_nid_postfix and uprv_isInvariantUString_nid_postfix correctly implement both length < 0 (NUL-terminated) and length >= 0 (explicit length) semantics, preserving ICU 68.2's distinction where byte strings skip embedded NUL in length mode and UTF-16 strings treat NUL as invariant.
    • core/libs/prx/libSceIcu/InvariantChars.cpp: verified sign safety by static_caststd::uint8_t(*s++) on signed char platforms, ensuring bytes above 127 evaluate as variant without undefined behavior or negative indexing.
    • core/libs/prx/libSceIcu/LegacyExports.cpp and LegacyExports.hpp: verified clean removal of NotImplemented_nid_no_patch stubs and exact signature alignment with UBool (std::int8_t) and APS5_VABI.
    • core/libs/tests/GuestIcuInvariantChars.cpp: verified test logic exercises all 256 byte values, zero-length strings, embedded NUL boundary checks for both byte and UTF-16 strings, and non-ASCII/variant inputs without side effects or unexercised branches.
    • AGENTS.md compliance: verified that InvariantChars.cpp contains only the verbatim upstream ICU license header with a pinned commit link, no prohibited comments in implementation or test code, and technical debt documentation correctly updated in docs/dev/debt/libSceIcu.md.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5908227535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19998#pullrequestreview-5908227535). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T00:44:01Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `f42308ff7a`: - **Conventions**: `tools/check_conventions.py` failed; `git diff --check` clean. ``` (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above) 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_icu_invariant_chars_tests` built cleanly. - **CTest** (`guest_icu_invariant_chars`): ``` 1/1 Test #3473: guest_icu_invariant_chars ........ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceIcu/LegacyExports.cpp`, `core/libs/prx/libSceIcu/include/LegacyExports.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceIcu/InvariantChars.cpp: verified IsInvariant guarantees c <= 0x7f before indexing InvariantChars[4], avoiding out-of-bounds array accesses and bit-shift amounts >= 32 for any input code unit or byte. - core/libs/prx/libSceIcu/InvariantChars.cpp: verified uprv_isInvariantString_nid_postfix and uprv_isInvariantUString_nid_postfix correctly implement both length < 0 (NUL-terminated) and length >= 0 (explicit length) semantics, preserving ICU 68.2's distinction where byte strings skip embedded NUL in length mode and UTF-16 strings treat NUL as invariant. - core/libs/prx/libSceIcu/InvariantChars.cpp: verified sign safety by static_cast<std::uint8_t>(*s++) on signed char platforms, ensuring bytes above 127 evaluate as variant without undefined behavior or negative indexing. - core/libs/prx/libSceIcu/LegacyExports.cpp and LegacyExports.hpp: verified clean removal of NotImplemented_nid_no_patch stubs and exact signature alignment with UBool (std::int8_t) and APS5_VABI. - core/libs/tests/GuestIcuInvariantChars.cpp: verified test logic exercises all 256 byte values, zero-length strings, embedded NUL boundary checks for both byte and UTF-16 strings, and non-ASCII/variant inputs without side effects or unexercised branches. - AGENTS.md compliance: verified that InvariantChars.cpp contains only the verbatim upstream ICU license header with a pinned commit link, no prohibited comments in implementation or test code, and technical debt documentation correctly updated in docs/dev/debt/libSceIcu.md. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-18 12:42:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T12:42:23Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 67cd3aaf9e:

  • Conventions: tools/check_conventions.py failed.
    (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above)
    1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_icu_invariant_chars_tests built cleanly.
  • CTest (guest_icu_invariant_chars):
    1/1 Test #3870: guest_icu_invariant_chars ........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956729924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19998#pullrequestreview-5956729924). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T12:42:23Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `67cd3aaf9e`: - **Conventions**: `tools/check_conventions.py` failed. ``` (pull request): error: [pr-template] Fill in the pull request template: unchecked: No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) (licence header open; see above) 1 findings, 1 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_icu_invariant_chars_tests` built cleanly. - **CTest** (`guest_icu_invariant_chars`): ``` 1/1 Test #3870: guest_icu_invariant_chars ........ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` Requesting changes for the points above.

Pull request closed

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!19998
No description provided.