feat(libSceNKWebKit): implement PAL::fileSizeDescription #19460

Merged
MatteoSid merged 4 commits from upstream-pr/19460 into main 2026-11-13 14:39:00 +00:00
MatteoSid commented 2026-11-13 11:04:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MatteoSid on 2026-11-13T11:04:57Z.


What

Implements PAL::fileSizeDescription(unsigned long) (_ZN3PAL19fileSizeDescriptionEm, NID Pbp5FkR35mI) in libSceNKWebKit. Before this PR it threw through NotImplemented_nid_no_patch.

The code follows the non-Cocoa branch of pinned WebKit FileSizeFormatter.cpp lines 35-46 at c55364d53f97, the revision the other libSceNKWebKit WTF and WebCore entries pin:

  • below 1000: the decimal size and bytes;
  • below 1000000: size / 1000. to one decimal place and KB;
  • below 1000000000: size / 1000000. and MB;
  • otherwise: size / 1000000000. and GB.

Upstream formats the number with FormattedNumber::fixedWidth(value, 1), which is numberToFixedWidthString, that is double-conversion's ToFixed with the EcmaScript converter. ToFixed works on the exact binary value and rounds up when the first discarded bit is set (fixed-dtoa.cc lines 264-268). The PR reuses the merged NKWebKit::WtfAbi::NumberToFixedWidthString from src/WtfNumberFormat.cpp, which TextStream already uses for the same ToFixed behaviour. It builds the result with the merged WTF::StringImpl::create(const LChar*, unsigned) export, as the color serialization exports in WebCoreColorSpaces.cpp do. No new String layout or allocator is added.

The code is in the new src/PalFileSizeFormatter.cpp, which starts with a Derived from line and the upstream Apple notice, byte-identical to lines 1-24 of the pinned file. The stub leaves Export.cpp and InventoryExports.hpp, and the declaration goes into WtfExports.hpp beside the other PAL exports. In docs/dev/debt/libSceNKWebKit.md, the table row is removed and the throwing count goes from 5949 (main) to 5948. A new gap entry records that the code was not compared with a console module. It also records that the PS5 11.x tree returns an AtomString built by makeAtomString, while this PR returns a plain 8-bit String that is not in the atom table. The export name does not encode the return type, so the two cannot be told apart from the symbol.

Reachability: the only argument is a plain uint64_t. The function reads no object, global or earlier state, so any caller reaches the whole implementation, including WebCore code in the same module. The result is an ordinary 8-bit WTF::String, the same as the other implemented String-returning exports in this library return.

Tested

Linux, anyps5-dev:24.04 container (Ubuntu 24.04, GCC 13.3), Release, -DBUILD_TESTING=ON. Head 65e48e8917. It merges main at b33b901eab (merge commit 5bfaa3278c). The PR was first based on main d134f4c8ea.

The merge had no textual conflict, but git kept both "N of the 8703" count lines, 5948 from this branch and 5940 from main. 65e48e8917 keeps one line, set to 5939: main's 5940 minus the one stub this PR removes, with no recount.

  • On head 65e48e8917 I built all 77 libSceNKWebKit test targets and the NID-patched libSceNKWebKit.prx with no errors. ctest -R "nkwebkit|^public_headers$" passes 78 of 78: the 77 libSceNKWebKit tests, including nkwebkit_palfilesizeformatter, and public_headers. git diff --check origin/main HEAD is clean.

  • nkwebkit_palfilesizeformatter checks the exact strings. It also checks that each result is a non-null 8-bit StringImpl with one reference. Expected values were worked out from the exact double quotients with Python's Decimal and ROUND_HALF_UP:

    • bytes: 0 bytes, 1 bytes, 999 bytes;
    • KB: 1000 1.0 KB, 1049 1.0 KB, 1050 1.1 KB, 1150 1.1 KB, 1250 1.3 KB, 1350 1.4 KB, 999949 999.9 KB, 999950 1000.0 KB, 999999 1000.0 KB;
    • MB: 1000000 1.0 MB, 1250000 1.3 MB, 1500000 1.5 MB, 999949999 999.9 MB, 999999999 1000.0 MB;
    • GB: 1000000000 1.0 GB, 1250000000 1.3 GB, 123456789012 123.5 GB, UINT64_MAX 18446744073.7 GB.

    Two of these cases separate the rounding rules. 1150/1000. is just below 1.15, so it gives 1.1. 1250/1000. is exactly 1.25, a tie that ToFixed rounds up to 1.3, where printf's round-half-even would give 1.2.

  • Mutation check, run on the earlier head fd430701b2 (the code is unchanged since then), one change at a time: 17 of 17 make the test fail at run time (none by a build error). The mutations:

    • < changed to <= at each of the three thresholds;
    • each of the four suffixes changed;
    • binary divisors (1024, 1048576, 1073741824) for each unit;
    • integer division for KB;
    • a different number of decimal places for each unit;
    • printf("%.1f") (ties to even) instead of the ToFixed formatter;
    • a null String for bytes;
    • the old throwing stub.
  • nm -D --defined-only on the patched libSceNKWebKit.prx built from 65e48e8917 lists Pbp5FkR35mI (T). tools/nid_names.py's NID of _ZN3PAL19fileSizeDescriptionEm is Pbp5FkR35mI.

  • python3 tools/check_conventions.py --base origin/main --head HEAD passes.

  • Overlap:

    • On head 090b3a1ff7, tools/pr_overlap.py --branch in anyps5-dev-gh:24.04 merged the 95 open PRs that share files and found no shared export. It could not compare 25 PRs that conflict with main. I read their diffs by hand: none adds or removes fileSizeDescription or edits the lines next to my hunks. They share only the "N of the 8703" count line, which every libSceNKWebKit PR edits. #18377 and #18395 also conflict with main alone, in Export.cpp and LegacyExports.hpp, and merge-tree shows the same conflicts with this branch; their debt entries merge cleanly.
    • #19330 (PAL::CryptoDigest) removes the stubs just above this one. On head 090b3a1ff7, git merge-tree --write-tree merged it, #19302 and #18951 with this branch cleanly. On 65e48e8917 it merges #19302 (77928b987d) and main b33b901eab cleanly.
    • Searches for fileSizeDescription, Pbp5FkR35mI and FileSizeFormatter find no other PR.
  • Windows: JJenkx ran nkwebkit_palfilesizeformatter on head 65e48e8917 merged onto main (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs (comment).

  • Not run: macOS, a console, a title.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5294355803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19460). Originally posted by [MatteoSid](https://github.com/MatteoSid) on 2026-11-13T11:04:57Z. --- ### What Implements `PAL::fileSizeDescription(unsigned long)` (`_ZN3PAL19fileSizeDescriptionEm`, NID `Pbp5FkR35mI`) in libSceNKWebKit. Before this PR it threw through `NotImplemented_nid_no_patch`. The code follows the non-Cocoa branch of pinned WebKit [`FileSizeFormatter.cpp` lines 35-46](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WebCore/PAL/pal/FileSizeFormatter.cpp#L35-L46) at `c55364d53f97`, the revision the other libSceNKWebKit WTF and WebCore entries pin: - below 1000: the decimal size and ` bytes`; - below 1000000: `size / 1000.` to one decimal place and ` KB`; - below 1000000000: `size / 1000000.` and ` MB`; - otherwise: `size / 1000000000.` and ` GB`. Upstream formats the number with `FormattedNumber::fixedWidth(value, 1)`, which is [`numberToFixedWidthString`](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/dtoa.cpp#L107-L120), that is `double-conversion`'s `ToFixed` with the EcmaScript converter. `ToFixed` works on the exact binary value and rounds up when the first discarded bit is set ([`fixed-dtoa.cc` lines 264-268](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/dtoa/fixed-dtoa.cc#L264-L268)). The PR reuses the merged `NKWebKit::WtfAbi::NumberToFixedWidthString` from `src/WtfNumberFormat.cpp`, which `TextStream` already uses for the same `ToFixed` behaviour. It builds the result with the merged `WTF::StringImpl::create(const LChar*, unsigned)` export, as the color serialization exports in `WebCoreColorSpaces.cpp` do. No new String layout or allocator is added. The code is in the new `src/PalFileSizeFormatter.cpp`, which starts with a `Derived from` line and the upstream Apple notice, byte-identical to lines 1-24 of the pinned file. The stub leaves `Export.cpp` and `InventoryExports.hpp`, and the declaration goes into `WtfExports.hpp` beside the other `PAL` exports. In `docs/dev/debt/libSceNKWebKit.md`, the table row is removed and the throwing count goes from 5949 (main) to 5948. A new gap entry records that the code was not compared with a console module. It also records that the [PS5 11.x tree](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebCore/PAL/pal/FileSizeFormatter.cpp#L35-L46) returns an `AtomString` built by `makeAtomString`, while this PR returns a plain 8-bit `String` that is not in the atom table. The export name does not encode the return type, so the two cannot be told apart from the symbol. Reachability: the only argument is a plain `uint64_t`. The function reads no object, global or earlier state, so any caller reaches the whole implementation, including WebCore code in the same module. The result is an ordinary 8-bit `WTF::String`, the same as the other implemented String-returning exports in this library return. ### Tested Linux, `anyps5-dev:24.04` container (Ubuntu 24.04, GCC 13.3), Release, `-DBUILD_TESTING=ON`. Head `65e48e8917`. It merges `main` at `b33b901eab` (merge commit `5bfaa3278c`). The PR was first based on `main` `d134f4c8ea`. The merge had no textual conflict, but git kept both "N of the 8703" count lines, 5948 from this branch and 5940 from `main`. `65e48e8917` keeps one line, set to 5939: `main`'s 5940 minus the one stub this PR removes, with no recount. - On head `65e48e8917` I built all 77 libSceNKWebKit test targets and the NID-patched `libSceNKWebKit.prx` with no errors. `ctest -R "nkwebkit|^public_headers$"` passes 78 of 78: the 77 libSceNKWebKit tests, including `nkwebkit_palfilesizeformatter`, and `public_headers`. `git diff --check origin/main HEAD` is clean. - `nkwebkit_palfilesizeformatter` checks the exact strings. It also checks that each result is a non-null 8-bit `StringImpl` with one reference. Expected values were worked out from the exact `double` quotients with Python's `Decimal` and `ROUND_HALF_UP`: - bytes: `0 bytes`, `1 bytes`, `999 bytes`; - KB: 1000 `1.0 KB`, 1049 `1.0 KB`, 1050 `1.1 KB`, 1150 `1.1 KB`, 1250 `1.3 KB`, 1350 `1.4 KB`, 999949 `999.9 KB`, 999950 `1000.0 KB`, 999999 `1000.0 KB`; - MB: 1000000 `1.0 MB`, 1250000 `1.3 MB`, 1500000 `1.5 MB`, 999949999 `999.9 MB`, 999999999 `1000.0 MB`; - GB: 1000000000 `1.0 GB`, 1250000000 `1.3 GB`, 123456789012 `123.5 GB`, `UINT64_MAX` `18446744073.7 GB`. Two of these cases separate the rounding rules. 1150/1000. is just below 1.15, so it gives `1.1`. 1250/1000. is exactly 1.25, a tie that `ToFixed` rounds up to `1.3`, where `printf`'s round-half-even would give `1.2`. - Mutation check, run on the earlier head `fd430701b2` (the code is unchanged since then), one change at a time: 17 of 17 make the test fail at run time (none by a build error). The mutations: - `<` changed to `<=` at each of the three thresholds; - each of the four suffixes changed; - binary divisors (1024, 1048576, 1073741824) for each unit; - integer division for KB; - a different number of decimal places for each unit; - `printf("%.1f")` (ties to even) instead of the `ToFixed` formatter; - a null String for bytes; - the old throwing stub. - `nm -D --defined-only` on the patched `libSceNKWebKit.prx` built from `65e48e8917` lists `Pbp5FkR35mI` (`T`). `tools/nid_names.py`'s NID of `_ZN3PAL19fileSizeDescriptionEm` is `Pbp5FkR35mI`. - `python3 tools/check_conventions.py --base origin/main --head HEAD` passes. - Overlap: - On head `090b3a1ff7`, `tools/pr_overlap.py --branch` in `anyps5-dev-gh:24.04` merged the 95 open PRs that share files and found no shared export. It could not compare 25 PRs that conflict with `main`. I read their diffs by hand: none adds or removes `fileSizeDescription` or edits the lines next to my hunks. They share only the "N of the 8703" count line, which every libSceNKWebKit PR edits. #18377 and #18395 also conflict with `main` alone, in `Export.cpp` and `LegacyExports.hpp`, and merge-tree shows the same conflicts with this branch; their debt entries merge cleanly. - #19330 (`PAL::CryptoDigest`) removes the stubs just above this one. On head `090b3a1ff7`, `git merge-tree --write-tree` merged it, #19302 and #18951 with this branch cleanly. On `65e48e8917` it merges #19302 (`77928b987d`) and `main` `b33b901eab` cleanly. - Searches for `fileSizeDescription`, `Pbp5FkR35mI` and `FileSizeFormatter` find no other PR. - Windows: JJenkx ran `nkwebkit_palfilesizeformatter` on head `65e48e8917` merged onto `main` (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs ([comment](https://github.com/boykopovar/AnyPS5/pull/19460#issuecomment-6852703275)). - Not run: macOS, a console, a title. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!19460
No description provided.