feat(icu): format numbers with field position iterators #26173
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26173"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by IvanFogel on 2026-11-23T11:30:38Z.
What
Implement the existing
unum_formatDoubleForFieldsexport. Titles can format a number as a localized string and iterate the sign, integer, fraction, grouping, decimal separator, percent and currency spans in UTF-16 code units. A formatting preflight or short output still populates the field iterator. Reusing an iterator replaces its old fields and restarts traversal.The existing formatter and iterator registries validate guest handles and synchronize formatting with close and iteration. Formatting and offsets are staged with bundled ICU 78.1 before publishing field ranges to the guest iterator. Each changed output span, including status, is held open with the guest arena’s host-write scope before testing its temporary host protection. All spans are validated before the first guest result write. Rejected guest writes retain the previous iterator. C++ staging allocation failures return zero and ICU’s allocation error. When one of the three ICU formatting probes itself reports an allocation error, the guest immediately receives that failing call’s native return length and error, with its output and field iterator untouched. The replacement field list is prepared in a separate native ICU iterator before writing guest text or status. After the checked writes succeed, the registry switches the existing guest handle to the prepared native iterator. A failed replacement returns zero and the ICU memory-allocation error. Both the text and the position in the previous field list survive. The C entry points in ICU 68.2 and ICU 78.1 share the same argument checks, formatter call and result extraction. Console field data and allocator failure behavior remain unverified.
Draft. #19720 supplies the live guest classic number formatter handles, locale data and existing checked string output. Its opening prerequisite at
73c0847d0fd5907bfd52f165c7ca2554b5b31053expressly deferred this export. Both that head and mainfe540db950a61dfb5f5ddfc3c940a7c4738783b6are included. The additional feature commit isba3bf4476c908804b796b6b59b56f1f04a127822. Lystea11’s date formatter PR #24402 also needs to reserve a guest field iterator while formatting. Its six-line lock helper, declarations and iterator consumer are included here from head44b621151ff3f0bc07e02766e269478a81c6ca44and credited in the feature commit. This revision extends the shared helper so a locked native formatter sees the current field list for the original guest handle. The requested order is still #24402 first. On integration, retain the lookup of that current native iterator. The full branch merge still conflicts in ICU CMake registration, recovered signatures, the standard-name test and inherited build/debt files. #19720 is the runtime formatter prerequisite. No date formatting code or data-provider change is needed for this feature. The repository name scan checked 2,538 open PRs and found no open implementation change for this export. The opening exact-branch scan fetched 2,551 open PRs and reported 43 peers, including 35 whose overlapping paths the tool could not compare. All reported heads were separately pinned and their shared paths and formatter bodies inspected. No other implementation of this guest export was found. Other inherited ICU/test/debt changes need integration with adjacent branches. The date-formatter interoperation run below uses its formatter translation unit. At main63b98e5bf852, the shared ICU enumeration and right-to-left test still conflict. The coordinated ICU rebase is waiting on #16971.Tested
December 4, commit
1760f6a79809. The previous commit published new text when ICU refused the backing storage for the final field list. The regression failed for that reason on Linux and MinGW-w64/Wine. It now separately refuses the field vector and its backing buffer at capacities 0, 1, 2 and 8. In all eight cases it checks the error, zero return, every UTF-16 unit and the previous iterator’s partially consumed position. A second check denies guest output both during validation and during the final copy. The full ICU/public-header selection passed 128/128 on Linux and 128/128 on MinGW-w64/Wine with zero skips.I also compiled the unmodified date formatter translation unit from #24402 (
b2188fa8af62) against this revision. A single guest iterator alternated between signed-number and date formatting three times, returning the expected year, month and day spans and then the original numeric sign and integer spans. The probe passed on Linux and MinGW-w64/Wine. All Windows-format executions in this update used Wine.November 25, commit
d3104fca9730. I integrated main9c0d60cbfb6e. The branch now includes the revised number formatter prerequisite from #19720. It preserves main’s prefailed numbering-system guards and ICU data sources alongside the owned formatter and field-iterator implementation. The data-backed fixture now tests inferred regions against bundled likely-subtag data. Its fallback case uses the unassigned locale de_QM, so the expected parent-locale warning is tested even with the full ICU data installed. On this commit, 128 Linux and 128 MinGW-w64/Wine CTests passed, covering every registered guest ICU test and the public-header check.Arch Linux x86-64, GCC 16.2.1, and Win64 MinGW GCC 16.2.0 under Wine 11.22 on Linux. No native Windows, macOS, console or retail title run.
87000974315d3486af82478bca99baa1c74bd27epassed 121/121 ICU and public-header CTests on Linux and 121/121 on MinGW/Wine, with zero skips or failures. Maximum test times were 7.693s and 4.879s respectively. Both profiles independently compiled every listed ICU public header and the additional changed private headers (56 standalone units per profile).git diff --checkpassed. The earlier pending fragments are reconciled in place because the fold tool rejects a second fragment targeting an entry added or changed by another pending fragment.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:29:23Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
87000974315d3486af82478bca99baa1c74bd27e. I read the prepared description, commits, manifest, and diff, then inspected the changed number-format implementation, its backend, and the field-iterator locking path throughrepo_read.py. No tests were run; reported test results below are author-supplied.Results
Findings
Blocking
None.
Non-blocking
Not verified
I did not inspect every changed file in the 4,993-line manifest or the full inherited ICU build, feature, and test changes. The manifest reports changed files as included, but the prepared review folder does not expose its individual files through the reader listing. I reviewed the formatter-focused diff and selected source ranges. I did not run tests or verify console behavior. The reported Linux and MinGW/Wine results are from the PR description, not runs performed in this review.
To get this to a good state
Nothing is required. The console comparison and reported test coverage remain useful follow-up evidence.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:39:02Z.
Review: COMMENTED
Reviewed — comments
The change adds ICU number formatting with field iteration and broad ICU integration updates; the feature code was inspected, but the full changed-file set was not reviewed, so a formal approval is not justified.
What I ran
Reviewed head
d3104fca97309cc8e0da2dbf9a5a2f0de77559aa. No commands or tests were run. The author reports Linux and MinGW/Wine CTest runs in the PR description; those results were not independently verified.Read
review/description.md,review/commits.md,review/manifest.json, and the first 300 lines ofreview/diff.patch. At repository head, readcore/libs/prx/libSceIcu/NumberFormat.cpp,core/libs/prx/libSceIcu/NumberFormatBackend.cpp, andcore/libs/prx/libSceIcu/FieldPositionIterator.cpp.list_filesreported all changed files included; no files were listed as excluded. The remaining changed files were not read.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
Most changed files were not read, including ICU data/build integration, date formatting, numbering systems, and their tests. The remaining diff, the console behavior, and the author-reported test results were not independently verified. No negative control was run.
To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files before relying on this review as a full PR assessment.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:37:16Z.
Review: COMMENTED
Outputpublishes text and status beforeSetFields_nid_no_patchcreates the guest iterator's new fields. The latter builds another field vector and can fail withU_MEMORY_ALLOCATION_ERROR. In that case the caller can see the new text even though the function reports failure and may still hold fields from its prior iteration. Please prepare the replacement iterator state before any guest output, then publish the fields and text from the same completed preparation.Source review at
d3104fca97. The combined stack has a conflict in the shared RightToLeft fixture.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T09:58:34Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Closing a registered field iterator can close the same ICU iterator twice because the extracted map node retains an owning pointer.
What I ran
Reviewed head
1760f6a7980956cbc30fc846e5d97b945d75004dby inspecting the prepared diff and selected source files; I ran no commands or tests.Results
Findings
Blocking
core/libs/prx/libSceIcu/FieldPositionIterator.cpp:21: The registry now owns each native iterator throughFieldIteratorOwner.ufieldpositer_close_nid_postfixextracts that owning entry, explicitly callsufieldpositer_close(fpositer), and then the extracted node destroys itsFieldIteratorOwner, which closes the same pointer again. Remove the explicit close and let the extracted owner close it once. This can cause a double free whenever a guest closes a field iterator.Non-blocking
None.
Sources
Not verified
The prepared manifest lists 68 reviewed files and no excluded files. I read
FieldPositionIterator.cpp,FieldPositionIterator.hpp,NumberFormat.cpp,NumberFormatBackend.cpp, andNumberFormatBackend.hpp; I inspected relevant diff hunks and portions ofNumberFormat.cppandNumberFormatNid.cpp. The other manifest files were not read, so this review does not verify their behavior. No tests, builds, console runs, or allocation-failure checks were performed.To get this to a good state
Remove the duplicate close and rerun the field iterator close and formatting tests on the updated head.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.