feat(libSceIcu): implement u_terminateUChars and u_terminateWChars #22846

Merged
Callimann8 merged 1 commit from upstream-pr/22846 into main 2026-11-18 13:36:26 +00:00
Callimann8 commented 2026-11-18 12:28:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Callimann8 on 2026-11-18T12:28:45Z.


What

Implements u_terminateUChars and u_terminateWChars in libSceIcu. Both were stubs in LegacyExports.cpp; they now share the Terminate helper in TerminateBuffer.cpp that u_terminateChars and u_terminateUChar32s already use, following ICU 68.2's string termination contract (ustring.cpp):

  • A successful call writes a terminator when length < capacity and clears a pending U_STRING_NOT_TERMINATED_WARNING.
  • length == capacity reports U_STRING_NOT_TERMINATED_WARNING; length > capacity reports U_BUFFER_OVERFLOW_ERROR.
  • A failure status, a null status or a negative length leaves everything unchanged. The length is always returned.
  • u_terminateWChars writes a 2-byte terminator: the guest wchar_t is taken as 16 bits, as the libSceLibcInternal wide strings already do.
  • The debt fragment updates the ICU buffer termination entry. The "Older callable exports" entry still names only u_terminateChars and u_terminateUChar32s; it is left alone because the pending feat-icu-ulist fragment already changes it.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release). guest_icu_terminate_buffer now runs its full matrix (16 capacity/length cases × 8 initial statuses, null status, null destination, guard words around the status) for char16_t and the 16-bit wchar_t as well as char and int32_t. All 63 libSceIcu tests (ctest -R guest_icu) pass on this branch. tools/check_conventions.py --base origin/main and tools/debt_fold.py --check pass. Not tested on a console.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5375945395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22846). Originally posted by [Callimann8](https://github.com/Callimann8) on 2026-11-18T12:28:45Z. --- ### What Implements `u_terminateUChars` and `u_terminateWChars` in libSceIcu. Both were stubs in `LegacyExports.cpp`; they now share the `Terminate` helper in `TerminateBuffer.cpp` that `u_terminateChars` and `u_terminateUChar32s` already use, following ICU 68.2's string termination contract (`ustring.cpp`): - A successful call writes a terminator when `length < capacity` and clears a pending `U_STRING_NOT_TERMINATED_WARNING`. - `length == capacity` reports `U_STRING_NOT_TERMINATED_WARNING`; `length > capacity` reports `U_BUFFER_OVERFLOW_ERROR`. - A failure status, a null status or a negative length leaves everything unchanged. The length is always returned. - `u_terminateWChars` writes a 2-byte terminator: the guest `wchar_t` is taken as 16 bits, as the `libSceLibcInternal` wide strings already do. - The debt fragment updates the ICU buffer termination entry. The "Older callable exports" entry still names only `u_terminateChars` and `u_terminateUChar32s`; it is left alone because the pending `feat-icu-ulist` fragment already changes it. ### Tested Linux (Ubuntu 24.04, GCC 13.3, Release). `guest_icu_terminate_buffer` now runs its full matrix (16 capacity/length cases × 8 initial statuses, null status, null destination, guard words around the status) for `char16_t` and the 16-bit `wchar_t` as well as `char` and `int32_t`. All 63 libSceIcu tests (`ctest -R guest_icu`) pass on this branch. `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check` pass. Not tested on a console. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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-11-18 12:51:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T12:51:24Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review covers the new termination wrappers, their declarations and tests, and the debt note.

What I ran

Reviewed head 17034f619148adbf7b503fb167498844d0249ee3 against main. I did not run build or tests; the test results below are author-reported.

Results

Check Result Note
Code review passed New wrappers use the shared helper
Tests not run Author reports 63 libSceIcu tests passed
Console ABI not run Debt note records this limitation

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read the changed source and test additions in TerminateBuffer.cpp, TerminateBuffer.hpp, tests/TerminateBuffer.cpp, the relevant removal hunks in LegacyExports.cpp and include/LegacyExports.hpp, and the new debt fragment. I did not read the full 9,637-line LegacyExports.cpp or 2,256-line include/LegacyExports.hpp; neither has added lines. The 18 changed 3rdparty submodule pointers were excluded as unsupported files and their contents were not reviewed. I did not run tests, convention checks, or debt checks, and did not verify console ABI behavior.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956871994 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22846#pullrequestreview-5956871994). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T12:51:24Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review covers the new termination wrappers, their declarations and tests, and the debt note. ## What I ran Reviewed head `17034f619148adbf7b503fb167498844d0249ee3` against `main`. I did not run build or tests; the test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | New wrappers use the shared helper | | Tests | not run | Author reports 63 libSceIcu tests passed | | Console ABI | not run | Debt note records this limitation | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read the changed source and test additions in `TerminateBuffer.cpp`, `TerminateBuffer.hpp`, `tests/TerminateBuffer.cpp`, the relevant removal hunks in `LegacyExports.cpp` and `include/LegacyExports.hpp`, and the new debt fragment. I did not read the full 9,637-line `LegacyExports.cpp` or 2,256-line `include/LegacyExports.hpp`; neither has added lines. The 18 changed `3rdparty` submodule pointers were excluded as unsupported files and their contents were not reviewed. I did not run tests, convention checks, or debt checks, and did not verify console ABI behavior. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-18 12:58:09 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_terminate_buffer_tests built cleanly.
  • CTest (guest_icu_terminate_buffer):
    1/1 Test #3819: guest_icu_terminate_buffer .......   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/TerminateBuffer.cpp, core/libs/prx/libSceIcu/TerminateBuffer.hpp, 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/TerminateBuffer.cpp: Verified u_terminateUChars and u_terminateWChars forward correctly to the Terminate helper with matching parameter order and signatures.
    • core/libs/prx/libSceIcu/TerminateBuffer.cpp: Verified ICU termination contract error codes (U_BUFFER_OVERFLOW_ERROR = 15, U_STRING_NOT_TERMINATED_WARNING = -124, U_ZERO_ERROR = 0) and behavior when length < capacity, length == capacity, and length > capacity.
    • core/libs/prx/libSceIcu/TerminateBuffer.cpp: Verified null status pointer check (!status), pending error check (*status > 0), negative length check (length < 0), and null destination exception throwing.
    • core/libs/prx/libSceIcu/LegacyExports.cpp and include/LegacyExports.hpp: Confirmed removal of duplicate stubs and headers for u_terminateUChars_nid_postfix and u_terminateWChars_nid_postfix.
    • core/libs/prx/libSceIcu/tests/TerminateBuffer.cpp: Verified unit test templating exercises char16_t and uint16_t across length/capacity edge cases and statuses.
    • docs/dev/debt/changes/feat-icu-terminate-uchars-wchars.md: Verified AGENTS.md technical debt fragment conventions and documentation of wchar_t size and limitations.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956987790 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22846#pullrequestreview-5956987790). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T12:58:09Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `48c91bf619`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_icu_terminate_buffer_tests` built cleanly. - **CTest** (`guest_icu_terminate_buffer`): ``` 1/1 Test #3819: guest_icu_terminate_buffer ....... 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/TerminateBuffer.cpp`, `core/libs/prx/libSceIcu/TerminateBuffer.hpp`, `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/TerminateBuffer.cpp: Verified u_terminateUChars and u_terminateWChars forward correctly to the Terminate helper with matching parameter order and signatures. - core/libs/prx/libSceIcu/TerminateBuffer.cpp: Verified ICU termination contract error codes (U_BUFFER_OVERFLOW_ERROR = 15, U_STRING_NOT_TERMINATED_WARNING = -124, U_ZERO_ERROR = 0) and behavior when length < capacity, length == capacity, and length > capacity. - core/libs/prx/libSceIcu/TerminateBuffer.cpp: Verified null status pointer check (!status), pending error check (*status > 0), negative length check (length < 0), and null destination exception throwing. - core/libs/prx/libSceIcu/LegacyExports.cpp and include/LegacyExports.hpp: Confirmed removal of duplicate stubs and headers for u_terminateUChars_nid_postfix and u_terminateWChars_nid_postfix. - core/libs/prx/libSceIcu/tests/TerminateBuffer.cpp: Verified unit test templating exercises char16_t and uint16_t across length/capacity edge cases and statuses. - docs/dev/debt/changes/feat-icu-terminate-uchars-wchars.md: Verified AGENTS.md technical debt fragment conventions and documentation of wchar_t size and limitations. Looks Good To Me
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!22846
No description provided.