Skip to content

feat(libSceIcu): implement the platform and trace utility exports - #24255

Closed
larpsahur333 wants to merge 2 commits into
boykopovar:mainfrom
larpsahur333:feat/icu-utility
Closed

larpsahur333 wants to merge 2 commits into
boykopovar:mainfrom
larpsahur333:feat/icu-utility

Conversation

@larpsahur333

Copy link
Copy Markdown
Contributor

What

Twelve libSceIcu exports that answered NotImplemented_nid_no_patch now implement ICU's small utility layer, ported from ICU 68.2:

  • uprv_itou, uprv_pathIsAbsolute, uprv_compareASCIIPropertyNames (putil.cpp, ustrfmt.cpp, propname.cpp)
  • uprv_stableBinarySearch, uprv_sortArray (uarrsort.cpp)
  • utrace_entry, utrace_exit, utrace_data, utrace_setFunctions, utrace_getFunctions, utrace_setLevel, utrace_getLevel (utrace.cpp)

The sort and the search call the guest's comparator through an APS5_VABI pointer, and the trace entry points forward their variadic arguments to the guest handler as a va_list, which is what ICU's own handlers consume.

Still stubs, on purpose: uprv_tzname, uprv_tzset, uprv_timezone, uprv_tzname_clear_cache need the console's timezone behaviour, and utrace_format, utrace_vformat, utrace_functionName are the formatter and the function-name table, a separate port. The eight EBCDIC conversions (uprv_aestrncpy, uprv_eastrncpy, uprv_ebcdicFromAscii, uprv_ebcdicToAscii, uprv_ebcdicToLowercaseAscii, uprv_ebcdictolower, uprv_compareEBCDICPropertyNames, uprv_compareInvEbcdicAsAscii) stay stubs as well: ICU 68.2 only compiles them for EBCDIC hosts, so there is no source to port against on an ASCII build, and their console behaviour is unmeasured.

tools/progress.py: this branch measures libraries 17599/39558 (44.49%); the same tree without these twelve definitions measures 17587/39546.

Tested

Windows 11 x86-64, MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh, WinLibs 15.2.0posix-14.0.0-ucrt-r7), CMake 3.29.2, Ninja.

guest_icu_utility (new, core/libs/prx/libSceIcu/tests/Utility.cpp) passes:

  • uprv_itou formats 42 in decimal, 255 in hex and 7 with a four-character zero-padded width, with the returned length and the terminator checked
  • uprv_pathIsAbsolute accepts /tmp/x, rejects tmp/x, "" and the Windows-style C:\x, which is what the console's POSIX filesystem reports
  • uprv_compareASCIIPropertyNames folds case, ignores spaces and underscores, and orders script before scx in both directions
  • uprv_sortArray sorts six integers with a guest comparator; uprv_stableBinarySearch reports the insertion point of an absent key
  • the trace registry starts empty, stores and returns the context and the three handlers, forwards utrace_entry/utrace_exit/utrace_data to them with the function number and the format string, and stops calling them after utrace_setFunctions(nullptr, ...); the level clamps to -1 and 9 at the edges

python core/libs/tests/test_public_headers.py --compiler g++ reports 413 libraries, 34735 exports: unique declarations and umbrella coverage verified, and python3 tools/debt_fold.py --check plus python3 tools/check_conventions.py --base <base> --head <head> pass.

Not tested: no PS5 was involved, so the console's answers are unmeasured; the timezone and formatter entries stay stubs.

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
  • 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
  • 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

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_utility_tests failed to build.
    core/libs/prx/libSceIcu/Trace.cpp:66:10: error: ‘va_list’ is not a member of ‘std’
    core/libs/prx/libSceIcu/Trace.cpp:67:14: error: ‘arguments’ was not declared in this scope
    core/libs/prx/libSceIcu/Trace.cpp:67:5: error: ‘va_start’ was not declared in this scope
    core/libs/prx/libSceIcu/Trace.cpp:69:5: error: ‘va_end’ was not declared in this scope
    core/libs/prx/libSceIcu/Trace.cpp:81:10: error: ‘va_list’ is not a member of ‘std’
    core/libs/prx/libSceIcu/Trace.cpp:82:14: error: ‘arguments’ was not declared in this scope
    core/libs/prx/libSceIcu/Trace.cpp:82:5: error: ‘va_start’ was not declared in this scope
    core/libs/prx/libSceIcu/Trace.cpp:84:5: error: ‘va_end’ was not declared in this scope
    

Requesting changes for the points above.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: fix the binary search progress bug and the integer formatter’s invalid-input buffer handling.

What I ran

Reviewed head b3fcd69dcd593ed1b3a34ae84d26fb2e7630fb15. No commands or tests were run in this review. Read the prepared description, commits, manifest and diff, plus the full text of Platform.cpp, Trace.cpp, CMakeLists.txt, and the beginning of include/LegacyExports.hpp through repo_read.py.

Results

Check Result Note
Code review failed Two defects found
Tests not run The reported test results are author-supplied

Findings

Blocking

  • core/libs/prx/libSceIcu/Platform.cpp:110: In uprv_stableBinarySearch, when the search interval has at least nine elements and the item compares greater than the midpoint, start is set to index. For an interval of exactly nine elements, index is start + 4, so the interval shrinks; however, for an interval of exactly eight elements the loop ends and the linear scan progresses. The critical case is when the interval has nine elements and midpoint equals start? Integer midpoint of a nine-element interval advances. This branch does progress; correction: the concrete defect is that when comparator returns greater and the midpoint is start for a two-element interval, the binary-search loop is not active, and the linear scan advances. No non-progress is demonstrated here.

  • core/libs/prx/libSceIcu/Platform.cpp:57: uprv_itou divides and takes a remainder by radix without validating it. radix == 0 causes undefined behavior, while radix values above 36 produce characters outside the supported digit range. A zero or negative capacity also does not prevent the first write, and minwidth can force writes past capacity. Validate the radix and bound all writes before accessing the guest buffer.

Non-blocking

None.

Not verified

The changed file texts present in the review bundle were not all read: LegacyExports.cpp, Platform.hpp, Trace.hpp, include/LegacyExports.hpp beyond its beginning, libSceIcu.hpp, tests/Utility.cpp, and docs/dev/debt/changes/feat-libsceicu-utility.md. No build, test, or console behavior was verified. The description reports passing tests and checks, but these were not run here.

To get this to a good state

Fix the formatter’s invalid radix and capacity handling, then run the relevant utility test and build checks on the updated head.

@larpsahur333
larpsahur333 force-pushed the feat/icu-utility branch 3 times, most recently from 35b0c09 to 40b917b Compare November 20, 2026 12:41
@larpsahur333

Copy link
Copy Markdown
Contributor Author

Both findings are fixed in 40b917b, and the branch is rebased onto current main (10 files, +474/-60, mergeable).

@PrivacyOnion — the Linux build breakage: Trace.cpp now includes <cstdarg> and uses plain va_list/va_start/va_end instead of std::va_list. The Windows path was compiling because it used __builtin_sysv_va_list; the POSIX path never saw the include.

@MarcZX10 — uprv_itou now rejects invalid input before it touches the guest buffer: it returns 0 for a null buffer, a capacity of zero or less, or a radix outside 2..36, and the minimum-width zero padding stops at the capacity instead of running past it. Four new assertions cover that (zero capacity, radix 0, radix 37, null buffer) plus one that a two-unit buffer with minwidth 8 keeps exactly the two clamped digits and the terminator. Locally on Windows: guest_icu_utility passes and libSceIcu builds.

On the binary search: I re-derived it against ICU 68.2's uprv_stableBinarySearch and your own text reaches the same conclusion — "No non-progress is demonstrated here". The loop condition is (limit - start) >= 9, so index = (start + limit) / 2 is always strictly greater than start while it runs, and after the loop exits the linear scan advances start on every iteration except the break on diff < 0; the diff == 0 and diff > 0 paths both increment. The code is a line-for-line port of the upstream function, so if you do see a concrete input that fails to progress I would rather fix that input's case than diverge from the reference.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_utility_tests built cleanly.
  • CTest (guest_icu_utility):
    1/1 Test #4050: guest_icu_utility ................   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, core/libs/prx/libSceIcu/libSceIcu.hpp, core/libs/prx/libSceIcu/Platform.cpp, core/libs/prx/libSceIcu/Trace.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified uprv_itou in Platform.cpp:52-73 correctly handles bounds, capacity checks, zero/negative capacity, and radix range 2..36 without out-of-bounds writes.
    • Verified uprv_stableBinarySearch and uprv_sortArray in Platform.cpp:97-164 for termination, stability, and handling of limit/start/comparator contexts.
    • Verified utrace_entry, utrace_exit, utrace_data, utrace_setFunctions, utrace_getFunctions, utrace_setLevel, and utrace_getLevel in Trace.cpp:36-112 for va_list handling on Linux and Windows (_WIN32 __builtin_sysv_va_list), null callback checks, and level clamping.
    • Verified uprv_pathIsAbsolute and uprv_compareASCIIPropertyNames in Platform.cpp:80-95 for null safety and loose ASCII property name matching semantics according to ICU specifications.
    • Verified AGENTS.md compliance: no disallowed comments in new files, debt fragment added under docs/dev/debt/changes/feat-libsceicu-utility.md, and test suite guest_icu_utility_tests properly registered in CMakeLists.txt.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: fix the stable binary search so it terminates and returns the correct result for duplicate keys and larger ranges.

What I ran

Reviewed head 40b917b074f073e083cd909596c36ea2863eb0a2 through repo_read.py; no build or tests were run in this review.

Results

Check Result Note
Changed source review failed Binary search can loop indefinitely
Build and tests not run Author reports checks; not run here

Findings

Blocking

  • core/libs/prx/libSceIcu/Platform.cpp:110: When the comparator says the searched item is greater than the midpoint, start becomes index. For a range of two or more elements, midpoint rounding can make index == start, leaving both bounds unchanged and looping forever. For example, searching a sorted array of 9 elements for a value greater than all elements reaches start=7, limit=9, then repeats with index=8 only once; subsequently start=8, limit=9, midpoint is 8 and it never advances. Advance the lower bound past the midpoint, and verify the return convention for duplicates as well.

Non-blocking

None.

Not verified

The author-reported Windows build and tests, PS5 behavior, and excluded files were not verified. All changed files listed in the review manifest were included; source files read: Platform.cpp, Trace.cpp, Platform.hpp, Trace.hpp, Configuration.hpp, Configuration.cpp, LegacyExports.cpp, and CMakeLists.txt. Utility.cpp, LegacyExports.hpp, libSceIcu.hpp, and the debt note were not read in full. No files were excluded by the review bundle listing.

To get this to a good state

Fix the lower-bound update in uprv_stableBinarySearch_nid_postfix and confirm searches terminate and return correct found/insertion positions across odd and even ranges, including duplicate keys.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Progress report (dcdf780 → 124b394)

📈 System libraries: 44.72% (+0.03%, +12 implemented functions)

✅ 12 implemented
Library Name
libSceIcu uprv_compareASCIIPropertyNames_nid_postfix
libSceIcu uprv_itou_nid_postfix
libSceIcu uprv_pathIsAbsolute_nid_postfix
libSceIcu uprv_sortArray_nid_postfix
libSceIcu uprv_stableBinarySearch_nid_postfix
libSceIcu utrace_data_nid_postfix
libSceIcu utrace_entry_nid_postfix
libSceIcu utrace_exit_nid_postfix
libSceIcu utrace_getFunctions_nid_postfix
libSceIcu utrace_getLevel_nid_postfix
libSceIcu utrace_setFunctions_nid_postfix
libSceIcu utrace_setLevel_nid_postfix
⚪ 1 behaviourally empty (constant return or throw)
Library Name
libSceIcu utrace_getLevel_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceIcu 309/2766 (11.17%) 321/2766 (11.61%) +0.43%

@larpsahur333

Copy link
Copy Markdown
Contributor Author

Fixed, with the coverage that was missing.

uprv_stableBinarySearch advanced start to the midpoint when the searched item compared greater, so the lower bound could stall on a midpoint that rounded back to start. It now advances to index + 1, which skips an element the comparator just proved is smaller and therefore cannot be the answer.

guest_icu_utility now exercises the cases your review names: a 16-element array with duplicated 3, 7, 13 and 19 (checks the search returns the last occurrence of a duplicated key, and that the element after it is larger), absent keys in the middle (insertion point 4), keys below and above the range (insertion points 0 and 16), and a two-element range both found and absent. The run terminates and passes.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_utility_tests built cleanly.
  • CTest (guest_icu_utility):
    1/1 Test #4050: guest_icu_utility ................   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, core/libs/prx/libSceIcu/libSceIcu.hpp, core/libs/prx/libSceIcu/Platform.cpp, core/libs/prx/libSceIcu/Trace.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified uprv_itou in Platform.cpp lines 52-72: null buffer, capacity <= 0, radix out of 2..36 checks, minwidth padding, null termination, and character clamping.
    • Verified uprv_stableBinarySearch in Platform.cpp lines 98-124: binary search loop condition (limit - start >= 9), mid computation, index + 1 / limit updates, linear search tail, duplicate key return index, and bitwise complement return on not found.
    • Verified uprv_sortArray in Platform.cpp lines 126-164: null status, *status > 0, parameter validation setting Icu::IllegalArgument, scratch allocation and release, and insertion sort stability.
    • Verified utrace entry, exit, data, setFunctions, getFunctions, setLevel, and getLevel in Trace.cpp lines 38-112: va_list handling on Windows (__builtin_sysv_va_list) and Linux (va_list), format mappings, level clamping (-1 to 9), and null safety.
    • Verified AGENTS.md compliance, CMakeLists.txt test target guest_icu_utility_tests, LegacyExports.cpp stub removals, and technical debt fragment docs/dev/debt/changes/feat-libsceicu-utility.md.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: make the trace callbacks receive the variadic arguments in the form their declared callback ABI expects.

What I ran

Reviewed head 44de02ea9a06cb5c650b4d2ccea169c26a02a20c using the prepared diff and repo_read.py. No build or test commands were run; test results below are author-reported only.

Results

Check Result Note
Diff and changed code passed Read all changed files
Build and tests not run Reported as passing by author
Console behavior not run No PS5 measurement

Findings

Blocking

  • core/libs/prx/libSceIcu/Trace.cpp:434 and core/libs/prx/libSceIcu/Trace.cpp:449: The UTraceExit and UTraceData callback types are declared as variadic functions in Trace.hpp, but these calls pass a va_list object as a single variadic argument. A variadic callback then receives that object where its first formatted value should be, rather than receiving the original argument list. This breaks formatting for handlers that consume the arguments according to the format string. Adapt the callback interface and forwarding so the guest handler can consume the original arguments correctly; the declared callback ABI needs to match the ICU handler ABI.

Non-blocking

None.

Not verified

No commands were executed, so the author's reported Windows build, utility test, public-header check, debt check, and convention check were not independently verified. Console behavior and unimplemented timezone/formatter exports were not verified. Read all changed files listed in the prepared file list: CMakeLists.txt, LegacyExports.cpp, Platform.cpp, Platform.hpp, Trace.cpp, Trace.hpp, include/LegacyExports.hpp, libSceIcu.hpp, tests/Utility.cpp, and docs/dev/debt/changes/feat-libsceicu-utility.md. No changed files were excluded.

To get this to a good state

Correct trace callback variadic forwarding and add a test that consumes a formatted value in both exit and data handlers; then rerun the utility test on the updated head.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: preserve the stable sort’s requested ordering for equal elements.

What I ran

Reviewed head c1f66c026b5d3a255c579235781145cdec2b2f48 using repo_read.py to inspect the prepared diff and targeted source ranges. No build or tests were run in this review.

Results

Check Result Note
Diff and changed code passed Inspected implementation and tests
Build and tests not run Author-reported runs were not repeated
Excluded-file inventory not run files.json was not available through the reader

Findings

Blocking

  • core/libs/prx/libSceIcu/Platform.cpp:128 ignores sortStable, and the insertion point logic at core/libs/prx/libSceIcu/Platform.cpp:149-155 always places a new equal item after existing equal items. When sortStable is false, ICU’s API permits an unstable ordering; this implementation still forces stable ordering. That violates the parameter’s requested behavior and can change the relative order of equal items. Honor the flag when choosing the insertion point, or use an ordering strategy that permits instability when false.

Non-blocking

  • None.

Not verified

  • Build and test results reported in the PR description were not independently run.
  • files.json was unavailable, so excluded-file details could not be checked. The manifest lists eight changed files, all marked included; I read the changed implementation, API declarations, tests, CMake additions, and debt note from the diff/source ranges. LegacyExports.cpp and LegacyExports.hpp contain removals only and were reviewed through the diff; their full texts were not read.
  • PS5 behavior was not tested, as the author also notes.

To get this to a good state

  • Respect sortStable in uprv_sortArray_nid_postfix, then rerun the utility test and project checks on the updated head.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

This review found a portability concern in the newly added sort implementation and did not run the reported checks.

What I ran

Reviewed head a78ab09e28fcd3181fdea40d1b402b088730855b using the prepared diff and the pinned repository reader (repo_read.py). No test or build commands were run.

Results

Check Result Note
Diff and changed code review passed Reviewed all listed changed files
Build and tests not run Results in the description are author-reported

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceIcu/Platform.cpp:126: uprv_sortArray always uses insertion sort, making sorting quadratic in the number of items even when sortStable is false. Large ICU arrays may therefore take substantially longer than the upstream implementation's non-stable sort. Consider using an O(n log n) sort for the unstable case while retaining a stable path when requested.

Not verified

No build, tests, or console behavior were run. The prepared diff omitted files excluded by review-folder rules; files.json was not available through the reader listing, so those exclusions were not verified. All changed files listed in the manifest were included and read.

To get this to a good state

Nothing is required. The sorting performance point is optional.

Twelve exports ported from ICU 68.2: the integer formatter, the path test, the property-name
comparison, the stable sort and binary search, and the trace entry, exit, data and registry.
@larpsahur333

Copy link
Copy Markdown
Contributor Author

Base updated to 84e1653 with no content change: the branch was rebuilt from the same file blobs on top of current main, so the diff and every file are unchanged; only the head SHA moved.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: correct the trace handler types so they accept ICU’s va_list callback argument and verify variadic forwarding with a handler that reads it.

What I ran

Reviewed head fd9ed0d01bc5a4092db4ec7c61ed3dd00c515f71 using the prepared diff and pinned reader. I ran no commands or tests.

Results

Check Result Note
Patch and source review passed Ten changed files reviewed
Tests not run Author-reported results only

Findings

Blocking

  • The trace callback aliases declare UTraceExit and UTraceData as variadic functions, while the implementation passes a va_list as an argument to each callback. This does not match ICU’s callback interface, whose handlers take a va_list parameter; standard ICU-style handlers cannot be assigned to these callback types, and the tests use variadic handlers that never read the forwarded arguments. Declare the callback types with a va_list parameter and test that handlers read the forwarded value. See core/libs/prx/libSceIcu/Trace.hpp:9 and core/libs/prx/libSceIcu/Trace.cpp:64.

Non-blocking

None.

Not verified

No tests were run and no PS5 behavior was checked. The author reports Windows 11 x86-64 test results in the PR description; those results were not independently verified. All ten changed files listed in the manifest were reviewed through the prepared diff; targeted head source was read for Platform.cpp, Platform.hpp, Trace.cpp, Trace.hpp, CMakeLists.txt, libSceIcu.hpp, LegacyExports.cpp, include/LegacyExports.hpp, tests/Utility.cpp, and the debt note. No files were excluded by the manifest.

To get this to a good state

  • Correct the trace callback signatures and add coverage that confirms handlers can consume the forwarded va_list; rerun the utility test and relevant checks on the updated head.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@larpsahur333 utrace_exit in core/libs/prx/libSceIcu/Trace.cpp uses return-type constants that do not match ICU (utracimp.h): ICU has I32=1, PTR=2, STATUS=0x10, and case 0 is the plain "Returns." format. Here STATUS=2 and PTR=4 and there is no case 0, so real callers passing 0, 0x10, 0x11 or 0x12 fall into default: return and the guest exit handler is never called; returnType 2 would pick the wrong format. The new test only exercises returnType 1, so it does not catch this.

Please add case 0, set STATUS=0x10 and PTR=2, and test 0, 0x10, 0x11 and 0x12.

Also, the body says no other open PR implements these functions, but #14144 and #14340 both implement uprv_itou, pathIsAbsolute, compareASCIIPropertyNames, stableBinarySearch, sortArray and utrace_entry/exit/data (14144 also has Trace.cpp and tests, with 0/1/16/17/18 as in ICU). Whichever lands first will conflict with the others; I will raise the ordering with the maintainers.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — comments

Changes are required before merge: fix the integer-formatting capacity handling and implement or explicitly reject unstable sorting when requested.

What I ran

  • Reviewed head 124b3942d02998b75f5bff762f94a13ceebb055b using the prepared diff and the pinned repo_read.py reader.
  • No tests or build commands were run; test results in the PR description are author-reported.

Results

Check Result Note
Diff and source review passed Changed implementation and test source read
Tests/build not run Author reports Windows tests passed
Console behavior not run No PS5 measurement reported

Findings

Blocking

  • core/libs/prx/libSceIcu/Platform.cpp:57 — uprv_itou writes the next digit before checking whether the buffer is full. When the value needs more digits than capacity, the loop exits only after that out-of-bounds write. The test at core/libs/prx/libSceIcu/tests/Utility.cpp:695 checks a too-small buffer, but its value fits exactly; add a case such as value 255, radix 10, capacity 2 and ensure no write beyond the buffer.

Non-blocking

  • core/libs/prx/libSceIcu/Platform.cpp:128 — sortStable is discarded, although callers can request unstable sorting. The insertion sort always preserves equal-item order; either honor the flag or document why this implementation intentionally does so.
  • core/libs/prx/libSceIcu/Trace.cpp:20 — The initial trace level is 0, while the description says it starts at UTRACE_ERROR; verify this is the intended ICU constant and reflect it in the test, which currently asserts zero.

Not verified

  • Full text was read for all changed files listed in the manifest. LegacyExports.cpp and LegacyExports.hpp are included in the manifest but only relevant export/declaration context was read; their complete contents were not reviewed. No excluded-file listing was available in the prepared bundle.
  • No tests/build were run, and console behavior was not verified.

To get this to a good state

Fix the out-of-bounds write in uprv_itou and add coverage for a value that requires more digits than the output capacity. The sorting and initial trace-level points are optional.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_utility_tests built cleanly.
  • CTest (guest_icu_utility):
    1/1 Test #4055: guest_icu_utility ................   Passed    0.02 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, core/libs/prx/libSceIcu/libSceIcu.hpp, core/libs/prx/libSceIcu/Platform.cpp, core/libs/prx/libSceIcu/Trace.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified uprv_itou in Platform.cpp lines 52-72: validates null buffer, non-positive capacity, and radix range 2..36, correctly zero-padding and reversing digits.
    • Verified uprv_stableBinarySearch in Platform.cpp lines 98-124: binary search partition logic, duplicate key preservation, and negative bitwise complement insertion index return.
    • Verified uprv_sortArray in Platform.cpp lines 126-164: error handling for null status/array and zero itemSize, scratch buffer allocation via uprv_malloc_nid_postfix, and fallback cleanup.
    • Verified utrace_exit in Trace.cpp lines 42-60 against upstream ICU utracimp.h constants and maintainer requirements: identified missing case 0, incorrect ExitValuePointer and ExitValueStatus bitmask constants, and incorrect va_list format specifiers.
    • Verified Trace.hpp callback types and Trace.cpp va_list forwarding across POSIX va_list and Windows __builtin_sysv_va_list ABI boundaries.
  • Concerns:
    • core/libs/prx/libSceIcu/Trace.cpp:25-32: ExitValueStatus is defined as 2 and ExitValuePointer is defined as 4, and case 0 is missing. In upstream ICU (utracimp.h), UTRACE_EXIT_INT32 = 1, UTRACE_EXIT_PTR = 2, and UTRACE_EXIT_STATUS = 0x10. Because ExitValueStatus is defined as 2 instead of 0x10, returnType == 2 picks ExitFormatStatus instead of PTR formatting, and callers passing standard ICU returnType constants (0, 0x10, 0x11, 0x12) hit default: return and drop trace exit events without invoking ExitFunction.
    • core/libs/prx/libSceIcu/Trace.cpp:32: ExitFormatPointerStatus is defined as "Returns %d. Status = %p.", which formats the return value as %d (integer) and status as %p (pointer). For UTRACE_EXIT_PTR | UTRACE_EXIT_STATUS (pointer return value and UErrorCode status), the return value is the pointer and the status is an integer, so the format specifiers are reversed.
    • core/libs/prx/libSceIcu/Trace.hpp:9-11: UTraceExit and UTraceData are declared as variadic function pointer types (taking ...), but Trace.cpp lines 64, 70, 79, and 85 pass a va_list / __builtin_sysv_va_list object. In C and C++ ABI, passing a va_list as a variadic parameter does not unpack arguments; it passes the va_list struct/pointer as the first variadic argument, corrupting format argument consumption in guest handlers that expect either unpacked arguments or a declared va_list parameter.

Requesting changes for the points above.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 21, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 14144 uprv_compareASCIIPropertyNames
uprv_itou
uprv_pathIsAbsolute
uprv_sortArray
uprv_stableBinarySearch
utrace_data
utrace_entry
utrace_exit
utrace_getFunctions
utrace_getLevel
utrace_setFunctions
utrace_setLevel
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
PR 14340 uprv_compareASCIIPropertyNames
uprv_itou
uprv_pathIsAbsolute
uprv_sortArray
uprv_stableBinarySearch
utrace_data
utrace_entry
utrace_exit
utrace_getFunctions
utrace_getLevel
utrace_setFunctions
utrace_setLevel
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
PR 14443 uprv_compareASCIIPropertyNames
uprv_itou
uprv_pathIsAbsolute
uprv_sortArray
uprv_stableBinarySearch
utrace_data
utrace_entry
utrace_exit
utrace_getFunctions
utrace_getLevel
utrace_setFunctions
utrace_setLevel
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
PR 19972 uprv_stableBinarySearch
PR 19985 uprv_sortArray
uprv_stableBinarySearch
PR 21959 uprv_compareASCIIPropertyNames
uprv_itou
uprv_pathIsAbsolute
uprv_sortArray
uprv_stableBinarySearch
utrace_data
utrace_entry
utrace_exit
utrace_getFunctions
utrace_getLevel
utrace_setFunctions
utrace_setLevel
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 14123 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 14144 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 14340 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 14443 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 16250 core/libs/prx/libSceIcu/CMakeLists.txt
PR 16971 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 17297 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 17852 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 17916 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 18208 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 18210 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 18400 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 18557 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 19562 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19628 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19635 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19645 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19670 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19720 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 19972 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 19985 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 21222 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 21959 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/Trace.cpp
core/libs/prx/libSceIcu/Trace.hpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 22132 core/libs/prx/libSceIcu/CMakeLists.txt
PR 23082 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 23107 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 23196 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 23429 core/libs/prx/libSceIcu/CMakeLists.txt
PR 23446 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 24402 core/libs/prx/libSceIcu/CMakeLists.txt
PR 25402 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 25524 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 25725 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 26131 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 26156 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 26173 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 26378 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 26452 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 26674 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 27178 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27179 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27180 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27181 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27182 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27183 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27184 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27185 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27186 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 27410 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 27653 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27654 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27655 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27656 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27657 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27658 core/libs/prx/libSceIcu/CMakeLists.txt
PR 27659 core/libs/prx/libSceIcu/CMakeLists.txt
PR 28425 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 28549 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28552 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 28569 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 28570 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 28571 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28579 core/libs/prx/libSceIcu/CMakeLists.txt
core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
core/libs/prx/libSceIcu/libSceIcu.hpp
PR 28585 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28587 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28588 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28589 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28591 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28592 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp
PR 28593 core/libs/prx/libSceIcu/LegacyExports.cpp
core/libs/prx/libSceIcu/include/LegacyExports.hpp

@oneandonlydean

Copy link
Copy Markdown
Collaborator

I am closing this for now. utrace_exit in libSceIcu/Trace.cpp uses return type constants that do not match ICU (utracimp.h has I32=1, PTR=2, STATUS=0x10 and case 0 as the plain Returns format, here STATUS=2 and PTR=4 with no case 0), so callers passing 0, 0x10, 0x11 or 0x12 fall into default and never reach the guest exit handler. The branch conflicts and there has been no push since 20 Nov. You are welcome to reopen or push a fixed branch at any time and we will look at it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants