feat(libSceNKWebKit): implement WTF::StringPrintStream #20404

Closed
RiverWhy wants to merge 7 commits from upstream-pr/20404 into main
RiverWhy commented 2026-11-15 05:19:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RiverWhy on 2026-11-15T05:19:55Z.


What

Implements the 11 exports of WTF::StringPrintStream, WTF's print-into-a-string PrintStream, following the pinned StringPrintStream.cpp (identical at e12a212a531a, the revision the URL parser follows):

  • Constructors (C1, C2): the buffer starts as the 128-byte inline buffer, empty and NUL-terminated.
  • vprintf(const char*, va_list): the source's two passes. The first formats into the remaining space through a copy of the guest va_list (a struct copy, which is va_copy for the System V va_list); if the text does not fit, the buffer grows to twice the needed size (fastMalloc, old contents copied, old heap buffer freed) and the second pass formats with the caller's list. Formatting is guest vsnprintf.
  • toCString, toString (String::fromUTF8, null for invalid UTF-8), toStringWithLatin1Fallback, and tryToString, which returns Expected<String, UTF8ConversionError> with OutOfMemory past String::MaxLength.
  • reset: empties the text and keeps the buffer, heap or inline.
  • Destructors (D1, D2, and D0, which also fastFrees the object, as WTF_MAKE_FAST_ALLOCATED does).

Layouts, with static_asserts in StringPrintStreamExports.hpp, were measured on a Linux build of WTF: the 160-byte object (vtable pointer, buffer, write position at 16, size at 24, inline buffer at 32) and the 16-byte Expected (value or error code at 0, has-value byte at 8, OutOfMemory = 1).

The constructor installs a vtable built here with the source's slot order (checked with -fdump-lang-class): complete and deleting destructors, vprintf, flush (empty, as PrintStream::flush is), then the PrintStream::begin and PrintStream::end exports. PrintStream::end is still a placeholder (#19380 implements it), so print through the stream throws until that lands; vprintf and the conversions do not depend on it. The empty flush slot is a local APS5_VABI function, so progress.py lists it among the inert names, as it does WtfJson.cpp's vtable slots.

A null object, format or argument list throws, and so does a failed format, where the source would move its write position backwards.

Debt: a fragment, docs/dev/debt/changes/feat-nkwebkit-string-print-stream.md, adds the entry under Functional and removes the 11 inventory rows.

Tested

Linux Mint 22.3:

  • New nkwebkit_stringprintstream test: construction over poisoned storage (both constructors), every vtable slot against the export it should hold, calling vprintf, flush and begin through the vtable as guest code does, and the deleting destructor through slot 1 on a fastMalloc'd stream. Buffer growth matches WTF built for Linux for the same sequences: three 120-character prints (position 360, size 482), one 1000-character print (size 2002), 127 characters staying inline then one more growing to 258, fifty short prints (140, 258), and reset keeping the 482-byte heap buffer. Also toCString, UTF-8 and invalid UTF-8 through toString, toStringWithLatin1Fallback and tryToString, and the null refusals. The test passes a real System V va_list on both Linux and Windows builds (__builtin_sysv_va_start, as FileHandle::printf does).
  • ctest -R nkwebkit: 91 tests passed. progress.py --module libSceNKWebKit: the 11 exports move to implemented.

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:5319775351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20404). Originally posted by [RiverWhy](https://github.com/RiverWhy) on 2026-11-15T05:19:55Z. --- ### What Implements the 11 exports of `WTF::StringPrintStream`, WTF's print-into-a-string `PrintStream`, following the pinned [StringPrintStream.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/StringPrintStream.cpp) (identical at `e12a212a531a`, the revision the URL parser follows): - Constructors (`C1`, `C2`): the buffer starts as the 128-byte inline buffer, empty and NUL-terminated. - `vprintf(const char*, va_list)`: the source's two passes. The first formats into the remaining space through a copy of the guest `va_list` (a struct copy, which is `va_copy` for the System V `va_list`); if the text does not fit, the buffer grows to twice the needed size (`fastMalloc`, old contents copied, old heap buffer freed) and the second pass formats with the caller's list. Formatting is guest `vsnprintf`. - `toCString`, `toString` (`String::fromUTF8`, null for invalid UTF-8), `toStringWithLatin1Fallback`, and `tryToString`, which returns `Expected<String, UTF8ConversionError>` with `OutOfMemory` past `String::MaxLength`. - `reset`: empties the text and keeps the buffer, heap or inline. - Destructors (`D1`, `D2`, and `D0`, which also `fastFree`s the object, as `WTF_MAKE_FAST_ALLOCATED` does). Layouts, with `static_assert`s in `StringPrintStreamExports.hpp`, were measured on a Linux build of WTF: the 160-byte object (vtable pointer, buffer, write position at 16, size at 24, inline buffer at 32) and the 16-byte `Expected` (value or error code at 0, has-value byte at 8, `OutOfMemory` = 1). The constructor installs a vtable built here with the source's slot order (checked with `-fdump-lang-class`): complete and deleting destructors, `vprintf`, `flush` (empty, as `PrintStream::flush` is), then the `PrintStream::begin` and `PrintStream::end` exports. `PrintStream::end` is still a placeholder (#19380 implements it), so `print` through the stream throws until that lands; `vprintf` and the conversions do not depend on it. The empty flush slot is a local `APS5_VABI` function, so `progress.py` lists it among the inert names, as it does `WtfJson.cpp`'s vtable slots. A null object, format or argument list throws, and so does a failed format, where the source would move its write position backwards. Debt: a fragment, `docs/dev/debt/changes/feat-nkwebkit-string-print-stream.md`, adds the entry under Functional and removes the 11 inventory rows. ### Tested Linux Mint 22.3: - New `nkwebkit_stringprintstream` test: construction over poisoned storage (both constructors), every vtable slot against the export it should hold, calling `vprintf`, `flush` and `begin` through the vtable as guest code does, and the deleting destructor through slot 1 on a `fastMalloc`'d stream. Buffer growth matches WTF built for Linux for the same sequences: three 120-character prints (position 360, size 482), one 1000-character print (size 2002), 127 characters staying inline then one more growing to 258, fifty short prints (140, 258), and `reset` keeping the 482-byte heap buffer. Also `toCString`, UTF-8 and invalid UTF-8 through `toString`, `toStringWithLatin1Fallback` and `tryToString`, and the null refusals. The test passes a real System V `va_list` on both Linux and Windows builds (`__builtin_sysv_va_start`, as `FileHandle::printf` does). - `ctest -R nkwebkit`: 91 tests passed. `progress.py --module libSceNKWebKit`: the 11 exports move to implemented. ### Checklist - [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-16 22:36:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T22:36:04Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and its focused tests look consistent with the stated behavior, but the build and tests were not run during this review.

What I ran

Reviewed head 8bdcc2572228bb01e0b6919bd64f7d695ed8f09e using the prepared diff and repo_read.py. I did not run build or test commands.

Results

Check Result Note
Diff and changed code passed Reviewed all six changed files
Build and tests not run Author reports Linux test results

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build and test results were not independently confirmed. The full text of Export.cpp and InventoryExports.hpp was excluded as too large; I reviewed the affected hunks in the prepared diff and the corresponding head ranges. No other changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5929078678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20404#pullrequestreview-5929078678). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T22:36:04Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and its focused tests look consistent with the stated behavior, but the build and tests were not run during this review. ## What I ran Reviewed head `8bdcc2572228bb01e0b6919bd64f7d695ed8f09e` using the prepared diff and `repo_read.py`. I did not run build or test commands. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Reviewed all six changed files | | Build and tests | not run | Author reports Linux test results | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Build and test results were not independently confirmed. The full text of `Export.cpp` and `InventoryExports.hpp` was excluded as too large; I reviewed the affected hunks in the prepared diff and the corresponding head ranges. No other changed files were excluded. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 13:00:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:00:47Z.

Review: COMMENTED


Built the exact changed sources and ran StringPrintStream on Linux against the existing WebKit runtime. The constructor, vtable, and string output checks passed.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170296930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20404#pullrequestreview-6170296930). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:00:47Z. **Review:** COMMENTED --- Built the exact changed sources and ran `StringPrintStream` on Linux against the existing WebKit runtime. The constructor, vtable, and string output checks passed. AI-assisted: yes.

Pull request closed

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!20404
No description provided.