feat(libSceIcu): implement the constrained field position exports #11118

Merged
mantavisual merged 18 commits from upstream-pr/11118 into main 2026-11-02 19:45:23 +00:00
mantavisual commented 2026-10-25 18:38:51 +00:00 (Migrated from github.com)

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


What

Implements the seven ucfpos_ exports that firmware 13.42's libSceIcu has (BunnyFl's export list): ucfpos_open, ucfpos_close, ucfpos_constrainCategory, ucfpos_constrainField, ucfpos_getCategory, ucfpos_getField and ucfpos_getIndexes. UConstrainedFieldPosition is the state object callers pass to ufmtval_nextPosition to walk the fields of formatted output. It holds a constraint, category, field and start/limit indexes, and needs no Unicode data.

Behaviour follows ICU 78.1's formattedvalue.cpp and the handle check in capi_helper.h:

  • ucfpos_open returns a new position with category UFIELD_CATEGORY_UNDEFINED (0), field 0 and indexes 0/0. Like ICU, it neither checks nor sets the error code unless allocation fails, so an incoming error and a null error pointer are accepted.

  • Every other function validates the handle as IcuCApiHelper::validate does:

    • an error that is already set makes the call do nothing;
    • a null handle sets U_ILLEGAL_ARGUMENT_ERROR;
    • memory whose first four bytes are not the magic 0x55434600 ("UCF") sets U_INVALID_FORMAT_ERROR.

    Failing getters return 0 and leave the index outputs untouched.

  • ucfpos_constrainCategory sets the category constraint and keeps the field. ucfpos_constrainField sets the field constraint, category and field.

  • ucfpos_close validates with its own status, clears the magic and frees the object, so null and foreign pointers are ignored.

The handle is a host object that starts with the magic; the rest of its layout differs from ICU's, which callers can't see. A null error pointer, or a null ucfpos_getIndexes output on a valid handle, throws APS5_INVALID_ARG_EX, since ICU dereferences them. No exported formatter fills a position yet, so ucfpos_getIndexes reports 0/0. The constraint is stored for a later ufmtval_nextPosition. The new debt entry records all of this.

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

Tested

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

  • New guest_icu_constrained_field_position:
    • Defaults, ucfpos_open with an incoming error and with a null error pointer.
    • Both constraints, including that a category constraint keeps the field.
    • That a set error changes nothing and leaves index outputs untouched.
    • Null handles (U_ILLEGAL_ARGUMENT_ERROR) and a zeroed foreign buffer (U_INVALID_FORMAT_ERROR).
    • ucfpos_close of null and foreign pointers.
    • The null error-pointer and null index-output rejections.
  • ctest -R "guest_icu_|patched_libraries": all 5 pass. The NID-patched libSceIcu.prx builds.
  • tools/progress.py --module libSceIcu: 38 implemented, 0 stubs. tools/check_test_registration.py build: 1344 test executables, none built and not run.
  • python3 tools/check_conventions.py --base origin/main passes. Overlap: no open PR implements or names any ucfpos_ 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: #11115
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007552317 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11118). Originally posted by [mantavisual](https://github.com/mantavisual) on 2026-10-25T18:38:51Z. --- ### What Implements the seven `ucfpos_` exports that firmware 13.42's `libSceIcu` has ([BunnyFl's export list](https://github.com/boykopovar/AnyPS5/pull/11013#issuecomment-6401310351)): `ucfpos_open`, `ucfpos_close`, `ucfpos_constrainCategory`, `ucfpos_constrainField`, `ucfpos_getCategory`, `ucfpos_getField` and `ucfpos_getIndexes`. `UConstrainedFieldPosition` is the state object callers pass to `ufmtval_nextPosition` to walk the fields of formatted output. It holds a constraint, category, field and start/limit indexes, and needs no Unicode data. Behaviour follows ICU 78.1's [formattedvalue.cpp](https://github.com/unicode-org/icu/blob/release-78.1/icu4c/source/i18n/formattedvalue.cpp) and the handle check in [capi_helper.h](https://github.com/unicode-org/icu/blob/release-78.1/icu4c/source/common/capi_helper.h): - `ucfpos_open` returns a new position with category `UFIELD_CATEGORY_UNDEFINED` (0), field 0 and indexes 0/0. Like ICU, it neither checks nor sets the error code unless allocation fails, so an incoming error and a null error pointer are accepted. - Every other function validates the handle as `IcuCApiHelper::validate` does: - an error that is already set makes the call do nothing; - a null handle sets `U_ILLEGAL_ARGUMENT_ERROR`; - memory whose first four bytes are not the magic `0x55434600` ("UCF") sets `U_INVALID_FORMAT_ERROR`. Failing getters return 0 and leave the index outputs untouched. - `ucfpos_constrainCategory` sets the category constraint and keeps the field. `ucfpos_constrainField` sets the field constraint, category and field. - `ucfpos_close` validates with its own status, clears the magic and frees the object, so null and foreign pointers are ignored. The handle is a host object that starts with the magic; the rest of its layout differs from ICU's, which callers can't see. A null error pointer, or a null `ucfpos_getIndexes` output on a valid handle, throws `APS5_INVALID_ARG_EX`, since ICU dereferences them. No exported formatter fills a position yet, so `ucfpos_getIndexes` reports 0/0. The constraint is stored for a later `ufmtval_nextPosition`. The new debt entry records all of this. **Depends on #11115** (stacked on it). The [agreed ICU order](https://github.com/boykopovar/AnyPS5/pull/11088#issuecomment-6401396662) is #11013 → #10961 → … → #10967 → #11088 → #11115, and this PR comes after #11115. Until those merge, the diff also shows their commits. This PR's own change is the last commit, `c65ef82953`. ### Tested Windows 11 Pro 23H2, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on #11115 (`eb607ba588`). - New `guest_icu_constrained_field_position`: - Defaults, `ucfpos_open` with an incoming error and with a null error pointer. - Both constraints, including that a category constraint keeps the field. - That a set error changes nothing and leaves index outputs untouched. - Null handles (`U_ILLEGAL_ARGUMENT_ERROR`) and a zeroed foreign buffer (`U_INVALID_FORMAT_ERROR`). - `ucfpos_close` of null and foreign pointers. - The null error-pointer and null index-output rejections. - `ctest -R "guest_icu_|patched_libraries"`: all 5 pass. The NID-patched `libSceIcu.prx` builds. - `tools/progress.py --module libSceIcu`: 38 implemented, 0 stubs. `tools/check_test_registration.py build`: 1344 test executables, none built and not run. - `python3 tools/check_conventions.py --base origin/main` passes. Overlap: no open PR implements or names any `ucfpos_` 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: #11115 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 18:42:13 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed exact head c65ef82953 against ICU 78.1 formattedvalue.cpp and capi_helper.h. The magic value, success/error short-circuiting, null/foreign handle status, default state, category/field constraints, and getter fallbacks match those references. The small differences documented for null error/index pointers are explicit and follow the repository’s throw-on-unknown/error rule. I independently built and ran GuestIcuConstrainedFieldPosition with GCC 12.2; it passed. The PR reports five focused ICU tests passing, and hosted conventions/intake checks are green; product build/test jobs are skipped. Its dependency on #11115 is declared.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644693095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11118#pullrequestreview-5644693095). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:42:13Z. **Review:** APPROVED --- Reviewed exact head c65ef82953f8b7a705586eafde6761f5bcd5bfe0 against ICU 78.1 `formattedvalue.cpp` and `capi_helper.h`. The magic value, success/error short-circuiting, null/foreign handle status, default state, category/field constraints, and getter fallbacks match those references. The small differences documented for null error/index pointers are explicit and follow the repository’s throw-on-unknown/error rule. I independently built and ran `GuestIcuConstrainedFieldPosition` with GCC 12.2; it passed. The PR reports five focused ICU tests passing, and hosted conventions/intake checks are green; product build/test jobs are skipped. Its dependency on #11115 is declared.
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!11118
No description provided.